refactor: extract useResizeContainer hook from useNoteView

This commit is contained in:
Julien Calixte
2026-02-14 23:40:43 +01:00
parent 9a05b58131
commit 77c1f41b6d
3 changed files with 42 additions and 32 deletions

View 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,
})
}