-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
104 lines (94 loc) · 3.12 KB
/
actions.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
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
$(document).ready(function()
{
// 1. Get all tweets
$('#get-tweets').on('click',function() {
$.ajax({
url: '/all-tweets',
type: 'GET',
success: (response) => {
var tbodyEl = $('#tweet-table');
tbodyEl.html('');
for (const tweet of response.tweets) {
tbodyEl.append('\
<tr>\
<td class="text">' + tweet.text + '</td>\
<td class="date">' + tweet.created_at + '</td>\
</tr>\
');
};
}
});
});
// 2. Get all user ID's
$('#get-ids').on('click', function() {
$.ajax({
url: '/all-tweets',
type: 'GET',
success: (response) => {
var tbodyEl = $('#id-table');
tbodyEl.html('');
for (const tweet of response.tweets) {
tbodyEl.append('\
<tr>\
<td>' + tweet.user.id + '</td>\
</tr>\
');
};
}
});
});
// 3. Get a tweet from its ID
$('#submit-tweet-id').on('click', function() {
$.ajax({
url: '/all-tweets',
type: 'GET',
success: (response) => {
var id = document.getElementById("enter-tweet-id").value;
document.getElementById("enter-tweet-id").value = "";
$('#tweet-from-id-table').html('');
for (const tweet of response.tweets) {
if(id == tweet.id) {
$('#tweet-from-id-table').append(`\
<tr>\
<td>${tweet.text}</td>\
<td>${tweet.created_at}</td>\
</tr>\
`);
}
};
}
});
});
// 4. Create a tweet from text & ID
$("#create-button").on('click', function() {
var numID = parseInt(document.getElementById("create-tweet-id").value);
var strID = document.getElementById("create-tweet-id").value;
var txt = document.getElementById("create-tweet-text").value;
$.ajax({
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(
{
id: numID,
id_str: strID,
text: txt
}
),
success: (response) => {
console.log('Here: ');
console.log(response);
}
/*
success: (response) => {
response.tweets.push(tweet);
console.log({tweet, response});
}
success: (response) => {
console.log(numID, strID, txt, response);
//fs.writeFileSync('favs.json', newTweet);
response.tweets.push(newTweet);
}
*/
});
});
});