forked from Abhay-N-J/NotO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
t.html
133 lines (130 loc) · 3.65 KB
/
t.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="top-bar">
<h1>
Share your ideas here
</h1>
</div>
<div class="main">
<div class="header">
</div>
<textarea></textarea>
<button>Add your ideas</button>
<div class="comments">
</div>
</div>
<script src="data.js"></script>
<script>
var id = window.location.search.slice(1);
var thread = threads.find(t => t.id == id);
var header = document.querySelector('.header');
var headerHtml = `
<h4 class="title">
${thread.title}
</h4>
<div class="bottom">
<p class="timestamp">
${new Date(thread.date).toLocaleString()}
</p>
<p class="comment-count">
${thread.comments.length} comments
</p>
</div>
`
header.insertAdjacentHTML('beforeend', headerHtml)
function addComment(comment) {
var commentHtml = `
<div class="comment">
<div class="top-comment">
<p class="user">
${comment.author}
</p>
<p class="comment-ts">
${new Date(comment.date).toLocaleString()}
</p>
</div>
<div class="comment-content">
${comment.content}
</div>
</div>
`
comments.insertAdjacentHTML('beforeend', commentHtml);
}
var comments = document.querySelector('.comments');
for (let comment of thread.comments) {
addComment(comment);
}
var btn = document.querySelector('button');
btn.addEventListener('click', function() {
var txt = document.querySelector('textarea');
var comment = {
content: txt.value,
date: Date.now(),
author: 'Aaron'
}
addComment(comment);
txt.value = '';
thread.comments.push(comment);
localStorage.setItem('threads', JSON.stringify(threads));
})
</script>
<style>
body {
margin: 10px 60px;
}
a {
text-decoration: none;
color: black;
}
h1, h4, ol {
margin: 0;
}
p {
margin: 5px 0;
}
textarea {
width: 80%;
height: 80px;
}
button {
display: block;
margin: 10px 0;
}
.top-bar {
background-color: skyblue;
padding: 0 40px;
}
.main {
background-color: #F6F6EF;
padding: 10px 40px;
}
.comments {
margin: 40px 0;
}
.comment {
margin: 10px 0;
}
.row {
padding: 5px 0;
}
.bottom, .top-comment {
display: flex;
color: grey;
font-size: 12px;
}
.timestamp {
padding-right: 10px;
}
.comment-ts {
padding-left: 10px;
}
</style>
</body>
</html>