(scroll) scroll on title click

This commit is contained in:
Julien Calixte
2021-03-14 21:51:38 +01:00
parent d624e064af
commit 0172ac5be3
3 changed files with 35 additions and 10 deletions

View File

@@ -1,14 +1,23 @@
import { NOTE_WIDTH } from '@/constants/note-width'
import { useOverlay } from '@/hooks/useOverlay.hook'
import { nextTick } from 'vue'
import { LocationQueryValue } from 'vue-router'
import { computed, nextTick } from 'vue'
import { LocationQueryValue, useRoute } from 'vue-router'
export const useFocus = () => {
const { scrollToNote } = useOverlay(false)
const { query } = useRoute()
const initialStackedNotes = computed(() =>
query.stackedNotes
? Array.isArray(query.stackedNotes)
? query.stackedNotes
: [query.stackedNotes]
: []
)
const scrollToFocusedNote = (
stackedNotes: LocationQueryValue[],
sha?: string
sha?: string,
stackedNotes: LocationQueryValue[] = initialStackedNotes.value
) => {
if (!sha) {
return

View File

@@ -61,7 +61,7 @@ export const useNote = (
}, {})
)
const unsubscribe = noteEventBus.addEventBusListener(
const unsubscribeLink = noteEventBus.addEventBusListener(
({ path, currentNoteSHA }) => {
const currentFile = tree.value.find((file) => file.sha === currentNoteSHA)
@@ -76,7 +76,7 @@ export const useNote = (
const file = tree.value.find((file) => file.path === finalPath)
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
scrollToFocusedNote(stackedNotes.value, file?.sha)
scrollToFocusedNote(file?.sha, stackedNotes.value)
return
}
@@ -115,7 +115,7 @@ export const useNote = (
stackedNotes.value = newStackedNotes
scrollToFocusedNote(stackedNotes.value, file.sha)
scrollToFocusedNote(file.sha, stackedNotes.value)
}
)
@@ -140,7 +140,7 @@ export const useNote = (
})
onUnmounted(() => {
unsubscribe()
unsubscribeLink()
})
watch(stackedNotes, resizeContainer, {