refactor: extract useResizeContainer hook from useNoteView
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
import { computed, onMounted, onUnmounted, watch } from "vue"
|
||||
import { computed, onUnmounted } from "vue"
|
||||
|
||||
import { noteEventBus } from "@/bus/noteEventBus"
|
||||
import { NOTE_WIDTH } from "@/constants/note-width"
|
||||
import { useOverlay } from "@/hooks/useOverlay.hook"
|
||||
import { useRouteQueryStackedNotes } from "@/hooks/useRouteQueryStackedNotes.hook"
|
||||
import { resolvePath } from "@/modules/repo/services/resolvePath"
|
||||
import { useUserRepoStore } from "@/modules/repo/store/userRepo.store"
|
||||
import { pathToNotePathTitle } from "@/utils/noteTitle"
|
||||
import { errorMessage } from "@/utils/notif"
|
||||
|
||||
export const useNoteView = (containerClass: string) => {
|
||||
export const useNoteView = () => {
|
||||
const store = useUserRepoStore()
|
||||
const { isMobile } = useOverlay(false)
|
||||
const { stackedNotes, addStackedNote } = useRouteQueryStackedNotes()
|
||||
|
||||
const titles = computed(() =>
|
||||
@@ -45,36 +42,10 @@ export const useNoteView = (containerClass: string) => {
|
||||
},
|
||||
)
|
||||
|
||||
const resizeContainer = () => {
|
||||
const container = document.querySelector(
|
||||
`.${containerClass}`,
|
||||
) as HTMLElement | null
|
||||
|
||||
if (!container) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isMobile.value) {
|
||||
container.style.height = `${(stackedNotes.value.length + 1) * 100}vh`
|
||||
} else {
|
||||
container.style.width = `${
|
||||
NOTE_WIDTH * (stackedNotes.value.length + 1)
|
||||
}px`
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
resizeContainer()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
unsubscribeLink()
|
||||
})
|
||||
|
||||
watch(stackedNotes, resizeContainer, {
|
||||
immediate: true,
|
||||
})
|
||||
|
||||
return {
|
||||
titles,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user