-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
55 lines (41 loc) · 1.08 KB
/
main.js
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
const tweeter = Tweeter()
const renderer = Renderer()
const postInput = $('#input')
const post = function () {
const postText = postInput.val()
try {
tweeter.addPost(postText)
}
catch (err) {
alert(err.message)
}
postInput.val('')
render()
}
$('#posts').on("click", ".delete", function () {
const postID = $(this).closest(".post").data().id
tweeter.removePost(postID)
render()
})
$("#posts").on("click", '.delete-comment', function () {
const postID = $(this).closest(".post").data().id
const commentID = $(this).closest(".comments").data().id
tweeter.removeComment(postID, commentID)
render()
})
$("#posts").on("click", '.comment', function () {
const commentText = $(this).siblings(".postComment").val()
const postID = $(this).closest(".post").data().id
try {
tweeter.addComment(commentText, postID)
}
catch (err) {
alert(err.message)
}
$(this).siblings(".postComment").val('')
render()
});
const render = () => {
renderer.renderPosts(tweeter.getPosts())
}
render()