Compare commits

..

No commits in common. "fd1d55de5d386f6f72c300034486939055ed8b80" and "10717432907d0ad86a1fef6a58567ebb126690ec" have entirely different histories.

View File

@ -14,32 +14,25 @@ export default function InfiniteCanvas() {
const isDarkTheme = useThemeDetector() const isDarkTheme = useThemeDetector()
useEffect(() => { useEffect(() => {
const initPos = getInitialPosition(canvasDimentsion) window.scrollTo({
window.scrollTo(initPos) left: (canvasDimentsion.value.width / 2) - (window.innerWidth / 2),
top: (canvasDimentsion.value.height / 2) - (window.innerHeight / 2)
})
const _updateDimensions = () => { const updateDimensions = () => {
canvasDimentsion.value = { canvasDimentsion.value = {
width: Math.max(canvasDimentsion.value.width, window.innerWidth), width: Math.max(canvasDimentsion.value.width, window.innerWidth),
height: Math.max(canvasDimentsion.value.height, window.innerHeight), height: Math.max(canvasDimentsion.value.height, window.innerHeight),
} }
} }
function _updatePosition() { updateDimensions()
localStorage.setItem("pos", JSON.stringify({ window.addEventListener("resize", updateDimensions)
left: window.scrollX,
top: window.scrollY
}))
}
_updateDimensions()
window.addEventListener("resize", _updateDimensions)
window.addEventListener("scrollend", _updatePosition)
notes.loadLocalStorage() notes.loadLocalStorage()
images.loadLocalStorage() images.loadLocalStorage()
return () => { return () => {
window.removeEventListener("resize", _updateDimensions) window.removeEventListener("resize", updateDimensions)
window.removeEventListener("scrollend", _updatePosition)
} }
}, []) }, [])
@ -79,32 +72,3 @@ export default function InfiniteCanvas() {
</> </>
) )
} }
interface ScrollToOptions extends ScrollOptions {
left?: number;
top?: number;
}
function getInitialPosition(canvasDimensions: typeof canvasDimentsion): ScrollToOptions {
const defaultScroll: ScrollToOptions = {
left: (canvasDimensions.value.width / 2) - (window.innerWidth / 2),
top: (canvasDimensions.value.height / 2) - (window.innerHeight / 2)
}
let initPosition;
try {
initPosition = JSON.parse(localStorage.getItem("pos") ?? "")
} catch (e) {
console.error("no local storage for pos")
}
if (!initPosition) return defaultScroll
return initPosition
}