feat(client): Implement threaded replies

Resolve #2113
Resolve #5819
This commit is contained in:
syuilo 2020-05-10 16:22:39 +09:00
parent a482d9b078
commit 64bbfed432
2 changed files with 79 additions and 41 deletions

View File

@ -1,18 +1,21 @@
<template> <template>
<div class="wrpstxzv" v-size="[{ max: 450 }]"> <div class="wrpstxzv" :class="{ children }" v-size="[{ max: 450 }]">
<mk-avatar class="avatar" :user="note.user"/>
<div class="main"> <div class="main">
<x-note-header class="header" :note="note" :mini="true"/> <mk-avatar class="avatar" :user="note.user"/>
<div class="body"> <div class="body">
<p v-if="note.cw != null" class="cw"> <x-note-header class="header" :note="note" :mini="true"/>
<mfm v-if="note.cw != ''" class="text" :text="note.cw" :author="note.user" :i="$store.state.i" :custom-emojis="note.emojis" /> <div class="body">
<x-cw-button v-model="showContent" :note="note"/> <p v-if="note.cw != null" class="cw">
</p> <mfm v-if="note.cw != ''" class="text" :text="note.cw" :author="note.user" :i="$store.state.i" :custom-emojis="note.emojis" />
<div class="content" v-show="note.cw == null || showContent"> <x-cw-button v-model="showContent" :note="note"/>
<x-sub-note-content class="text" :note="note"/> </p>
<div class="content" v-show="note.cw == null || showContent">
<x-sub-note-content class="text" :note="note"/>
</div>
</div> </div>
</div> </div>
</div> </div>
<x-sub v-for="reply in replies" :key="reply.id" :note="reply" class="reply" :detail="true" :children="true"/>
</div> </div>
</template> </template>
@ -23,6 +26,8 @@ import XSubNoteContent from './sub-note-content.vue';
import XCwButton from './cw-button.vue'; import XCwButton from './cw-button.vue';
export default Vue.extend({ export default Vue.extend({
name: 'x-sub',
components: { components: {
XNoteHeader, XNoteHeader,
XSubNoteContent, XSubNoteContent,
@ -34,6 +39,16 @@ export default Vue.extend({
type: Object, type: Object,
required: true required: true
}, },
detail: {
type: Boolean,
required: false,
default: false
},
children: {
type: Boolean,
required: false,
default: false
},
// TODO // TODO
truncate: { truncate: {
type: Boolean, type: Boolean,
@ -41,23 +56,28 @@ export default Vue.extend({
} }
}, },
inject: {
narrow: {
default: false
}
},
data() { data() {
return { return {
showContent: false showContent: false,
replies: [],
}; };
} },
created() {
if (this.detail) {
this.$root.api('notes/children', {
noteId: this.note.id,
limit: 5
}).then(replies => {
this.replies = replies;
});
}
},
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.wrpstxzv { .wrpstxzv {
display: flex;
padding: 16px 32px; padding: 16px 32px;
font-size: 0.9em; font-size: 0.9em;
@ -65,43 +85,61 @@ export default Vue.extend({
padding: 14px 16px; padding: 14px 16px;
} }
> .avatar { &.children {
flex-shrink: 0; padding: 10px 0 0 16px;
display: block; font-size: 1em;
margin: 0 8px 0 0;
width: 38px; &.max-width_450px {
height: 38px; padding: 10px 0 0 8px;
border-radius: 8px; }
} }
> .main { > .main {
flex: 1; display: flex;
min-width: 0;
> .header { > .avatar {
margin-bottom: 2px; flex-shrink: 0;
display: block;
margin: 0 8px 0 0;
width: 38px;
height: 38px;
border-radius: 8px;
} }
> .body { > .body {
> .cw { flex: 1;
cursor: default; min-width: 0;
display: block;
margin: 0;
padding: 0;
overflow-wrap: break-word;
> .text { > .header {
margin-right: 8px; margin-bottom: 2px;
}
} }
> .content { > .body {
> .text { > .cw {
cursor: default;
display: block;
margin: 0; margin: 0;
padding: 0; padding: 0;
overflow-wrap: break-word;
> .text {
margin-right: 8px;
}
}
> .content {
> .text {
margin: 0;
padding: 0;
}
} }
} }
} }
} }
> .reply {
border-left: solid 1px var(--divider);
margin-top: 10px;
}
} }
</style> </style>

View File

@ -79,7 +79,7 @@
<div class="deleted" v-if="appearNote.deletedAt != null">{{ $t('deleted') }}</div> <div class="deleted" v-if="appearNote.deletedAt != null">{{ $t('deleted') }}</div>
</div> </div>
</article> </article>
<x-sub v-for="note in replies" :key="note.id" :note="note" class="reply"/> <x-sub v-for="note in replies" :key="note.id" :note="note" class="reply" :detail="true"/>
</div> </div>
</template> </template>