fix: prevent stacking a duplicate of the main note when clicking a self-link

This commit is contained in:
Julien Calixte
2026-03-21 22:59:10 +01:00
parent c0b1a33c69
commit 32f79785a8
3 changed files with 30 additions and 4 deletions

View File

@@ -8,9 +8,14 @@ import { router } from "@/router/router"
export const useATProtoLinks = (
className: ComputedRef<string> | string,
currentAtUri?: Ref<string> | string,
options: {
currentAtUri?: Ref<string> | string | ComputedRef<string>
mainNoteId: Ref<string> | string | ComputedRef<string>
},
) => {
const { addStackedNote } = useRouteQueryStackedNotes()
const { addStackedNote, scrollToFocusedNote } = useRouteQueryStackedNotes()
const { currentAtUri, mainNoteId } = options
const linkNote = (event: Event) => {
const target = event.target as HTMLElement
const href = target.getAttribute("href")
@@ -44,6 +49,11 @@ export const useATProtoLinks = (
? `${params.shortDid}-${params.rkey}-${params.slug}`
: `${params.shortDid}-${params.rkey}`
if (noteId === toValue(mainNoteId)) {
scrollToFocusedNote(null)
return
}
addStackedNote(
toValue(currentAtUri) ?? "",
noteId,
@@ -56,6 +66,11 @@ export const useATProtoLinks = (
const { did, rkey } = parseAtUri(href)
const noteId = `${toShortDid(did)}-${rkey}`
if (noteId === toValue(mainNoteId)) {
scrollToFocusedNote(null)
return
}
addStackedNote(toValue(currentAtUri) ?? "", noteId)
}
}