refactor: welcome.timeline.vue to composition api #45

Merged
toast merged 1 commit from :refactor/welcome.timeline.vue into main 2022-07-30 12:24:54 +00:00

View file

@ -1,7 +1,7 @@
<template> <template>
<div class="civpbkhh"> <div class="civpbkhh">
<div ref="scroll" class="scrollbox" v-bind:class="{ scroll: isScrolling }"> <div ref="scroll" class="scrollbox" :class="{ scroll: isScrolling }">
<div v-for="note in notes" class="note"> <div v-for="note in notes" :key="note.id" class="note">
<div class="content _panel"> <div class="content _panel">
<div class="body"> <div class="body">
<MkA v-if="note.replyId" class="reply" :to="`/notes/${note.replyId}`"><i class="fas fa-reply"></i></MkA> <MkA v-if="note.replyId" class="reply" :to="`/notes/${note.replyId}`"><i class="fas fa-reply"></i></MkA>
@ -12,7 +12,7 @@
<XMediaList :media-list="note.files"/> <XMediaList :media-list="note.files"/>
</div> </div>
<div v-if="note.poll"> <div v-if="note.poll">
<XPoll :note="note" :readOnly="true"/> <XPoll :note="note" :read-only="true"/>
</div> </div>
</div> </div>
<XReactionsViewer ref="reactionsViewer" :note="note"/> <XReactionsViewer ref="reactionsViewer" :note="note"/>
@ -21,37 +21,26 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { onUpdated, ref, Ref } from 'vue';
import { Note } from 'misskey-js/built/entities';
import XReactionsViewer from '@/components/reactions-viewer.vue'; import XReactionsViewer from '@/components/reactions-viewer.vue';
import XMediaList from '@/components/media-list.vue'; import XMediaList from '@/components/media-list.vue';
import XPoll from '@/components/poll.vue'; import XPoll from '@/components/poll.vue';
import * as os from '@/os'; import * as os from '@/os';
import { $i } from '@/account';
export default defineComponent({ const notes: Ref<Note[]> = ref([]);
components: { const isScrolling = ref(false);
XReactionsViewer, const scroll: Ref<HTMLElement | null> = ref(null);
XMediaList,
XPoll
},
data() { os.api('notes/featured').then(newNotes => {
return { notes.value = newNotes;
notes: [], });
isScrolling: false,
};
},
created() { onUpdated(() => {
os.api('notes/featured').then(notes => { if (scroll.value && scroll.value.clientHeight > window.innerHeight) {
this.notes = notes; isScrolling.value = true;
});
},
updated() {
if (this.$refs.scroll.clientHeight > window.innerHeight) {
this.isScrolling = true;
}
} }
}); });
</script> </script>