From e707c3d5e3908c78e7ffcfda2c91ff3eda4c5954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=93=E3=81=B4=E3=81=AA=E3=81=9F=E3=81=BF=E3=81=BD?= <syuilotan@yahoo.co.jp> Date: Tue, 20 Feb 2018 09:48:30 +0900 Subject: [PATCH] wip --- .../desktop/-tags/home-widgets/mentions.tag | 125 ------------------ .../app/desktop/views/components/mentions.vue | 123 +++++++++++++++++ .../app/desktop/views/components/timeline.vue | 4 +- 3 files changed, 125 insertions(+), 127 deletions(-) delete mode 100644 src/web/app/desktop/-tags/home-widgets/mentions.tag create mode 100644 src/web/app/desktop/views/components/mentions.vue diff --git a/src/web/app/desktop/-tags/home-widgets/mentions.tag b/src/web/app/desktop/-tags/home-widgets/mentions.tag deleted file mode 100644 index d38ccabb52..0000000000 --- a/src/web/app/desktop/-tags/home-widgets/mentions.tag +++ /dev/null @@ -1,125 +0,0 @@ -<mk-mentions-home-widget> - <header><span data-is-active={ mode == 'all' } @click="setMode.bind(this, 'all')">ã™ã¹ã¦</span><span data-is-active={ mode == 'following' } @click="setMode.bind(this, 'following')">フォãƒãƒ¼ä¸</span></header> - <div class="loading" v-if="isLoading"> - <mk-ellipsis-icon/> - </div> - <p class="empty" v-if="isEmpty">%fa:R comments%<span v-if="mode == 'all'">ã‚ãªãŸå®›ã¦ã®æŠ•ç¨¿ã¯ã‚ã‚Šã¾ã›ã‚“。</span><span v-if="mode == 'following'">ã‚ãªãŸãŒãƒ•ã‚©ãƒãƒ¼ã—ã¦ã„るユーザーã‹ã‚‰ã®è¨€åŠã¯ã‚ã‚Šã¾ã›ã‚“。</span></p> - <mk-timeline ref="timeline"> - <yield to="footer"> - <template v-if="!parent.moreLoading">%fa:moon%</template> - <template v-if="parent.moreLoading">%fa:spinner .pulse .fw%</template> - </yield/> - </mk-timeline> - <style lang="stylus" scoped> - :scope - display block - background #fff - border solid 1px rgba(0, 0, 0, 0.075) - border-radius 6px - - > header - padding 8px 16px - border-bottom solid 1px #eee - - > span - margin-right 16px - line-height 27px - font-size 18px - color #555 - - &:not([data-is-active]) - color $theme-color - cursor pointer - - &:hover - text-decoration underline - - > .loading - padding 64px 0 - - > .empty - display block - margin 0 auto - padding 32px - max-width 400px - text-align center - color #999 - - > [data-fa] - display block - margin-bottom 16px - font-size 3em - color #ccc - - </style> - <script lang="typescript"> - this.mixin('i'); - this.mixin('api'); - - this.isLoading = true; - this.isEmpty = false; - this.moreLoading = false; - this.mode = 'all'; - - this.on('mount', () => { - document.addEventListener('keydown', this.onDocumentKeydown); - window.addEventListener('scroll', this.onScroll); - - this.fetch(() => this.$emit('loaded')); - }); - - this.on('unmount', () => { - document.removeEventListener('keydown', this.onDocumentKeydown); - window.removeEventListener('scroll', this.onScroll); - }); - - this.onDocumentKeydown = e => { - if (e.target.tagName != 'INPUT' && tag != 'TEXTAREA') { - if (e.which == 84) { // t - this.$refs.timeline.focus(); - } - } - }; - - this.fetch = cb => { - this.$root.$data.os.api('posts/mentions', { - following: this.mode == 'following' - }).then(posts => { - this.update({ - isLoading: false, - isEmpty: posts.length == 0 - }); - this.$refs.timeline.setPosts(posts); - if (cb) cb(); - }); - }; - - this.more = () => { - if (this.moreLoading || this.isLoading || this.$refs.timeline.posts.length == 0) return; - this.update({ - moreLoading: true - }); - this.$root.$data.os.api('posts/mentions', { - following: this.mode == 'following', - until_id: this.$refs.timeline.tail().id - }).then(posts => { - this.update({ - moreLoading: false - }); - this.$refs.timeline.prependPosts(posts); - }); - }; - - this.onScroll = () => { - const current = window.scrollY + window.innerHeight; - if (current > document.body.offsetHeight - 8) this.more(); - }; - - this.setMode = mode => { - this.update({ - mode: mode - }); - this.fetch(); - }; - </script> -</mk-mentions-home-widget> diff --git a/src/web/app/desktop/views/components/mentions.vue b/src/web/app/desktop/views/components/mentions.vue new file mode 100644 index 0000000000..28ba59f2b1 --- /dev/null +++ b/src/web/app/desktop/views/components/mentions.vue @@ -0,0 +1,123 @@ +<template> +<div class="mk-mentions"> + <header> + <span :data-is-active="mode == 'all'" @click="mode = 'all'">ã™ã¹ã¦</span> + <span :data-is-active="mode == 'following'" @click="mode = 'following'">フォãƒãƒ¼ä¸</span> + </header> + <div class="fetching" v-if="fetching"> + <mk-ellipsis-icon/> + </div> + <p class="empty" v-if="posts.length == 0 && !fetching"> + %fa:R comments% + <span v-if="mode == 'all'">ã‚ãªãŸå®›ã¦ã®æŠ•ç¨¿ã¯ã‚ã‚Šã¾ã›ã‚“。</span> + <span v-if="mode == 'following'">ã‚ãªãŸãŒãƒ•ã‚©ãƒãƒ¼ã—ã¦ã„るユーザーã‹ã‚‰ã®è¨€åŠã¯ã‚ã‚Šã¾ã›ã‚“。</span> + </p> + <mk-posts :posts="posts" ref="timeline"/> +</div> +</template> + +<script lang="ts"> +import Vue from 'vue'; +export default Vue.extend({ + data() { + return { + fetching: true, + moreFetching: false, + mode: 'all', + posts: [] + }; + }, + watch: { + mode() { + this.fetch(); + } + }, + mounted() { + document.addEventListener('keydown', this.onDocumentKeydown); + window.addEventListener('scroll', this.onScroll); + + this.fetch(() => this.$emit('loaded')); + }, + beforeDestroy() { + document.removeEventListener('keydown', this.onDocumentKeydown); + window.removeEventListener('scroll', this.onScroll); + }, + methods: { + onDocumentKeydown(e) { + if (e.target.tagName != 'INPUT' && e.target.tagName != 'TEXTAREA') { + if (e.which == 84) { // t + (this.$refs.timeline as any).focus(); + } + } + }, + onScroll() { + const current = window.scrollY + window.innerHeight; + if (current > document.body.offsetHeight - 8) this.more(); + }, + fetch(cb?) { + this.fetching = true; + this.posts = []; + (this as any).api('posts/mentions', { + following: this.mode == 'following' + }).then(posts => { + this.posts = posts; + this.fetching = false; + if (cb) cb(); + }); + }, + more() { + if (this.moreFetching || this.fetching || this.posts.length == 0) return; + this.moreFetching = true; + (this as any).api('posts/mentions', { + following: this.mode == 'following', + until_id: this.posts[this.posts.length - 1].id + }).then(posts => { + this.posts = this.posts.concat(posts); + this.moreFetching = false; + }); + } + } +}); +</script> + +<style lang="stylus" scoped> +.mk-mentions + background #fff + border solid 1px rgba(0, 0, 0, 0.075) + border-radius 6px + + > header + padding 8px 16px + border-bottom solid 1px #eee + + > span + margin-right 16px + line-height 27px + font-size 18px + color #555 + + &:not([data-is-active]) + color $theme-color + cursor pointer + + &:hover + text-decoration underline + + > .fetching + padding 64px 0 + + > .empty + display block + margin 0 auto + padding 32px + max-width 400px + text-align center + color #999 + + > [data-fa] + display block + margin-bottom 16px + font-size 3em + color #ccc + +</style> diff --git a/src/web/app/desktop/views/components/timeline.vue b/src/web/app/desktop/views/components/timeline.vue index 3e06774753..875a7961e4 100644 --- a/src/web/app/desktop/views/components/timeline.vue +++ b/src/web/app/desktop/views/components/timeline.vue @@ -1,7 +1,7 @@ <template> <div class="mk-timeline"> <mk-friends-maker v-if="alone"/> - <div class="loading" v-if="fetching"> + <div class="fetching" v-if="fetching"> <mk-ellipsis-icon/> </div> <p class="empty" v-if="posts.length == 0 && !fetching">%fa:R comments%自分ã®æŠ•ç¨¿ã‚„ã€è‡ªåˆ†ãŒãƒ•ã‚©ãƒãƒ¼ã—ã¦ã„るユーザーã®æŠ•ç¨¿ãŒè¡¨ç¤ºã•ã‚Œã¾ã™ã€‚</p> @@ -106,7 +106,7 @@ export default Vue.extend({ > .mk-following-setuper border-bottom solid 1px #eee - > .loading + > .fetching padding 64px 0 > .empty -- GitLab