✨ (scroll) scroll on title click
This commit is contained in:
@@ -3,7 +3,11 @@
|
|||||||
class="stacked-note"
|
class="stacked-note"
|
||||||
:class="{ [className]: true, overlay: displayNoteOverlay }"
|
:class="{ [className]: true, overlay: displayNoteOverlay }"
|
||||||
>
|
>
|
||||||
<div class="title-stacked-note" :class="titleClassName">{{ title }}</div>
|
<div class="title-stacked-note" :class="titleClassName">
|
||||||
|
<a @click.prevent="focus">
|
||||||
|
{{ title }}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<section v-html="content"></section>
|
<section v-html="content"></section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -13,6 +17,7 @@ import { computed, defineComponent, nextTick, watch } from 'vue'
|
|||||||
import { useFile } from '@/hooks/useFile.hook'
|
import { useFile } from '@/hooks/useFile.hook'
|
||||||
import { useLinks } from '@/hooks/useLinks.hook'
|
import { useLinks } from '@/hooks/useLinks.hook'
|
||||||
import { useNoteOverlay } from '@/hooks/useNoteOverlay.hook'
|
import { useNoteOverlay } from '@/hooks/useNoteOverlay.hook'
|
||||||
|
import { useFocus } from '@/hooks/useFocus.hook'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'StackedNote',
|
name: 'StackedNote',
|
||||||
@@ -26,6 +31,7 @@ export default defineComponent({
|
|||||||
setup(props) {
|
setup(props) {
|
||||||
const { content } = useFile(props.user, props.repo, props.sha)
|
const { content } = useFile(props.user, props.repo, props.sha)
|
||||||
const { listenToClick } = useLinks('stacked-note', props.sha)
|
const { listenToClick } = useLinks('stacked-note', props.sha)
|
||||||
|
const { scrollToFocusedNote } = useFocus()
|
||||||
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}`)
|
||||||
|
|
||||||
@@ -39,7 +45,13 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return { content, titleClassName, className, displayNoteOverlay }
|
return {
|
||||||
|
content,
|
||||||
|
titleClassName,
|
||||||
|
className,
|
||||||
|
displayNoteOverlay,
|
||||||
|
focus: () => scrollToFocusedNote(props.sha)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -64,6 +76,10 @@ $border-color: rgba(18, 19, 58, 0.2);
|
|||||||
top: 1rem;
|
top: 1rem;
|
||||||
left: 1.5rem;
|
left: 1.5rem;
|
||||||
direction: rtl;
|
direction: rtl;
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #363636;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 768px) {
|
@media screen and (max-width: 768px) {
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
import { NOTE_WIDTH } from '@/constants/note-width'
|
import { NOTE_WIDTH } from '@/constants/note-width'
|
||||||
import { useOverlay } from '@/hooks/useOverlay.hook'
|
import { useOverlay } from '@/hooks/useOverlay.hook'
|
||||||
import { nextTick } from 'vue'
|
import { computed, nextTick } from 'vue'
|
||||||
import { LocationQueryValue } from 'vue-router'
|
import { LocationQueryValue, useRoute } from 'vue-router'
|
||||||
|
|
||||||
export const useFocus = () => {
|
export const useFocus = () => {
|
||||||
const { scrollToNote } = useOverlay(false)
|
const { scrollToNote } = useOverlay(false)
|
||||||
|
const { query } = useRoute()
|
||||||
|
|
||||||
|
const initialStackedNotes = computed(() =>
|
||||||
|
query.stackedNotes
|
||||||
|
? Array.isArray(query.stackedNotes)
|
||||||
|
? query.stackedNotes
|
||||||
|
: [query.stackedNotes]
|
||||||
|
: []
|
||||||
|
)
|
||||||
|
|
||||||
const scrollToFocusedNote = (
|
const scrollToFocusedNote = (
|
||||||
stackedNotes: LocationQueryValue[],
|
sha?: string,
|
||||||
sha?: string
|
stackedNotes: LocationQueryValue[] = initialStackedNotes.value
|
||||||
) => {
|
) => {
|
||||||
if (!sha) {
|
if (!sha) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export const useNote = (
|
|||||||
}, {})
|
}, {})
|
||||||
)
|
)
|
||||||
|
|
||||||
const unsubscribe = noteEventBus.addEventBusListener(
|
const unsubscribeLink = noteEventBus.addEventBusListener(
|
||||||
({ path, currentNoteSHA }) => {
|
({ path, currentNoteSHA }) => {
|
||||||
const currentFile = tree.value.find((file) => file.sha === 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)
|
const file = tree.value.find((file) => file.path === finalPath)
|
||||||
|
|
||||||
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
|
if (!file?.sha || stackedNotes.value.includes(file.sha)) {
|
||||||
scrollToFocusedNote(stackedNotes.value, file?.sha)
|
scrollToFocusedNote(file?.sha, stackedNotes.value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ export const useNote = (
|
|||||||
|
|
||||||
stackedNotes.value = newStackedNotes
|
stackedNotes.value = newStackedNotes
|
||||||
|
|
||||||
scrollToFocusedNote(stackedNotes.value, file.sha)
|
scrollToFocusedNote(file.sha, stackedNotes.value)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ export const useNote = (
|
|||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
unsubscribe()
|
unsubscribeLink()
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(stackedNotes, resizeContainer, {
|
watch(stackedNotes, resizeContainer, {
|
||||||
|
|||||||
Reference in New Issue
Block a user