-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMuseumSwitch.jsx
75 lines (63 loc) · 1.67 KB
/
MuseumSwitch.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from "react";
import { useRouter } from "next/router";
import { useAppContext } from "../hooks/appContext";
import Bugs from "./icons/Bugs";
import Fishes from "./icons/Fishes";
import Fossils from "./icons/Fossils";
import styles from "../styles/components/MuseumSwitch.module.css";
function MuseumSwitch({ language, active }) {
const { menuItems, setMenuItems } = useAppContext();
const router = useRouter();
const switchItems = [
{
label: language.bugs,
icon: <Bugs />,
type: "bugs",
path: "/museum/bugs",
},
{
label: language.fishes,
icon: <Fishes />,
type: "fishes",
path: "/museum/fishes",
},
{
label: language.fossils,
icon: <Fossils />,
type: "fossils",
path: "/museum/fossils",
},
];
function saveMuseumPosition(e, href) {
e.preventDefault();
router.push(href);
const state = [...menuItems];
state.map((item) => {
if (item.rootPath === "museum") {
item.path = href;
}
});
setMenuItems(state);
}
return (
<div className={styles.museumSwitch}>
{switchItems.map((switchItem) => {
const classes = [styles.museumSwitchButton];
if (active === switchItem.type)
classes.push(styles.museumSwitchButtonActive);
return (
<a
key={`museum-switch-${switchItem.type}`}
href={switchItem.path}
className={classes.join(" ")}
onClick={(e) => saveMuseumPosition(e, switchItem.path)}
>
{switchItem.icon}
{switchItem.label}
</a>
);
})}
</div>
);
}
export default MuseumSwitch;