-
Notifications
You must be signed in to change notification settings - Fork 0
/
_DATA.js
executable file
·319 lines (308 loc) · 8.72 KB
/
_DATA.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
let users = {
sarah_edo: {
id: 'sarah_edo',
name: 'Sarah Drasner',
avatarURL: 'https://tylermcginnis.com/would-you-rather/sarah.jpg',
tweets: [
'8xf0y6ziyjabvozdd253nd',
'hbsc73kzqi75rg7v1e0i6a',
'2mb6re13q842wu8n106bhk',
'6h5ims9iks66d4m7kqizmv',
'3sklxkf9yyfowrf0o1ftbb'
]
},
tylermcginnis: {
id: 'tylermcginnis',
name: 'Tyler McGinnis',
avatarURL: 'https://tylermcginnis.com/would-you-rather/tyler.jpg',
tweets: [
'5c9qojr2d1738zlx09afby',
'f4xzgapq7mu783k9t02ghx',
'nnvkjqoevs8t02lzcc0ky',
'4pt0px8l0l9g6y69ylivti',
'fap8sdxppna8oabnxljzcv',
'leqp4lzfox7cqvsgdj0e7',
'26p5pskqi88i58qmza2gid',
'xi3ca2jcfvpa0i3t4m7ag'
]
},
dan_abramov: {
id: 'dan_abramov',
name: 'Dan Abramov',
avatarURL: 'https://tylermcginnis.com/would-you-rather/dan.jpg',
tweets: [
'5w6k1n34dkp1x29cuzn2zn',
'czpa59mg577x1oo45cup0d',
'omdbjl68fxact38hk7ypy6',
'3km0v4hf1ps92ajf4z2ytg',
'njv20mq7jsxa6bgsqc97',
'sfljgka8pfddbcer8nuxv',
'r0xu2v1qrxa6ygtvf2rkjw'
]
}
}
let tweets = {
'8xf0y6ziyjabvozdd253nd': {
id: '8xf0y6ziyjabvozdd253nd',
text:
"Shoutout to all the speakers I know for whom English is not a first language, but can STILL explain a concept well. It's hard enough to give a good talk in your mother tongue!",
author: 'sarah_edo',
timestamp: 1518122597860,
likes: ['tylermcginnis'],
replies: ['fap8sdxppna8oabnxljzcv', '3km0v4hf1ps92ajf4z2ytg'],
replyingTo: null
},
'5c9qojr2d1738zlx09afby': {
id: '5c9qojr2d1738zlx09afby',
text:
'I hope one day the propTypes pendulum swings back. Such a simple yet effective API. Was one of my favorite parts of React.',
author: 'tylermcginnis',
timestamp: 1518043995650,
likes: ['sarah_edo', 'dan_abramov'],
replies: ['njv20mq7jsxa6bgsqc97'],
replyingTo: null
},
f4xzgapq7mu783k9t02ghx: {
id: 'f4xzgapq7mu783k9t02ghx',
text:
'Want to work at Facebook/Google/:BigCompany? Start contributing code long before you ever interview there.',
author: 'tylermcginnis',
timestamp: 1517043995650,
likes: ['dan_abramov'],
replies: [],
replyingTo: null
},
hbsc73kzqi75rg7v1e0i6a: {
id: 'hbsc73kzqi75rg7v1e0i6a',
text: 'Puppies 101: buy a hamper with a lid on it.',
author: 'sarah_edo',
timestamp: 1516043995650,
likes: ['tylermcginnis'],
replies: ['leqp4lzfox7cqvsgdj0e7', 'sfljgka8pfddbcer8nuxv'],
replyingTo: null
},
'5w6k1n34dkp1x29cuzn2zn': {
id: '5w6k1n34dkp1x29cuzn2zn',
text:
'Is there a metric like code coverage, but that shows lines that, if changed (in a syntactically correct way), wouldn’t cause tests to fail?',
author: 'dan_abramov',
timestamp: 1515043995650,
likes: ['sarah_edo'],
replies: [],
replyingTo: null
},
czpa59mg577x1oo45cup0d: {
id: 'czpa59mg577x1oo45cup0d',
text:
"React came out 'rethinking best practices'. It has since accumulated 'best practices' of its own. Let’s see if we can do better.",
author: 'dan_abramov',
timestamp: 1515043995650,
likes: ['tylermcginnis', 'sarah_edo'],
replies: ['3sklxkf9yyfowrf0o1ftbb'],
replyingTo: null
},
'2mb6re13q842wu8n106bhk': {
id: '2mb6re13q842wu8n106bhk',
text:
'I think I realized I like dogs so much because I can really relate to being motivated by snacks',
author: 'sarah_edo',
timestamp: 1514043995650,
likes: ['dan_abramov'],
replies: ['26p5pskqi88i58qmza2gid'],
replyingTo: null
},
nnvkjqoevs8t02lzcc0ky: {
id: 'nnvkjqoevs8t02lzcc0ky',
text:
'Maybe the real benefit of open source was the friendships we made along the way?',
author: 'tylermcginnis',
timestamp: 1513043995650,
likes: [],
replies: [],
replyingTo: null
},
omdbjl68fxact38hk7ypy6: {
id: 'omdbjl68fxact38hk7ypy6',
text:
'A 7-minute Paul Joseph Watson video being translated and aired by a Russian state TV channel is the most surreal thing I’ve seen in 2018 yet',
author: 'dan_abramov',
timestamp: 1512043995650,
likes: [],
replies: [],
replyingTo: null
},
'4pt0px8l0l9g6y69ylivti': {
id: '4pt0px8l0l9g6y69ylivti',
text:
'Talking less about the downsides of OSS and focusing on some of the huge potential upsides for once might just help get more people into it.',
author: 'tylermcginnis',
timestamp: 1511043995650,
likes: ['dan_abramov'],
replies: [],
replyingTo: null
},
'6h5ims9iks66d4m7kqizmv': {
id: '6h5ims9iks66d4m7kqizmv',
text:
"By the way, if you have a blog post sitting around and want to get some eyes on it, we take guest submissions! That's how I started.",
author: 'sarah_edo',
timestamp: 1510043995650,
likes: ['dan_abramov', 'tylermcginnis'],
replies: ['xi3ca2jcfvpa0i3t4m7ag', 'r0xu2v1qrxa6ygtvf2rkjw'],
replyingTo: null
},
fap8sdxppna8oabnxljzcv: {
id: 'fap8sdxppna8oabnxljzcv',
author: 'tylermcginnis',
text:
"I agree. I'm always really impressed when I see someone giving a talk in a language that's not their own.",
timestamp: 1518122677860,
likes: ['sarah_edo'],
replyingTo: '8xf0y6ziyjabvozdd253nd',
replies: []
},
'3km0v4hf1ps92ajf4z2ytg': {
id: '3km0v4hf1ps92ajf4z2ytg',
author: 'dan_abramov',
text: 'It can be difficult at times.',
timestamp: 1518122667860,
likes: [],
replyingTo: '8xf0y6ziyjabvozdd253nd',
replies: []
},
njv20mq7jsxa6bgsqc97: {
id: 'njv20mq7jsxa6bgsqc97',
author: 'dan_abramov',
text: 'Sometimes you have to sacrifice simplicity for power.',
timestamp: 1518044095650,
likes: ['tylermcginnis'],
replyingTo: '5c9qojr2d1738zlx09afby',
replies: []
},
leqp4lzfox7cqvsgdj0e7: {
id: 'leqp4lzfox7cqvsgdj0e7',
author: 'tylermcginnis',
text: 'Also trashcans. Learned this the hard way.',
timestamp: 1516043255650,
likes: [],
replyingTo: 'hbsc73kzqi75rg7v1e0i6a',
replies: []
},
sfljgka8pfddbcer8nuxv: {
id: 'sfljgka8pfddbcer8nuxv',
author: 'dan_abramov',
text: 'Puppies are the best.',
timestamp: 1516045995650,
likes: ['sarah_edo', 'tylermcginnis'],
replyingTo: 'hbsc73kzqi75rg7v1e0i6a',
replies: []
},
'3sklxkf9yyfowrf0o1ftbb': {
id: '3sklxkf9yyfowrf0o1ftbb',
author: 'sarah_edo',
text:
'The idea of best practices being a negative thing is an interesting concept.',
timestamp: 1515044095650,
likes: ['dan_abramov'],
replyingTo: 'czpa59mg577x1oo45cup0d',
replies: []
},
'26p5pskqi88i58qmza2gid': {
id: '26p5pskqi88i58qmza2gid',
author: 'tylermcginnis',
text: 'Too relatable',
timestamp: 1514044994650,
likes: ['sarah_edo'],
replyingTo: '2mb6re13q842wu8n106bhk',
replies: []
},
xi3ca2jcfvpa0i3t4m7ag: {
id: 'xi3ca2jcfvpa0i3t4m7ag',
author: 'tylermcginnis',
text: 'Just DMd you!',
timestamp: 1510043995650,
likes: [],
replyingTo: '6h5ims9iks66d4m7kqizmv',
replies: []
},
r0xu2v1qrxa6ygtvf2rkjw: {
id: 'r0xu2v1qrxa6ygtvf2rkjw',
author: 'dan_abramov',
text: 'This is a great idea.',
timestamp: 1510044395650,
likes: ['tylermcginnis'],
replyingTo: '6h5ims9iks66d4m7kqizmv',
replies: []
}
}
export function _getUsers() {
return new Promise((res, rej) => {
setTimeout(() => res({ ...users }), 1000)
})
}
export function _getTweets() {
return new Promise((res, rej) => {
setTimeout(() => res({ ...tweets }), 1000)
})
}
export function _saveLikeToggle({ id, hasLiked, authedUser }) {
return new Promise((res, rej) => {
setTimeout(() => {
tweets = {
...tweets,
[id]: {
...tweets[id],
likes:
hasLiked === true
? tweets[id].likes.filter(uid => uid !== authedUser)
: tweets[id].likes.concat([authedUser])
}
}
res()
}, 500)
})
}
function generateUID() {
return (
Math.random()
.toString(36)
.substring(2, 15) +
Math.random()
.toString(36)
.substring(2, 15)
)
}
function formatTweet({ author, text, replyingTo = null }) {
return {
author,
id: generateUID(),
likes: [],
replies: [],
text,
timestamp: Date.now(),
replyingTo
}
}
export function _saveTweet({ text, author, replyingTo }) {
return new Promise((res, rej) => {
const formattedTweet = formatTweet({
text,
author,
replyingTo
})
setTimeout(() => {
tweets = {
...tweets,
[formattedTweet.id]: formattedTweet
}
users = {
...users,
[author]: {
...users[author],
tweets: users[author].tweets.concat([formattedTweet.id])
}
}
res(formattedTweet)
}, 1000)
})
}