Various changes

Removed debug logging, implemented Issue #7
This commit is contained in:
Neshura 2022-12-09 18:29:47 +01:00
parent fbc815e776
commit 758cb6a9f0
No known key found for this signature in database
GPG key ID: ACDF5B6EBECF6B0A

View file

@ -15,28 +15,40 @@ function stopPropagation(e: any) {
const Sidebar = () => {
const isMobile = useWindowSize();
console.log(isMobile); // DEBUG
const router = useRouter();
const [active, setActive] = useState(!isMobile);
const { maps, isLoading, isError } = useNavbar();
const [active, setActive] = useState(isMobile);
const { maps, isLoading, isError }:{ maps: ReadyOrNotMap[], isLoading: boolean, isError: boolean} = useNavbar();
if(typeof(isMobile) === "boolean" && typeof(active) === "undefined") {
setActive(!isMobile);
}
if (isError) { return (<div><nav><a>Error loading Sidemenu</a></nav></div>) }
if (isError) {
return (
<>
<div><nav><a>Error loading Sidemenu</a></nav></div>
<div className={styles.sidebarPlaceholder}></div>
</>
)
}
else if (isLoading) {
return (
<>
<div>
<nav>
<a>Loading...</a>
</nav>
</div>
<div className={styles.sidebarPlaceholder}></div>
</>
)
}
else {
// > is a placeholder
return (
<>
<div className={styles.sidebar} onClick={() => setActive(!active)}>
<nav className={[styles.sidebarList, (active ? styles.sl_active : styles.sl_inactive)].join(" ")}>
{maps.map((item: ReadyOrNotMap) => (
{maps.map((item) => (
<Link key={item.name} href={item.href}>
<a className={[styles.navElem, (router.query.map == item.href ? styles.ne_active : styles.ne_inactive)].join(" ")} onClick={stopPropagation}>{item.name}</a>
</Link>
@ -46,6 +58,8 @@ const Sidebar = () => {
<Image src={active ? "/sidebar_arrow_flipped.webp" : "/sidebar_arrow.webp"} width={32} height={96} alt={active ? ">" : "<"} />
</div>
</div>
<div className={styles.sidebarPlaceholder}></div>
</>
);
}
}