parent
fbc815e776
commit
758cb6a9f0
1 changed files with 36 additions and 22 deletions
|
@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue