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

@@ -1,5 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, nextTick, ref, watch } from "vue" import { computed, nextTick, ref, watch } from "vue"
import { useRoute } from "vue-router"
import { errorMessage } from "@/utils/notif" import { errorMessage } from "@/utils/notif"
import { useATProtoLinks } from "@/hooks/useATProtoLinks.hook" import { useATProtoLinks } from "@/hooks/useATProtoLinks.hook"
import { useNoteOverlay } from "@/hooks/useNoteOverlay.hook" import { useNoteOverlay } from "@/hooks/useNoteOverlay.hook"
@@ -33,8 +34,16 @@ const url = computedAsync(async () =>
const className = computed(() => `stacked-note-${props.index}`) const className = computed(() => `stacked-note-${props.index}`)
const titleClassName = computed(() => `title-${className.value}`) const titleClassName = computed(() => `title-${className.value}`)
const route = useRoute()
const mainNoteId = computed(
() => `${route.params.shortDid}-${route.params.rkey}`,
)
const { scrollToFocusedNote } = useRouteQueryStackedNotes() const { scrollToFocusedNote } = useRouteQueryStackedNotes()
const { listenToClick } = useATProtoLinks(className.value, didrkey) const { listenToClick } = useATProtoLinks(className.value, {
currentAtUri: didrkey,
mainNoteId,
})
const { displayNoteOverlay } = useNoteOverlay(className.value, index) const { displayNoteOverlay } = useNoteOverlay(className.value, index)
const noteNotFound = ref(false) const noteNotFound = ref(false)

View File

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

View File

@@ -108,8 +108,10 @@ const language = computed(() =>
: null, : null,
) )
const mainNoteId = computed(() => `${props.shortDid}-${props.rkey}`)
const { stackedNotes, scrollToFocusedNote } = useRouteQueryStackedNotes() const { stackedNotes, scrollToFocusedNote } = useRouteQueryStackedNotes()
const { listenToClick } = useATProtoLinks("note-display") const { listenToClick } = useATProtoLinks("note-display", { mainNoteId })
useResizeContainer("note-container", stackedNotes) useResizeContainer("note-container", stackedNotes)
watch( watch(