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()
useEffect(() => {
const initPos = getInitialPosition(canvasDimentsion)
window.scrollTo(initPos)
window.scrollTo({
left: (canvasDimentsion.value.width / 2) - (window.innerWidth / 2),
top: (canvasDimentsion.value.height / 2) - (window.innerHeight / 2)
})
const _updateDimensions = () => {
const updateDimensions = () => {
canvasDimentsion.value = {
width: Math.max(canvasDimentsion.value.width, window.innerWidth),
height: Math.max(canvasDimentsion.value.height, window.innerHeight),
}
}
function _updatePosition() {
localStorage.setItem("pos", JSON.stringify({
left: window.scrollX,
top: window.scrollY
}))
}
_updateDimensions()
window.addEventListener("resize", _updateDimensions)
window.addEventListener("scrollend", _updatePosition)
updateDimensions()
window.addEventListener("resize", updateDimensions)
notes.loadLocalStorage()
images.loadLocalStorage()
return () => {
window.removeEventListener("resize", _updateDimensions)
window.removeEventListener("scrollend", _updatePosition)
window.removeEventListener("resize", updateDimensions)
}
}, [])
@ -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
}