-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
71 lines (63 loc) · 2.02 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
65
66
67
68
69
70
71
import * as utils from './util/functions.js'
import * as constants from './util/constants.js'
import * as postsApi from './api/posts.js'
import * as mirrorsApi from './api/mirrors.js'
const app = new Vue({
el: '#app',
data: {
sortBy: constants.defaultOptionsValues.sortBy,
filter: '',
posts: '',
previousSearch: '',
searching: false,
footer: [
{
link: 'https://github.com/droidadroit/r-soccer-goals',
text: 'Github'
},
{
link: 'mailto:yashwanth.reddyth@gmail.com?subject=%5Br/soccer%20goals%5D',
text: 'Help'
}
]
},
mounted: function() {
utils.getOptionValue('sortBy').then(data => this.sortBy = data);
utils.getPreviousSearch().then(data => this.previousSearch = data);
},
methods: {
processForm: function() {
let vm = this;
vm.posts = [];
vm.searching = true;
postsApi.getPosts(vm.filter, vm.sortBy)
.then(data => {
vm.posts = data;
utils.setOptionValue({
previousQuery: {
sortBy: vm.sortBy,
query: vm.filter
}
});
})
.finally(_ => {
vm.searching = false;
});
},
recentSearch: function() {
this.filter = this.previousSearch.query,
this.sortBy = this.previousSearch.sortBy;
this.processForm();
},
loadMirrors: function(id) {
let vm = this;
if (vm.posts.filter(post => post.id === id)[0].mirrors === null) {
mirrorsApi.getMirrors(id).then(data => {
utils.assignMirrors(data, vm.posts, id);
});
}
},
openLink: utils.openInNewTab,
openSettings: utils.openSettings
}
});