From 2de118a45d0c9da11f652f9603650bd4008d8d4d Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 21 Feb 2017 20:34:54 +0900 Subject: [PATCH] wip --- src/web/app/common/tags/signin-history.tag | 24 ++-- .../app/desktop/tags/following-setuper.tag | 58 ++++---- src/web/app/desktop/tags/image-dialog.tag | 35 ++--- src/web/app/desktop/tags/images-viewer.tag | 26 ++-- src/web/app/desktop/tags/notifications.tag | 40 +++--- src/web/app/desktop/tags/post-detail-sub.tag | 33 +++-- src/web/app/desktop/tags/post-detail.tag | 126 ++++++++++-------- src/web/app/desktop/tags/post-form-window.tag | 23 ++-- src/web/app/desktop/tags/post-preview.tag | 4 +- src/web/app/desktop/tags/progress-dialog.tag | 19 ++- .../app/desktop/tags/repost-form-window.tag | 19 ++- src/web/app/desktop/tags/repost-form.tag | 29 ++-- src/web/app/desktop/tags/ui.tag | 1 + .../app/desktop/tags/user-friends-graph.tag | 67 ---------- src/web/app/desktop/tags/user-likes-graph.tag | 42 ------ 15 files changed, 243 insertions(+), 303 deletions(-) delete mode 100644 src/web/app/desktop/tags/user-friends-graph.tag delete mode 100644 src/web/app/desktop/tags/user-likes-graph.tag diff --git a/src/web/app/common/tags/signin-history.tag b/src/web/app/common/tags/signin-history.tag index 47bf68c28..386898005 100644 --- a/src/web/app/common/tags/signin-history.tag +++ b/src/web/app/common/tags/signin-history.tag @@ -55,21 +55,23 @@ this.fetching = true; this.on('mount', () => { - this.api 'i/signin_history' - }).then((history) => { - this.history = history - this.fetching = false - this.update(); - .catch (err) => - console.error err + this.api('i/signin_history').then(history => { + this.update({ + fetching: false, + history: history + }); + }); - this.stream.on 'signin' this.on-signin + this.stream.on('signin', this.onSignin); + }); this.on('unmount', () => { - this.stream.off 'signin' this.on-signin + this.stream.off('signin', this.onSignin); + }); - this.on-signin = (signin) => { - @history.unshift signin + this.onSignin = signin => { + this.history.unshift(signin); this.update(); + }; diff --git a/src/web/app/desktop/tags/following-setuper.tag b/src/web/app/desktop/tags/following-setuper.tag index 03b26b10e..3dc8fb54c 100644 --- a/src/web/app/desktop/tags/following-setuper.tag +++ b/src/web/app/desktop/tags/following-setuper.tag @@ -1,6 +1,6 @@

気になるユーザーをフォロー:

-
0 }> +
0 }>
{ name }

@{ username }

@@ -8,8 +8,8 @@
-

おすすめのユーザーは見つかりませんでした。

-

読み込んでいます +

おすすめのユーザーは見つかりませんでした。

+

読み込んでいます

