Skip to content

Commit 0ea9fab

Browse files
committed
feat: clear message on sidebar link click
add icons for sidebar items
1 parent 0364348 commit 0ea9fab

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/components/Header.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
import { useRef } from "react";
22
import { Link } from "react-router";
3-
import { IconBars3 } from ".";
3+
import { IconBars3, IconGlobe } from ".";
4+
import { useStore } from "../store";
45

56
export function Header() {
67
const drawerRef = useRef<HTMLInputElement>(null);
78

9+
const setMessage = useStore((s) => s.setMessage);
10+
811
const closeDrawer = () => {
912
if (drawerRef.current) {
1013
drawerRef.current.checked = false;
1114
}
1215
};
1316

17+
const handleLink = () => {
18+
closeDrawer();
19+
setMessage("info", ""); // clear any messages
20+
};
21+
22+
// SideBar nav item
23+
const NavItem = ({
24+
to,
25+
icon,
26+
label,
27+
}: {
28+
to: string;
29+
icon: JSX.Element;
30+
label: string;
31+
}) => (
32+
<li>
33+
<Link to={to} onClick={handleLink}>
34+
<span className="text-primary">{icon}</span>
35+
{label}
36+
</Link>
37+
</li>
38+
);
39+
1440
// https://v5.daisyui.com/components/drawer/#drawer-that-opens-from-right-side-of-page
1541
const SideBar = () => (
1642
<div className="drawer">
@@ -36,11 +62,7 @@ export function Header() {
3662
className="drawer-overlay"
3763
></label>
3864
<ul className="menu bg-base-200 text-base-content min-h-full w-40 p-4">
39-
<li>
40-
<Link to="/" onClick={closeDrawer}>
41-
Networks
42-
</Link>
43-
</li>
65+
<NavItem to="/" label="Networks" icon={<IconGlobe />} />
4466
</ul>
4567
</div>
4668
</div>

0 commit comments

Comments
 (0)