refactor: extract PublicNoteList shared component
Move the duplicated <ul> + infinite scroll + note row markup into a new PublicNoteList component with a #meta scoped slot. Both list views now delegate rendering to it, supplying only their view-specific author/date markup via the slot.
This commit is contained in:
65
src/components/PublicNoteList.vue
Normal file
65
src/components/PublicNoteList.vue
Normal file
@@ -0,0 +1,65 @@
|
||||
<script setup lang="ts">
|
||||
import { PublicNoteListItem } from "@/modules/note/models/Note"
|
||||
import { slugify } from "@/utils/slugify"
|
||||
import { vInfiniteScroll } from "@vueuse/components"
|
||||
|
||||
defineProps<{
|
||||
notes: PublicNoteListItem[]
|
||||
canLoadMore: boolean
|
||||
onLoadMore: () => Promise<void>
|
||||
}>()
|
||||
|
||||
defineSlots<{
|
||||
meta(props: { note: PublicNoteListItem }): unknown
|
||||
}>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ul
|
||||
class="list rounded-box shadow-sm"
|
||||
v-infinite-scroll="[onLoadMore, { canLoadMore: () => canLoadMore }]"
|
||||
>
|
||||
<li v-for="note in notes" class="list-row">
|
||||
<div class="list-col">
|
||||
<router-link
|
||||
:to="{
|
||||
name: 'PublicNoteView',
|
||||
params: {
|
||||
did: note.did,
|
||||
rkey: note.rkey,
|
||||
slug: slugify(note.title),
|
||||
},
|
||||
}"
|
||||
class="btn btn-link"
|
||||
>{{ note.title }}</router-link
|
||||
>
|
||||
<div class="text-xs opacity-80 alias">
|
||||
<slot name="meta" :note="note" />
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
li {
|
||||
display: flex;
|
||||
|
||||
.list-col {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
a {
|
||||
display: inline;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.alias {
|
||||
text-align: right;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user