もっと見る @@ -81,7 +81,7 @@ text-align center color #aaa - > .loading + > .fetching margin 0 padding 16px text-align center @@ -126,38 +126,46 @@ this.mixin('api'); this.mixin('user-preview'); - this.users = null - this.loading = true + this.users = null; + this.fetching = true; - this.limit = 6users - this.page = 0 + this.limit = 6; + this.page = 0; this.on('mount', () => { - this.load(); + this.fetch(); + }); - this.load = () => { - this.loading = true - this.users = null - this.update(); + this.fetch = () => { + this.update({ + fetching: true, + users: null + }); this.api('users/recommendation', { - limit: @limit - offset: @limit * this.page - }).then((users) => { - this.loading = false + limit: this.limit, + offset: this.limit * this.page + }).then(users => { + this.fetching = false this.users = users - this.update(); - .catch (err, text-status) -> - console.error err + this.update({ + fetching: false, + users: users + }); + }); + }; this.refresh = () => { - if this.users.length < @limit - this.page = 0 - else - this.page++ - this.load(); + if (this.users.length < this.limit) { + this.page = 0; + } else { + this.page++; + } + this.fetch(); + }; this.close = () => { this.unmount(); + }; diff --git a/src/web/app/desktop/tags/image-dialog.tag b/src/web/app/desktop/tags/image-dialog.tag index a1acd05f6..91245dac9 100644 --- a/src/web/app/desktop/tags/image-dialog.tag +++ b/src/web/app/desktop/tags/image-dialog.tag @@ -35,41 +35,26 @@ diff --git a/src/web/app/desktop/tags/images-viewer.tag b/src/web/app/desktop/tags/images-viewer.tag index e1ceeb0f5..83bce7bf4 100644 --- a/src/web/app/desktop/tags/images-viewer.tag +++ b/src/web/app/desktop/tags/images-viewer.tag @@ -26,20 +26,22 @@ diff --git a/src/web/app/desktop/tags/notifications.tag b/src/web/app/desktop/tags/notifications.tag index 2db27a4fc..7ba74412e 100644 --- a/src/web/app/desktop/tags/notifications.tag +++ b/src/web/app/desktop/tags/notifications.tag @@ -182,32 +182,36 @@ this.mixin('user-preview'); this.mixin('get-post-summary'); - this.notifications = [] - this.loading = true + this.notifications = []; + this.loading = true; this.on('mount', () => { - this.api 'i/notifications' - }).then((notifications) => { - this.notifications = notifications - this.loading = false - this.update(); - .catch (err, text-status) -> - console.error err + this.api('i/notifications').then(notifications => { + this.update({ + loading: false, + notifications: notifications + }); + }); - this.stream.on 'notification' this.on-notification + this.stream.on('notification', this.onNotification); + }); this.on('unmount', () => { - this.stream.off 'notification' this.on-notification + this.stream.off('notification', this.onNotification); + }); - this.on-notification = (notification) => { - @notifications.unshift notification + this.onNotification = notification => { + this.notifications.unshift(notification); this.update(); + }; this.on('update', () => { - @notifications.forEach (notification) => - date = (new Date notification.created_at).getDate() - month = (new Date notification.created_at).getMonth() + 1 - notification._date = date - notification._datetext = month + '月 ' + date + '日' + this.notifications.forEach(notification => { + const date = new Date(notification.created_at).getDate(); + const month = new Date(notification.created_at).getMonth() + 1; + notification._date = date; + notification._datetext = `${month}月 ${date}日`; + }); + }); diff --git a/src/web/app/desktop/tags/post-detail-sub.tag b/src/web/app/desktop/tags/post-detail-sub.tag index 24feda9be..f1b3c915c 100644 --- a/src/web/app/desktop/tags/post-detail-sub.tag +++ b/src/web/app/desktop/tags/post-detail-sub.tag @@ -108,33 +108,40 @@ this.mixin('date-stringify'); this.mixin('user-preview'); - this.post = this.opts.post + this.post = this.opts.post; - this.url = CONFIG.url + '/' + this.post.user.username + '/' + this.post.id + this.url = CONFIG.url + '/' + this.post.user.username + '/' + this.post.id; - this.title = @date-stringify this.post.created_at + this.title = this.dateStringify(this.post.created_at); this.on('mount', () => { - if this.post.text? - tokens = @analyze this.post.text - this.refs.text.innerHTML = @compile tokens + if (this.p.text) { + const tokens = this.analyze(this.p.text); - this.refs.text.children.forEach (e) => - if e.tag-name == 'MK-URL' - riot.mount e + this.refs.text.innerHTML = this.refs.text.innerHTML.replace('

