Extract windowsize function from map script

This commit is contained in:
Neshura 2022-12-04 16:42:49 +01:00
parent 6fa3d727b0
commit 8177802bb3
No known key found for this signature in database
GPG key ID: ACDF5B6EBECF6B0A
3 changed files with 33 additions and 28 deletions

View file

@ -6,34 +6,12 @@ import { NextPageWithLayout } from './_app';
import React from 'react';
import useSWR, { KeyedMutator, mutate } from 'swr';
import { useRouter } from 'next/router';
import Image from 'next/image'
import Image from 'next/image';
import ReadyOrNotMap from '../interfaces/ReadyOrNot';
import useWindowSize from '../components/windowsize';
const fetcher = (url: string) => fetch(url).then((res) => res.json())
function useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: 0,
height: 0,
});
useEffect(() => {
function handleResize() {
setWindowSize({
width: window.innerWidth,
height: window.innerHeight,
});
}
window.addEventListener("resize", handleResize);
handleResize();
return () => window.removeEventListener("resize", handleResize);
}, []);
return windowSize.width <= 1080;
}
const ReadyOrNotMaps: NextPageWithLayout = () => {
const [floor, setFloor] = useState(0);
const { mapInfo, isLoadingInfo, isErrorInfo } = useMap(useRouter().query.map?.toString() || "a_lethal_obsession")