diff --git a/.gitignore b/.gitignore index ddb6132..c29dfdc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ # do not track installed modules -/node_modules +node_modules/ # do not track built files -/.next +.vscode/ +.next/ *.tsbuildinfo next-env.d.ts @@ -13,6 +14,6 @@ yarn-error.log* .pnpm-debug.log* # production -/build -/data -/confs +build/ +data/ +confs/ diff --git a/components/layout.tsx b/components/layout.tsx index 699bf27..6163070 100644 --- a/components/layout.tsx +++ b/components/layout.tsx @@ -26,7 +26,6 @@ const LayoutReadyOrNot = ({ children }: { children: React.ReactNode }) => { -
{children}
diff --git a/components/sidebar.tsx b/components/sidebar.tsx index 113c438..35386ec 100644 --- a/components/sidebar.tsx +++ b/components/sidebar.tsx @@ -4,7 +4,8 @@ import { useRouter } from 'next/router' import useSWR from 'swr'; import ReadyOrNotMap from '../interfaces/ReadyOrNot'; import React, { useState } from 'react'; -import Image from 'next/image' +import Image from 'next/image'; +import useWindowSize from '../components/windowsize'; const fetcher = (url: string) => fetch(url).then((res) => res.json()) @@ -12,37 +13,53 @@ function stopPropagation(e: any) { e.stopPropagation(); } - const Sidebar = () => { + const isMobile = useWindowSize(); const router = useRouter(); - const [active, setActive] = useState(true); - const { maps, isLoading, isError } = useNavbar(); + const [active, setActive] = useState(isMobile); + const { maps, isLoading, isError }:{ maps: ReadyOrNotMap[], isLoading: boolean, isError: boolean} = useNavbar(); - if (isError) { return (
) } + if(typeof(isMobile) === "boolean" && typeof(active) === "undefined") { + setActive(!isMobile); + } + + if (isError) { + return ( + <> +
+
+ + ) + } else if (isLoading) { return ( -
- -
+ <> +
+ +
+
+ ) } else { - // > is a placeholder return ( -
setActive(!active)}> - -
- > + <> +
setActive(!active)}> + +
+ {active" : "<"} /> +
-
+
+ ); } } diff --git a/components/windowsize.tsx b/components/windowsize.tsx new file mode 100644 index 0000000..063fae5 --- /dev/null +++ b/components/windowsize.tsx @@ -0,0 +1,34 @@ +import { useEffect, useState } from "react"; + +interface ScreenSize { + width: number | undefined; + height: number | undefined; +} + +export default function useWindowSize(): boolean | undefined { + const [windowSize, setWindowSize] = useState({ + width: undefined, + height: undefined, + }); + + useEffect(() => { + function handleResize() { + setWindowSize({ + width: window.innerWidth, + height: window.innerHeight, + }); + } + + window.addEventListener("resize", handleResize); + + handleResize(); + + return () => window.removeEventListener("resize", handleResize); + }, []); + if(typeof(windowSize.width) === "number") { + return windowSize.width <= 1080; + } + else { + return undefined; + } +} \ No newline at end of file diff --git a/pages/[map].tsx b/pages/[map].tsx index 5676b61..922df1d 100644 --- a/pages/[map].tsx +++ b/pages/[map].tsx @@ -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") diff --git a/public/sidebar_arrow.webp b/public/sidebar_arrow.webp index a78f750..9c00889 100644 Binary files a/public/sidebar_arrow.webp and b/public/sidebar_arrow.webp differ diff --git a/public/sidebar_arrow_flipped.webp b/public/sidebar_arrow_flipped.webp new file mode 100644 index 0000000..482d5db Binary files /dev/null and b/public/sidebar_arrow_flipped.webp differ diff --git a/resources/sidebar_arrow.svg b/resources/sidebar_arrow.svg index 870d15f..bd01371 100644 --- a/resources/sidebar_arrow.svg +++ b/resources/sidebar_arrow.svg @@ -28,8 +28,8 @@ inkscape:document-units="px" showgrid="true" inkscape:zoom="11.313709" - inkscape:cx="-3.1819805" - inkscape:cy="35.974057" + inkscape:cx="-3.1819804" + inkscape:cy="36.062444" inkscape:window-width="2560" inkscape:window-height="1391" inkscape:window-x="0" @@ -52,7 +52,7 @@ id="layer1"> diff --git a/resources/sidebar_arrow.webp b/resources/sidebar_arrow.webp index a78f750..9c00889 100644 Binary files a/resources/sidebar_arrow.webp and b/resources/sidebar_arrow.webp differ diff --git a/resources/sidebar_arrow_flipped.webp b/resources/sidebar_arrow_flipped.webp new file mode 100644 index 0000000..482d5db Binary files /dev/null and b/resources/sidebar_arrow_flipped.webp differ