[Client] 良い感じに

This commit is contained in:
syuilo 2017-03-20 05:43:27 +09:00
parent 0390820f07
commit 95440dffb5
3 changed files with 55 additions and 17 deletions

View file

@ -24,6 +24,10 @@
</style> </style>
<script> <script>
this.reactions = this.opts.post.reaction_counts; this.post = this.opts.post;
this.on('update', () => {
this.reactions = this.post.reaction_counts;
});
</script> </script>
</mk-reactions-viewer> </mk-reactions-viewer>

View file

@ -46,7 +46,7 @@
</div> </div>
</div> </div>
<footer> <footer>
<mk-reactions-viewer post={ p }></mk-reactions-viewer> <mk-reactions-viewer post={ p } ref="reactionsViewer"></mk-reactions-viewer>
<button onclick={ reply } title="返信"><i class="fa fa-reply"></i> <button onclick={ reply } title="返信"><i class="fa fa-reply"></i>
<p class="count" if={ p.replies_count > 0 }>{ p.replies_count }</p> <p class="count" if={ p.replies_count > 0 }>{ p.replies_count }</p>
</button> </button>
@ -336,12 +336,28 @@
this.isDetailOpened = false; this.isDetailOpened = false;
this.post = this.opts.post; this.set = post => {
this.post = post;
this.isRepost = this.post.repost && this.post.text == null && this.post.media_ids == null && this.post.poll == null; this.isRepost = this.post.repost && this.post.text == null && this.post.media_ids == null && this.post.poll == null;
this.p = this.isRepost ? this.post.repost : this.post; this.p = this.isRepost ? this.post.repost : this.post;
this.p.reactions_count = this.p.reaction_counts ? Object.keys(this.p.reaction_counts).map(key => this.p.reaction_counts[key]).reduce((a, b) => a + b) : 0; this.p.reactions_count = this.p.reaction_counts ? Object.keys(this.p.reaction_counts).map(key => this.p.reaction_counts[key]).reduce((a, b) => a + b) : 0;
this.title = dateStringify(this.p.created_at); this.title = dateStringify(this.p.created_at);
this.url = `/${this.p.user.username}/${this.p.id}`; this.url = `/${this.p.user.username}/${this.p.id}`;
};
this.set(this.opts.post);
this.refresh = () => {
this.api('posts/show', {
post_id: this.post.id
}).then(post => {
this.set(post);
this.update();
if (this.refs.reactionsViewer) this.refs.reactionsViewer.update({
post
});
});
};
this.on('mount', () => { this.on('mount', () => {
if (this.p.text) { if (this.p.text) {
@ -379,7 +395,8 @@
this.react = () => { this.react = () => {
riot.mount(document.body.appendChild(document.createElement('mk-reaction-picker')), { riot.mount(document.body.appendChild(document.createElement('mk-reaction-picker')), {
source: this.refs.reactButton, source: this.refs.reactButton,
post: this.p post: this.p,
cb: this.refresh
}); });
}; };

View file

@ -43,7 +43,7 @@
</div> </div>
</div> </div>
<footer> <footer>
<mk-reactions-viewer post={ p }></mk-reactions-viewer> <mk-reactions-viewer post={ p } ref="reactionsViewer"></mk-reactions-viewer>
<button onclick={ reply }><i class="fa fa-reply"></i> <button onclick={ reply }><i class="fa fa-reply"></i>
<p class="count" if={ p.replies_count > 0 }>{ p.replies_count }</p> <p class="count" if={ p.replies_count > 0 }>{ p.replies_count }</p>
</button> </button>
@ -312,12 +312,28 @@
import getPostSummary from '../../common/scripts/get-post-summary'; import getPostSummary from '../../common/scripts/get-post-summary';
import openPostForm from '../scripts/open-post-form'; import openPostForm from '../scripts/open-post-form';
this.post = this.opts.post; this.set = post => {
this.post = post;
this.isRepost = this.post.repost != null && this.post.text == null; this.isRepost = this.post.repost != null && this.post.text == null;
this.p = this.isRepost ? this.post.repost : this.post; this.p = this.isRepost ? this.post.repost : this.post;
this.p.reactions_count = this.p.reaction_counts ? Object.keys(this.p.reaction_counts).map(key => this.p.reaction_counts[key]).reduce((a, b) => a + b) : 0; this.p.reactions_count = this.p.reaction_counts ? Object.keys(this.p.reaction_counts).map(key => this.p.reaction_counts[key]).reduce((a, b) => a + b) : 0;
this.summary = getPostSummary(this.p); this.summary = getPostSummary(this.p);
this.url = `/${this.p.user.username}/${this.p.id}`; this.url = `/${this.p.user.username}/${this.p.id}`;
};
this.set(this.opts.post);
this.refresh = () => {
this.api('posts/show', {
post_id: this.post.id
}).then(post => {
this.set(post);
this.update();
if (this.refs.reactionsViewer) this.refs.reactionsViewer.update({
post
});
});
};
this.on('mount', () => { this.on('mount', () => {
if (this.p.text) { if (this.p.text) {
@ -358,7 +374,8 @@
this.react = () => { this.react = () => {
riot.mount(document.body.appendChild(document.createElement('mk-reaction-picker')), { riot.mount(document.body.appendChild(document.createElement('mk-reaction-picker')), {
source: this.refs.reactButton, source: this.refs.reactButton,
post: this.p post: this.p,
cb: this.refresh
}); });
}; };
</script> </script>