diff --git a/src/hooks/usePublicNoteList.hook.ts b/src/hooks/usePublicNoteList.hook.ts new file mode 100644 index 0000000..22252e1 --- /dev/null +++ b/src/hooks/usePublicNoteList.hook.ts @@ -0,0 +1,43 @@ +import { Author, getAka } from "@/modules/atproto/getAka" +import { PublicNoteListItem } from "@/modules/note/models/Note" +import { computedAsync } from "@vueuse/core" +import { computed, ref, Ref } from "vue" + +export function usePublicNoteList(did?: Ref) { + const isLoading = ref(false) + const notes = ref([]) + const cursor = ref(null) + const canLoadMore = computed(() => cursor.value !== undefined) + + const onLoadMore = async () => { + isLoading.value = true + + const path = did?.value ? `/${did.value}/notes` : "/notes" + const noteAPI = new URL(path, "https://api.litenote.li212.fr") + + if (cursor.value) { + noteAPI.searchParams.set("cursor", cursor.value) + } + + const response = await fetch(noteAPI) + const data: { notes: PublicNoteListItem[]; cursor: string | undefined } = + await response.json() + + notes.value.push(...data.notes) + cursor.value = data.cursor + isLoading.value = false + } + + const aka = computedAsync>(async () => { + if (notes.value.length === 0) { + return new Map() + } + + return getAka(new Set(notes.value.map((n) => n.did))) + }, new Map()) + + const getAlias = (did: string) => + aka.value.has(did) ? aka.value.get(did)?.alias : "" + + return { notes, isLoading, canLoadMore, onLoadMore, aka, getAlias } +} diff --git a/src/router/router.ts b/src/router/router.ts index a293e81..37d3d1e 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -20,12 +20,18 @@ const routes: Array = [ component: () => import("@/views/PublicNoteListView.vue"), }, { - path: "/notes", + path: "/pub", name: "PublicNoteListView", component: () => import("@/views/PublicNoteListView.vue"), }, { - path: "/notes/:did/:rkey", + path: "/pub/:did", + name: "PublicNoteListByDidView", + props: true, + component: () => import("@/views/PublicNoteListByDidView.vue"), + }, + { + path: "/pub/:did/:rkey", name: "PublicNoteView", props: true, component: () => import("@/views/PublicNoteView.vue"), diff --git a/src/views/PublicNoteListByDidView.vue b/src/views/PublicNoteListByDidView.vue new file mode 100644 index 0000000..50e3259 --- /dev/null +++ b/src/views/PublicNoteListByDidView.vue @@ -0,0 +1,87 @@ + + + + + diff --git a/src/views/PublicNoteListView.vue b/src/views/PublicNoteListView.vue index d5ea1d5..0dec415 100644 --- a/src/views/PublicNoteListView.vue +++ b/src/views/PublicNoteListView.vue @@ -1,44 +1,10 @@