', this.compile(tokens)); + + this.refs.text.children.forEach(e => { + if (e.tagName == 'MK-URL') riot.mount(e); + }); + } + }); this.like = () => { - if this.post.is_liked + if (this.post.is_liked) { this.api('posts/likes/delete', { post_id: this.post.id }).then(() => { - this.post.is_liked = false + this.post.is_liked = false; this.update(); - else + }); + } else { this.api('posts/likes/create', { post_id: this.post.id }).then(() => { - this.post.is_liked = true + this.post.is_liked = true; this.update(); + }); + } + }; diff --git a/src/web/app/desktop/tags/post-detail.tag b/src/web/app/desktop/tags/post-detail.tag index 00426ea9b..cc5fbeed8 100644 --- a/src/web/app/desktop/tags/post-detail.tag +++ b/src/web/app/desktop/tags/post-detail.tag @@ -335,102 +335,120 @@ this.mixin('date-stringify'); this.mixin('NotImplementedException'); - this.fetching = true - this.loading-context = false - this.content = null - this.post = null + this.fetching = true; + this.loadingContext = false; + this.content = null; + this.post = null; this.on('mount', () => { - this.api('posts/show', { post_id: this.opts.post - }).then((post) => { - this.fetching = false - this.post = post + }).then(post => { + const isRepost = post.repost != null; + const p = isRepost ? post.repost : post; + this.update({ + fetching: false, + post: post, + isRepost: isRepost, + p: p, + title: this.dateStringify(p.created_at) + }); + this.trigger('loaded'); - this.is-repost = this.post.repost? - this.p = if @is-repost then this.post.repost else this.post + if (this.p.text) { + const tokens = this.analyze(this.p.text); - this.title = @date-stringify this.p.created_at + this.refs.text.innerHTML = this.compile(tokens); - this.update(); - - if this.p.text? - tokens = @analyze this.p.text - this.refs.text.innerHTML = @compile tokens - - this.refs.text.children.forEach (e) => - if e.tag-name == 'MK-URL' - riot.mount e + this.refs.text.children.forEach(e => { + if (e.tagName == 'MK-URL') riot.mount(e); + }); // URLをプレビュー tokens - .filter (t) -> t.type == 'link' - .map (t) => - this.preview = this.refs.text.appendChild(document.createElement('mk-url-preview')); - riot.mount this.preview, do - url: t.content + .filter(t => t.type == 'link') + .map(t => { + riot.mount(this.refs.text.appendChild(document.createElement('mk-url-preview')), { + url: t.content + }); + }); + } // Get likes this.api('posts/likes', { - post_id: this.p.id + post_id: this.p.id, limit: 8 - }).then((likes) => { - this.likes = likes - this.update(); + }).then(likes => { + this.update({ + likes: likes + }); + }); // Get reposts this.api('posts/reposts', { - post_id: this.p.id + post_id: this.p.id, limit: 8 - }).then((reposts) => { - this.reposts = reposts - this.update(); + }).then(reposts => { + this.update({ + reposts: reposts + }); + }); // Get replies this.api('posts/replies', { - post_id: this.p.id + post_id: this.p.id, limit: 8 - }).then((replies) => { - this.replies = replies - this.update(); - - this.update(); + }).then(replies => { + this.update({ + replies: replies + }); + }); + }); + }); this.reply = () => { - form = document.body.appendChild(document.createElement('mk-post-form-window')); - riot.mount form, do + riot.mount(document.body.appendChild(document.createElement('mk-post-form-window')), { reply: this.p + }); + }; this.repost = () => { - form = document.body.appendChild(document.createElement('mk-repost-form-window')); - riot.mount form, do + riot.mount(document.body.appendChild(document.createElement('mk-repost-form-window')), { post: this.p + }); + }; this.like = () => { - if this.p.is_liked + if (this.p.is_liked) { this.api('posts/likes/delete', { post_id: this.p.id }).then(() => { - this.p.is_liked = false + this.p.is_liked = false; this.update(); - else + }); + } else { this.api('posts/likes/create', { post_id: this.p.id }).then(() => { - this.p.is_liked = true + this.p.is_liked = true; this.update(); + }); + } + }; - this.load-context = () => { - this.loading-context = true + this.loadContext = () => { + this.loadingContext = true; - // Get context + // Fetch context this.api('posts/context', { post_id: this.p.reply_to_id - }).then((context) => { - this.context = context.reverse! - this.loading-context = false - this.update(); + }).then(context => { + this.update({ + loadContext: false, + content: context.reverse() + }); + }); + }; diff --git a/src/web/app/desktop/tags/post-form-window.tag b/src/web/app/desktop/tags/post-form-window.tag index 8f5bf1a51..4f2ea2538 100644 --- a/src/web/app/desktop/tags/post-form-window.tag +++ b/src/web/app/desktop/tags/post-form-window.tag @@ -32,24 +32,31 @@ diff --git a/src/web/app/desktop/tags/post-preview.tag b/src/web/app/desktop/tags/post-preview.tag index 06008da3c..458a6f83f 100644 --- a/src/web/app/desktop/tags/post-preview.tag +++ b/src/web/app/desktop/tags/post-preview.tag @@ -86,8 +86,8 @@ this.mixin('date-stringify'); this.mixin('user-preview'); - this.post = this.opts.post + this.post = this.opts.post; - this.title = @date-stringify this.post.created_at + this.title = this.dateStringify(this.post.created_at); diff --git a/src/web/app/desktop/tags/progress-dialog.tag b/src/web/app/desktop/tags/progress-dialog.tag index cba4e3404..760f869f6 100644 --- a/src/web/app/desktop/tags/progress-dialog.tag +++ b/src/web/app/desktop/tags/progress-dialog.tag @@ -75,20 +75,25 @@ diff --git a/src/web/app/desktop/tags/repost-form-window.tag b/src/web/app/desktop/tags/repost-form-window.tag index d7521caab..75fe9f482 100644 --- a/src/web/app/desktop/tags/repost-form-window.tag +++ b/src/web/app/desktop/tags/repost-form-window.tag @@ -12,25 +12,32 @@ diff --git a/src/web/app/desktop/tags/repost-form.tag b/src/web/app/desktop/tags/repost-form.tag index 7d309bf75..de10a37f0 100644 --- a/src/web/app/desktop/tags/repost-form.tag +++ b/src/web/app/desktop/tags/repost-form.tag @@ -117,28 +117,31 @@ this.mixin('api'); this.mixin('notify'); - this.wait = false - this.quote = false + this.wait = false; + this.quote = false; this.cancel = () => { this.trigger('cancel'); + }; this.ok = () => { - this.wait = true + this.wait = true; this.api('posts/create', { - repost_id: this.opts.post.id - text: if this.quote then this.refs.text.value else undefined - }).then((data) => { + repost_id: this.opts.post.id, + text: this.quote ? this.refs.text.value : undefined + }).then(data => { this.trigger('posted'); - @notify 'Repostしました!' - .catch (err) => - console.error err - @notify 'Repostできませんでした' + this.notify('Repostしました!'); + }).catch(err => { + this.notify('Repostできませんでした'); }).then(() => { - this.wait = false - this.update(); + this.update({ + wait: false + }); + }); this.onquote = () => { - this.quote = true + this.quote = true; + }; diff --git a/src/web/app/desktop/tags/ui.tag b/src/web/app/desktop/tags/ui.tag index e6781f4a2..832299e32 100644 --- a/src/web/app/desktop/tags/ui.tag +++ b/src/web/app/desktop/tags/ui.tag @@ -31,6 +31,7 @@ if (e.which == 80 || e.which == 78) { // p or n e.preventDefault(); this.openPostForm(); + } }; diff --git a/src/web/app/desktop/tags/user-friends-graph.tag b/src/web/app/desktop/tags/user-friends-graph.tag deleted file mode 100644 index 8932d596f..000000000 --- a/src/web/app/desktop/tags/user-friends-graph.tag +++ /dev/null @@ -1,67 +0,0 @@ - - - - - diff --git a/src/web/app/desktop/tags/user-likes-graph.tag b/src/web/app/desktop/tags/user-likes-graph.tag deleted file mode 100644 index 5639ee36e..000000000 --- a/src/web/app/desktop/tags/user-likes-graph.tag +++ /dev/null @@ -1,42 +0,0 @@ - - - - -