This commit is contained in:
syuilo 2018-04-26 11:19:57 +09:00
parent 3972e98f74
commit a2a3dd55ad
3 changed files with 57 additions and 36 deletions

View file

@ -46,6 +46,8 @@ export default Vue.extend({
const w = (this as any).os.new(MkUserListsWindow); const w = (this as any).os.new(MkUserListsWindow);
w.$once('choosen', list => { w.$once('choosen', list => {
this.list = list; this.list = list;
this.src = 'list';
w.close();
}); });
} }
} }

View file

@ -1,9 +1,11 @@
<template> <template>
<mk-window ref="window" is-modal width="500px" height="550px" @closed="$destroy"> <mk-window ref="window" is-modal width="450px" height="500px" @closed="$destroy">
<span slot="header">%fa:list% リスト</span> <span slot="header">%fa:list% リスト</span>
<button class="ui" @click="add">リストを作成</button> <div data-id="6e4caea3-d8f9-4ab7-96de-ab67fe8d5c82" :data-darkmode="_darkmode_">
<a v-for="list in lists" :key="list.id" @click="choice(list)">{{ list.title }}</a> <button class="ui" @click="add">リストを作成</button>
<a v-for="list in lists" :key="list.id" @click="choice(list)">{{ list.title }}</a>
</div>
</mk-window> </mk-window>
</template> </template>
@ -46,4 +48,22 @@ export default Vue.extend({
<style lang="stylus" scoped> <style lang="stylus" scoped>
root(isDark)
padding 16px
> button
margin-bottom 16px
> a
display block
padding 16px
border solid 1px isDark ? #1c2023 : #eee
border-radius 4px
[data-id="6e4caea3-d8f9-4ab7-96de-ab67fe8d5c82"][data-darkmode]
root(true)
[data-id="6e4caea3-d8f9-4ab7-96de-ab67fe8d5c82"]:not([data-darkmode])
root(false)
</style> </style>

View file

@ -8,35 +8,29 @@
<div class="loading" v-if="fetching"> <div class="loading" v-if="fetching">
<mk-ellipsis-icon/> <mk-ellipsis-icon/>
</div> </div>
<p class="empty" v-if="empty">%fa:R comments%このユーザーはまだ何も投稿していないようです</p> <mk-notes ref="timeline" :more="existMore ? more : null">
<mk-notes ref="timeline" :notes="notes"> <p class="empty" slot="empty">%fa:R comments%このユーザーはまだ何も投稿していないようです</p>
<div slot="footer">
<template v-if="!moreFetching">%fa:moon%</template>
<template v-if="moreFetching">%fa:spinner .pulse .fw%</template>
</div>
</mk-notes> </mk-notes>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
const fetchLimit = 10;
export default Vue.extend({ export default Vue.extend({
props: ['user'], props: ['user'],
data() { data() {
return { return {
fetching: true, fetching: true,
moreFetching: false, moreFetching: false,
existMore: false,
mode: 'default', mode: 'default',
unreadCount: 0, unreadCount: 0,
notes: [],
date: null date: null
}; };
}, },
computed: {
empty(): boolean {
return this.notes.length == 0;
}
},
watch: { watch: {
mode() { mode() {
this.fetch(); this.fetch();
@ -44,13 +38,11 @@ export default Vue.extend({
}, },
mounted() { mounted() {
document.addEventListener('keydown', this.onDocumentKeydown); document.addEventListener('keydown', this.onDocumentKeydown);
window.addEventListener('scroll', this.onScroll);
this.fetch(() => this.$emit('loaded')); this.fetch(() => this.$emit('loaded'));
}, },
beforeDestroy() { beforeDestroy() {
document.removeEventListener('keydown', this.onDocumentKeydown); document.removeEventListener('keydown', this.onDocumentKeydown);
window.removeEventListener('scroll', this.onScroll);
}, },
methods: { methods: {
onDocumentKeydown(e) { onDocumentKeydown(e) {
@ -61,36 +53,43 @@ export default Vue.extend({
} }
}, },
fetch(cb?) { fetch(cb?) {
(this as any).api('users/notes', { this.fetching = true;
userId: this.user.id, (this.$refs.timeline as any).init(() => new Promise((res, rej) => {
untilDate: this.date ? this.date.getTime() : undefined, (this as any).api('users/notes', {
includeReplies: this.mode == 'with-replies', userId: this.user.id,
withMedia: this.mode == 'with-media' limit: fetchLimit + 1,
}).then(notes => { untilDate: this.date ? this.date.getTime() : undefined,
this.notes = notes; includeReplies: this.mode == 'with-replies',
this.fetching = false; withMedia: this.mode == 'with-media'
if (cb) cb(); }).then(notes => {
}); if (notes.length == fetchLimit + 1) {
notes.pop();
this.existMore = true;
}
res(notes);
this.fetching = false;
if (cb) cb();
}, rej);
}));
}, },
more() { more() {
if (this.moreFetching || this.fetching || this.notes.length == 0) return;
this.moreFetching = true; this.moreFetching = true;
(this as any).api('users/notes', { (this as any).api('users/notes', {
userId: this.user.id, userId: this.user.id,
limit: fetchLimit + 1,
includeReplies: this.mode == 'with-replies', includeReplies: this.mode == 'with-replies',
withMedia: this.mode == 'with-media', withMedia: this.mode == 'with-media',
untilId: this.notes[this.notes.length - 1].id untilId: (this.$refs.timeline as any).tail().id
}).then(notes => { }).then(notes => {
if (notes.length == fetchLimit + 1) {
notes.pop();
} else {
this.existMore = false;
}
notes.forEach(n => (this.$refs.timeline as any).append(n));
this.moreFetching = false; this.moreFetching = false;
this.notes = this.notes.concat(notes);
}); });
}, },
onScroll() {
const current = window.scrollY + window.innerHeight;
if (current > document.body.offsetHeight - 16/*遊び*/) {
this.more();
}
},
warp(date) { warp(date) {
this.date = date; this.date = date;
this.fetch(); this.fetch();