From db38eaf6391e948c352d6e8759605d017471a640 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Wed, 19 Jul 2023 17:25:44 +0200 Subject: [PATCH] scope use links --- src/components/StackedNote.vue | 2 +- src/hooks/useLinks.hook.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/StackedNote.vue b/src/components/StackedNote.vue index 79f959c..1142d84 100644 --- a/src/components/StackedNote.vue +++ b/src/components/StackedNote.vue @@ -24,8 +24,8 @@ const props = defineProps<{ const { scrollToFocusedNote } = useQueryStackedNotes() const { content } = useFile(props.sha) -const { listenToClick } = useLinks('stacked-note', props.sha) const className = computed(() => `stacked-note-${props.index}`) +const { listenToClick } = useLinks(className.value, props.sha) const titleClassName = computed(() => `title-${className.value}`) useTitleNotes(props.repo) diff --git a/src/hooks/useLinks.hook.ts b/src/hooks/useLinks.hook.ts index d3b2b50..d21fde4 100644 --- a/src/hooks/useLinks.hook.ts +++ b/src/hooks/useLinks.hook.ts @@ -1,9 +1,12 @@ import { noteEventBus } from '@/bus/noteEventBus' import { useUserRepoStore } from '@/modules/repo/store/userRepo.store' import { isExternalLink } from '@/utils/link' -import { onUnmounted } from 'vue' +import { ComputedRef, onUnmounted, toValue } from 'vue' -export const useLinks = (className: string, sha?: string) => { +export const useLinks = ( + className: ComputedRef | string, + sha?: string +) => { const store = useUserRepoStore() const linkNote: EventListener = (event) => { @@ -34,7 +37,7 @@ export const useLinks = (className: string, sha?: string) => { }) } - const selector = `.${className} a` + const selector = `.${toValue(className)} a` const removeListeners = () => { const elements = document.querySelectorAll(selector)