-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
34 lines (30 loc) · 1.06 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
const tweeter = Tweeter()
const renderer = Renderer()
renderer(tweeter.getPosts())
$('#post').click(function () { //when twit button is pressed
let twit = $('input').val()
if (twit != '') {
$('input').val('')
tweeter.addPost(twit)
renderer(tweeter.getPosts())
}
})
$('#posts').on('click', '.delete', function () { //when delete post button is pressed
let id = $(this).closest('.post').data().id
tweeter.removePost(id)
renderer(tweeter.getPosts())
})
$('#posts').on('click', '.addComment', function () { //when comment post button is pressed
let postId = $(this).closest('.post').data().id
let text = $(this).closest('p').find('input').val()
if (text != '') {
tweeter.addComment(postId, text)
renderer(tweeter.getPosts())
}
})
$('#posts').on('click', '.delete-comment', function () { //when delete comment button is pressed
let postId = $(this).closest('.post').data().id
let commentId = $(this).closest('p').data().id
tweeter.removeComment(postId, commentId)
renderer(tweeter.getPosts())
})