feat: add public notes by author page

Extract note-list fetching into usePublicNoteList composable, add
/pub/:did route to view notes from a single author, and make author
aliases clickable links in both the note list and note view.
This commit is contained in:
Julien Calixte
2026-02-15 13:18:59 +01:00
parent bf73f08cb2
commit ff8795581e
5 changed files with 156 additions and 42 deletions

View File

@@ -1,44 +1,10 @@
<script setup lang="ts">
import BackButton from "@/components/BackButton.vue"
import { Author, getAka } from "@/modules/atproto/getAka"
import { PublicNoteListItem } from "@/modules/note/models/Note"
import { computedAsync } from "@vueuse/core"
import { computed, ref } from "vue"
import { usePublicNoteList } from "@/hooks/usePublicNoteList.hook"
import { vInfiniteScroll } from "@vueuse/components"
const isLoading = ref(false)
const notes = ref<PublicNoteListItem[]>([])
const cursor = ref<string | null | undefined>(null)
const canLoadMore = computed(() => cursor.value !== undefined)
const onLoadMore = async () => {
isLoading.value = true
const noteAPI = new URL("/notes", "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<Map<string, Author>>(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 : ""
const { notes, isLoading, canLoadMore, onLoadMore, getAlias } =
usePublicNoteList()
</script>
<template>
@@ -63,9 +29,16 @@ const getAlias = (did: string) =>
>
<div class="text-xs opacity-80 alias">
<span v-if="getAlias(note.did)">
<router-link
v-if="getAlias(note.did)"
:to="{
name: 'PublicNoteListByDidView',
params: { did: note.did },
}"
class="link link-hover"
>
{{ getAlias(note.did) }}
</span>
</router-link>
<span v-if="note.publishedAt"
>&nbsp;&nbsp;{{
new Date(note.publishedAt).toLocaleDateString()