-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
64 lines (63 loc) · 2.24 KB
/
app.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
function sortTweets(tweets) {
return tweets.sort(function(a,b){
return new Date(b.created_at) - new Date(a.created_at);
});
}
const app = Vue.createApp({
data() {
const tweets = sortTweets(searchDocuments);
return {
tweets: tweets,
results: undefined,
search: '',
lastIndex: 30,
minisearch: undefined,
}
},
mounted() {
/* make timeline visible */
this.$refs.timeline.style.display = 'block';
this.miniSearch = new MiniSearch({
fields: ['full_text'], // fields to index for full-text search
storeFields: ['full_text', 'created_at', 'id_str', 'favorite_count', 'retweet_count'],
idField: 'id_str',
});
this.miniSearch.addAll(this.tweets);
/* infinite scroll */
window.addEventListener('scroll', () => {
if (window.innerHeight + window.pageYOffset >= document.body.offsetHeight - 50) {
this.lastIndex += 20;
console.log(this.lastIndex);
}
});
},
methods: {
currentTweets() {
const results = (this.search) ? sortTweets(this.miniSearch.search(this.search)) : this.tweets;
console.log("currentTweets", this.tweets.length);
return results.slice(0, this.lastIndex);
},
shortDate(created_at) {
/* if it's in the current year, jun 9, else jun 9 2022 */
const date = new Date(created_at);
if (date.getFullYear() === new Date().getFullYear()) {
return date.toLocaleString('default', { month: 'short', day: 'numeric' });
}
return date.toLocaleString('default', { month: 'short', day: 'numeric', year: 'numeric' });
},
fix_full_text(item) {
const media = item.full_text.replace(/\.\.\/\.\.\/tweets_media\//g,'tweets_media/');
return media;
},
search(event) {
event.preventDefault();
},
local_url(item) {
return "./ivelasq3/status/" + item.id_str;
},
twitter_url(item) {
return "https://twitter.com/ivelasq3/status/" + item.id_str;
},
}
})
app.mount('#app')