-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
127 lines (117 loc) · 3.75 KB
/
Copy pathindex.js
File metadata and controls
127 lines (117 loc) · 3.75 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React, { useEffect, useState } from 'react';
import { useThemeConfig, ErrorCauseBoundary } from '@docusaurus/theme-common';
import {
splitNavbarItems,
useNavbarMobileSidebar,
} from '@docusaurus/theme-common/internal';
import NavbarItem from '@theme/NavbarItem';
import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle';
import SearchBar from '@theme/SearchBar';
import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle';
import NavbarLogo from '@theme/Navbar/Logo';
import NavbarSearch from '@theme/Navbar/Search';
import styles from './styles.module.css';
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@site/src/components/ui/select";
import { useBoardStore } from "@site/src/lib/stores/store";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faMicrochip } from "@fortawesome/free-solid-svg-icons";
import { useNavigate, useLocation } from 'react-router-dom'; // Verwende useLocation
function useNavbarItems() {
return useThemeConfig().navbar.items;
}
function NavbarItems({ items }) {
return (
<>
{items.map((item, i) => (
<ErrorCauseBoundary
key={i}
onError={(error) =>
new Error(
`A theme navbar item failed to render.
Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:
${JSON.stringify(item, null, 2)}`,
{ cause: error },
)
}
>
<NavbarItem {...item} />
</ErrorCauseBoundary>
))}
</>
);
}
function NavbarContentLayout({ left, right }) {
return (
<div className="navbar__inner">
<div className="navbar__items">{left}</div>
<div className="navbar__items navbar__items--right">{right}</div>
</div>
);
}
const BoardDropdown = () => {
const board = useBoardStore((state) => state.board);
const location = useLocation();
const handleBoardChange = (selectedBoard) => {
// Verwende die setBoard-Funktion direkt, um das Board im Store zu aktualisieren
console.log(selectedBoard)
useBoardStore.setState({ board: selectedBoard });
// Hier kannst du weitere Aktionen ausführen, wenn sich das Board ändert
};
useEffect(() => {
const searchParams = new URLSearchParams(location.search);
const currentBoard = searchParams.get('board');
// Map der Suchbegriffe zu den entsprechenden Board-Werten
const boardMap = {
home: ":home",
edus2: ":edu S2",
edu: ":edu",
bike: ":bike",
co2: ":CO2 Ampel",
mini: ":mini",
basic: "basic",
};
// Überprüfen, ob der Suchbegriff gültig ist, und Board setzen
if (currentBoard && boardMap[currentBoard.toLowerCase()]) {
useBoardStore.setState({ board: boardMap[currentBoard.toLowerCase()] });
} else {
console.warn("Ungültiger Board-Parameter:", currentBoard);
}
}, [location.search]); // Überwache Änderungen an den Query-Parametern
return (<></>
);
};
export default function NavbarContent() {
const mobileSidebar = useNavbarMobileSidebar();
const items = useNavbarItems();
const [leftItems, rightItems] = splitNavbarItems(items);
const searchBarItem = items.find((item) => item.type === 'search');
return (
<NavbarContentLayout
left={
<>
{!mobileSidebar.disabled && <NavbarMobileSidebarToggle />}
<NavbarLogo />
<NavbarItems items={leftItems} />
</>
}
right={
<>
<BoardDropdown />
<NavbarItems items={rightItems} />
<NavbarColorModeToggle className={styles.colorModeToggle} />
{!searchBarItem && (
<NavbarSearch>
<SearchBar />
</NavbarSearch>
)}
</>
}
/>
);
}