-
Notifications
You must be signed in to change notification settings - Fork 2
/
story-comments.js
68 lines (60 loc) · 1.69 KB
/
story-comments.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
import Component from '@ember/component';
import { computed, get } from '@ember/object';
import config from 'ember-get-config';
import layout from '../templates/components/story-comments';
export default Component.extend({
layout,
classNames: ['story-comments'],
adminURL: `${config.adminRoot}/admin`,
comments: computed('getComments', {
get() {
// @todo: figure out if we need isLoading here
// @body: commented these out to silence build errors, needs improved approach
// this.set('isLoading', true);
return get(this, 'getComments')().then(comments => {
// this.set('isLoading', false);
return comments;
});
},
set(k,v) { return v; }
}),
didInsertElement() {
if (get(this, 'isShowingComments')) {
get(this, 'element').scrollIntoView();
}
},
commentsCount: computed('comments.[]', 'story', function() {
if (get(this, 'comments')) {
return get(this, 'comments.length');
} else {
return get(this, 'story.commentsCount');
}
}),
isShowingForm: computed({
get() {
return get(this, 'isShowingComments');
},
set(k,v) { return v; }
}),
isShowingComments: computed({
get() {
if (typeof document === 'undefined') {
// don't run in fastboot
return;
}
var hash = window.location.hash.slice(1).split('&');
return hash.indexOf('comments') !== -1 || hash.indexOf('commentlist') !== -1;
},
set(k,v){ return v; }
}),
actions: {
getComments() {
this.set('isShowingComments', true);
this.set('isShowingForm', true);
},
saveSuccess() {
this.set('isShowingForm', false);
this.set('isSuccess', true);
}
}
});