From 5b6768188906c9b0b011a2a1e6b6889dd6d27aff Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 21 Feb 2017 11:44:53 +0900 Subject: [PATCH] wip --- src/web/app/desktop/tags/crop-window.tag | 28 ++-- src/web/app/desktop/tags/follow-button.tag | 78 ++++++----- src/web/app/desktop/tags/home.tag | 37 +++-- .../tags/select-file-from-drive-window.tag | 27 ++-- .../desktop/tags/set-avatar-suggestion.tag | 6 +- .../desktop/tags/set-banner-suggestion.tag | 6 +- src/web/app/desktop/tags/timeline.tag | 69 +++++---- src/web/app/desktop/tags/user-timeline.tag | 131 +++++++++--------- src/web/app/desktop/tags/users-list.tag | 79 ++++++----- src/web/app/mobile/tags/home-timeline.tag | 48 ++++--- src/web/app/mobile/tags/timeline.tag | 67 +++++---- src/web/app/mobile/tags/ui-header.tag | 14 +- 12 files changed, 334 insertions(+), 256 deletions(-) diff --git a/src/web/app/desktop/tags/crop-window.tag b/src/web/app/desktop/tags/crop-window.tag index 56845f24a..c5c186555 100644 --- a/src/web/app/desktop/tags/crop-window.tag +++ b/src/web/app/desktop/tags/crop-window.tag @@ -160,29 +160,35 @@ diff --git a/src/web/app/desktop/tags/follow-button.tag b/src/web/app/desktop/tags/follow-button.tag index 64055a158..1877e4a53 100644 --- a/src/web/app/desktop/tags/follow-button.tag +++ b/src/web/app/desktop/tags/follow-button.tag @@ -71,54 +71,70 @@ this.mixin('is-promise'); this.mixin('stream'); - this.user = null - this.user-promise = if @is-promise this.opts.user then this.opts.user else Promise.resolve this.opts.user - this.init = true - this.wait = false + this.user = null; + this.userPromise = this.isPromise(this.opts.user) + ? this.opts.user + : Promise.resolve(this.opts.user); + this.init = true; + this.wait = false; this.on('mount', () => { - this.user-promise}).then((user) => { - this.user = user - this.init = false - this.update(); - this.stream.on 'follow' this.on-stream-follow - this.stream.on 'unfollow' this.on-stream-unfollow + this.userPromise.then(user => { + this.update({ + init: false, + user: user + }); + this.stream.on('follow', this.onStreamFollow); + this.stream.on('unfollow', this.onStreamUnfollow); + }); + }); this.on('unmount', () => { - this.stream.off 'follow' this.on-stream-follow - this.stream.off 'unfollow' this.on-stream-unfollow + this.stream.off('follow', this.onStreamFollow); + this.stream.off('unfollow', this.onStreamUnfollow); + }); - this.on-stream-follow = (user) => { - if user.id == this.user.id - this.user = user - this.update(); + this.onStreamFollow = user => { + if (user.id == this.user.id) { + this.update({ + user: user + }); + } + }; - this.on-stream-unfollow = (user) => { - if user.id == this.user.id - this.user = user - this.update(); + this.onStreamUnfollow = user => { + if (user.id == this.user.id) { + this.update({ + user: user + }); + } + }; this.onclick = () => { - this.wait = true - if this.user.is_following + this.wait = true; + if (this.user.is_following) { this.api('following/delete', { user_id: this.user.id }).then(() => { - this.user.is_following = false - .catch (err) -> - console.error err + this.user.is_following = false; + }).catch(err => { + console.error(err); }).then(() => { - this.wait = false + this.wait = false; this.update(); - else + }); + } else { this.api('following/create', { user_id: this.user.id }).then(() => { - this.user.is_following = true - .catch (err) -> - console.error err + this.user.is_following = true; + }).catch(err => { + console.error(err); }).then(() => { - this.wait = false + this.wait = false; this.update(); + }); + } + }; diff --git a/src/web/app/desktop/tags/home.tag b/src/web/app/desktop/tags/home.tag index 3d0d9d415..7a148d123 100644 --- a/src/web/app/desktop/tags/home.tag +++ b/src/web/app/desktop/tags/home.tag @@ -59,32 +59,39 @@ diff --git a/src/web/app/desktop/tags/select-file-from-drive-window.tag b/src/web/app/desktop/tags/select-file-from-drive-window.tag index 45ece233f..777073583 100644 --- a/src/web/app/desktop/tags/select-file-from-drive-window.tag +++ b/src/web/app/desktop/tags/select-file-from-drive-window.tag @@ -131,31 +131,38 @@ diff --git a/src/web/app/desktop/tags/set-avatar-suggestion.tag b/src/web/app/desktop/tags/set-avatar-suggestion.tag index ba44a7a33..335148ea5 100644 --- a/src/web/app/desktop/tags/set-avatar-suggestion.tag +++ b/src/web/app/desktop/tags/set-avatar-suggestion.tag @@ -35,11 +35,13 @@ this.mixin('update-avatar'); this.set = () => { - @update-avatar this.I + this.updateAvatar(this.I); + }; - this.close = (e) => { + this.close = e => { e.preventDefault(); e.stopPropagation(); this.unmount(); + }; diff --git a/src/web/app/desktop/tags/set-banner-suggestion.tag b/src/web/app/desktop/tags/set-banner-suggestion.tag index fa735e4e4..deddc478c 100644 --- a/src/web/app/desktop/tags/set-banner-suggestion.tag +++ b/src/web/app/desktop/tags/set-banner-suggestion.tag @@ -35,11 +35,13 @@ this.mixin('update-banner'); this.set = () => { - @update-banner this.I + this.updateBanner(this.I); + }; - this.close = (e) => { + this.close = e => { e.preventDefault(); e.stopPropagation(); this.unmount(); + }; diff --git a/src/web/app/desktop/tags/timeline.tag b/src/web/app/desktop/tags/timeline.tag index f63afabd4..a589adf5a 100644 --- a/src/web/app/desktop/tags/timeline.tag +++ b/src/web/app/desktop/tags/timeline.tag @@ -3,7 +3,9 @@

{ post._datetext }{ posts[i + 1]._datetext }

- + diff --git a/src/web/app/desktop/tags/user-timeline.tag b/src/web/app/desktop/tags/user-timeline.tag index bc2e1744e..e8ff3dc05 100644 --- a/src/web/app/desktop/tags/user-timeline.tag +++ b/src/web/app/desktop/tags/user-timeline.tag @@ -50,89 +50,84 @@ this.mixin('is-promise'); this.mixin('get-post-summary'); - this.user = null - this.user-promise = if @is-promise this.opts.user then this.opts.user else Promise.resolve this.opts.user - this.is-loading = true - this.is-empty = false - this.more-loading = false - this.unread-count = 0 - this.mode = 'default' + this.user = null; + this.userPromise = this.isPromise(this.opts.user) + ? this.opts.user + : Promise.resolve(this.opts.user); + this.isLoading = true; + this.isEmpty = false; + this.moreLoading = false; + this.unreadCount = 0; + this.mode = 'default'; this.on('mount', () => { - document.addEventListener 'visibilitychange' @window-onVisibilitychange, false - document.addEventListener 'keydown' this.on-document-keydown - window.addEventListener 'scroll' this.on-scroll + document.addEventListener('keydown', this.onDocumentKeydown); + window.addEventListener('scroll', this.onScroll); - this.user-promise}).then((user) => { - this.user = user - this.update(); + this.userPromise.then(user => { + this.update({ + user: user + }); - @fetch => - this.trigger('loaded'); + this.fetch(() => this.trigger('loaded')); + }); this.on('unmount', () => { - document.removeEventListener 'visibilitychange' @window-onVisibilitychange - document.removeEventListener 'keydown' this.on-document-keydown - window.removeEventListener 'scroll' this.on-scroll + document.removeEventListener('keydown', this.onDocumentKeydown); + window.removeEventListener('scroll', this.onScroll); + }); - this.on-document-keydown = (e) => { - tag = e.target.tag-name.to-lower-case! - if tag != 'input' and tag != 'textarea' - if e.which == 84 // t + this.onDocumentKeydown = e => { + if (e.target.tagName !== 'INPUT' && e.target.tagName !== 'TEXTAREA') { + if (e.which == 84) { // [t] this.refs.timeline.focus(); + } + } + }; - this.fetch = (cb) => { + this.fetch = cb => { this.api('users/posts', { - user_id: this.user.id - with_replies: this.mode == 'with-replies' - }).then((posts) => { - this.is-loading = false - this.is-empty = posts.length == 0 - this.update(); - this.refs.timeline.set-posts posts - if cb? then cb! - .catch (err) => - console.error err - if cb? then cb! + user_id: this.user.id, + with_replies: this.mode == 'with-replies' + }).then(posts => { + this.update({ + isLoading: false, + isEmpty: posts.length == 0 + }); + this.refs.timeline.setPosts(posts); + if (cb) cb(); + }); + }; this.more = () => { - if @more-loading or @is-loading or this.refs.timeline.posts.length == 0 - return - this.more-loading = true - this.update(); + if (this.moreLoading || this.isLoading || this.refs.timeline.posts.length == 0) return; + this.update({ + moreLoading: true + }); this.api('users/posts', { - user_id: this.user.id - with_replies: this.mode == 'with-replies' - max_id: this.refs.timeline.tail!.id - }).then((posts) => { - this.more-loading = false - this.update(); - this.refs.timeline.prepend-posts posts - .catch (err) => - console.error err + user_id: this.user.id, + with_replies: this.mode == 'with-replies', + max_id: this.refs.timeline.tail().id + }).then(posts => { + this.update({ + moreLoading: false + }); + this.refs.timeline.prependPosts(posts); + }); + }; - this.on-stream-post = (post) => { - this.is-empty = false - this.update(); - this.refs.timeline.add-post post + this.onScroll = () => { + const current = window.scrollY + window.innerHeight; + if (current > document.body.offsetHeight - 16/*遊び*/) { + this.more(); + } + }; - if document.hidden - @unread-count++ - document.title = '(' + @unread-count + ') ' + @get-post-summary post - - this.window-onVisibilitychange = () => { - if !document.hidden - this.unread-count = 0 - document.title = 'Misskey' - - this.on-scroll = () => { - current = window.scrollY + window.inner-height - if current > document.body.offset-height - 16 // 遊び - @more! - - this.set-mode = (mode) => { - @update do + this.setMode = mode => { + this.update({ mode: mode - @fetch! + }); + this.fetch(); + }; diff --git a/src/web/app/desktop/tags/users-list.tag b/src/web/app/desktop/tags/users-list.tag index 2d85cd2ec..c94d0e228 100644 --- a/src/web/app/desktop/tags/users-list.tag +++ b/src/web/app/desktop/tags/users-list.tag @@ -1,7 +1,9 @@
@@ -9,8 +11,10 @@
- +

{ opts.noUsers }

読み込んでいます @@ -90,45 +94,48 @@ diff --git a/src/web/app/mobile/tags/home-timeline.tag b/src/web/app/mobile/tags/home-timeline.tag index 0d617c841..2cb051f32 100644 --- a/src/web/app/mobile/tags/home-timeline.tag +++ b/src/web/app/mobile/tags/home-timeline.tag @@ -3,41 +3,49 @@ diff --git a/src/web/app/mobile/tags/timeline.tag b/src/web/app/mobile/tags/timeline.tag index 06571e40e..421917d83 100644 --- a/src/web/app/mobile/tags/timeline.tag +++ b/src/web/app/mobile/tags/timeline.tag @@ -74,45 +74,58 @@ diff --git a/src/web/app/mobile/tags/ui-header.tag b/src/web/app/mobile/tags/ui-header.tag index 5cf2560d5..405db1897 100644 --- a/src/web/app/mobile/tags/ui-header.tag +++ b/src/web/app/mobile/tags/ui-header.tag @@ -89,16 +89,18 @@