-
-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathdashboard.js
More file actions
74 lines (60 loc) · 2.09 KB
/
Copy pathdashboard.js
File metadata and controls
74 lines (60 loc) · 2.09 KB
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
import Controller from '@ember/controller';
import { A } from '@ember/array';
import { computed } from '@ember/object';
import ajax from 'ember-fetch/ajax';
const TO_SHOW = 5;
export default Controller.extend({
init() {
this._super(...arguments);
this.loadingMore = false;
this.hasMore = false;
this.myCrates = A();
this.myFollowing = A();
this.myFeed = A();
this.myStats = 0;
this.favoriteUsers = [];
},
visibleCrates: computed('myCrates.[]', function() {
return this.myCrates.slice(0, TO_SHOW);
}),
visibleFollowing: computed('myFollowing.[]', function() {
return this.myFollowing.slice(0, TO_SHOW);
}),
visibleStats: computed('myStats', function() {
return this.myStats;
}),
hasMoreCrates: computed('myCrates.[]', function() {
return this.get('myCrates.length') > TO_SHOW;
}),
visibleFavorites: computed('favoriteUsers', function() {
return this.get('favoriteUsers').slice(0, TO_SHOW);
}),
hasMoreFollowing: computed('myFollowing.[]', function() {
return this.get('myFollowing.length') > TO_SHOW;
}),
hasMoreFavorites: computed('favoriteUsers', function() {
return this.get('favoriteUsers.length') > TO_SHOW;
}),
actions: {
async loadMore() {
this.set('loadingMore', true);
let page = this.myFeed.length / 10 + 1;
try {
let data = await ajax(`/api/v1/me/updates?page=${page}`);
let versions = data.versions.map(version => this.store.push(this.store.normalize('version', version)));
this.myFeed.pushObjects(versions);
this.set('hasMore', data.meta.more);
} finally {
this.set('loadingMore', false);
}
},
unfavoriteUser: function(user) {
this.store
.adapterFor('user')
.unfavorite(user.id)
.then(() => {
this.get('favoriteUsers').users.removeObject(user);
});
},
},
});