refactor: extract useResizeContainer hook from useNoteView
This commit is contained in:
37
src/hooks/useResizeContainer.hook.ts
Normal file
37
src/hooks/useResizeContainer.hook.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { onMounted, watch, type Ref } from "vue"
|
||||
|
||||
import { NOTE_WIDTH } from "@/constants/note-width"
|
||||
import { useOverlay } from "@/hooks/useOverlay.hook"
|
||||
|
||||
export const useResizeContainer = (
|
||||
containerClass: string,
|
||||
stackedNotes: Readonly<Ref<readonly string[]>>,
|
||||
) => {
|
||||
const { isMobile } = useOverlay(false)
|
||||
|
||||
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()
|
||||
})
|
||||
|
||||
watch(stackedNotes, resizeContainer, {
|
||||
immediate: true,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user