From 95440dffb5015539e11cf4107472f6793efae120 Mon Sep 17 00:00:00 2001 From: syuilo <syuilotan@yahoo.co.jp> Date: Mon, 20 Mar 2017 05:43:27 +0900 Subject: [PATCH] =?UTF-8?q?[Client]=20=E8=89=AF=E3=81=84=E6=84=9F=E3=81=98?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/app/common/tags/reactions-viewer.tag | 6 +++- src/web/app/desktop/tags/timeline-post.tag | 33 +++++++++++++++----- src/web/app/mobile/tags/timeline-post.tag | 33 +++++++++++++++----- 3 files changed, 55 insertions(+), 17 deletions(-) diff --git a/src/web/app/common/tags/reactions-viewer.tag b/src/web/app/common/tags/reactions-viewer.tag index b289d89e8..f32f5466a 100644 --- a/src/web/app/common/tags/reactions-viewer.tag +++ b/src/web/app/common/tags/reactions-viewer.tag @@ -24,6 +24,10 @@ </style> <script> - this.reactions = this.opts.post.reaction_counts; + this.post = this.opts.post; + + this.on('update', () => { + this.reactions = this.post.reaction_counts; + }); </script> </mk-reactions-viewer> diff --git a/src/web/app/desktop/tags/timeline-post.tag b/src/web/app/desktop/tags/timeline-post.tag index 998def6e4..8c3b7c9be 100644 --- a/src/web/app/desktop/tags/timeline-post.tag +++ b/src/web/app/desktop/tags/timeline-post.tag @@ -46,7 +46,7 @@ </div> </div> <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> <p class="count" if={ p.replies_count > 0 }>{ p.replies_count }</p> </button> @@ -336,12 +336,28 @@ this.isDetailOpened = false; - this.post = this.opts.post; - 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.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.url = `/${this.p.user.username}/${this.p.id}`; + 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.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.title = dateStringify(this.p.created_at); + 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', () => { if (this.p.text) { @@ -379,7 +395,8 @@ this.react = () => { riot.mount(document.body.appendChild(document.createElement('mk-reaction-picker')), { source: this.refs.reactButton, - post: this.p + post: this.p, + cb: this.refresh }); }; diff --git a/src/web/app/mobile/tags/timeline-post.tag b/src/web/app/mobile/tags/timeline-post.tag index 064cdcda9..71d00128b 100644 --- a/src/web/app/mobile/tags/timeline-post.tag +++ b/src/web/app/mobile/tags/timeline-post.tag @@ -43,7 +43,7 @@ </div> </div> <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> <p class="count" if={ p.replies_count > 0 }>{ p.replies_count }</p> </button> @@ -312,12 +312,28 @@ import getPostSummary from '../../common/scripts/get-post-summary'; import openPostForm from '../scripts/open-post-form'; - this.post = this.opts.post; - this.isRepost = this.post.repost != null && this.post.text == null; - 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.summary = getPostSummary(this.p); - this.url = `/${this.p.user.username}/${this.p.id}`; + this.set = post => { + this.post = post; + this.isRepost = this.post.repost != null && this.post.text == null; + 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.summary = getPostSummary(this.p); + 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', () => { if (this.p.text) { @@ -358,7 +374,8 @@ this.react = () => { riot.mount(document.body.appendChild(document.createElement('mk-reaction-picker')), { source: this.refs.reactButton, - post: this.p + post: this.p, + cb: this.refresh }); }; </script>