Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
feat: use client route instead of href
Browse files Browse the repository at this point in the history
  • Loading branch information
ziteh committed Sep 17, 2024
1 parent 8264a64 commit 3eeac32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
23 changes: 19 additions & 4 deletions app/components/appLayout/topbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SearchIcon from "@mui/icons-material/Search";
import HomeIcon from "@mui/icons-material/Home";
import { Tag, TagRelationChain, SimpleTag } from "@/app/lib/types";
import { useTagTreeState } from "@/app/store/tagTree";
import { useRouter } from "next/navigation";

const Search = styled("div")(({ theme }) => ({
position: "relative",
Expand Down Expand Up @@ -68,9 +69,10 @@ interface Props {

export default function Topbar(props: Props) {
const { isDesktop, onClick } = props;
const { selectedTagId } = useTagTreeState();
const { selectedTagId, updateSelectedTagId } = useTagTreeState();
const [parents, setParents] = useState<SimpleTag[]>([]);
const [tag, setTag] = useState<SimpleTag | null>(null);
const router = useRouter();

useEffect(() => {
updateTag(selectedTagId);
Expand All @@ -91,6 +93,11 @@ export default function Topbar(props: Props) {
setTag(data.self);
};

const onBreadcrumbNav = (id: number) => {
updateSelectedTagId(id);
router.push(`/explorer/${id}`);
};

return (
<Box sx={{ flexGrow: 1 }}>
<AppBar
Expand All @@ -104,21 +111,29 @@ export default function Topbar(props: Props) {
<MenuIcon />
</IconButton>
)}
<Link underline="none" color="inherit" href="/explorer/1">
<Link
underline="none"
color="inherit"
onClick={() => onBreadcrumbNav(1)}
>
Hie
</Link>
</Box>
<Box sx={{ flexGrow: 1 }}>
<Breadcrumbs>
<Link underline="none" color="inherit" href="/explorer">
<Link
underline="none"
color="inherit"
onClick={() => onBreadcrumbNav(1)}
>
<HomeIcon fontSize="small" />
</Link>
{parents.map((p, i) => (
<Link
key={i}
underline="hover"
color="inherit"
href={`/explorer/${p.id}`}
onClick={() => onBreadcrumbNav(p.id)}
>
{p.name}
</Link>
Expand Down
11 changes: 10 additions & 1 deletion app/explorer/[tag]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import { getTag } from "@/app/lib/tags";
import HomeIcon from "@mui/icons-material/Home";
import LocalOfferIcon from "@mui/icons-material/LocalOffer";
import { useTagTreeState } from "@/app/store/tagTree";
import { useRouter } from "next/navigation";

export default function Page({ params }: { params: { tag: string } }) {
const [children, setChildren] = useState<SimpleTag[]>([]);
const { updateSelectedTagId } = useTagTreeState();

const router = useRouter();

useEffect(() => {
updateTag();
}, []);
Expand All @@ -31,13 +34,19 @@ export default function Page({ params }: { params: { tag: string } }) {
setChildren(data.children);
};

const onChildClick = (id: number) => {
updateSelectedTagId(id);
router.push(`/explorer/${id}`);
};

return (
<div>
{children.map((c, i) => (
<Button
key={i}
startIcon={<LocalOfferIcon />}
href={`/explorer/${c.id}`}
// href={`/explorer/${c.id}`}
onClick={() => onChildClick(c.id)}
>
{c.name}
</Button>
Expand Down

0 comments on commit 3eeac32

Please sign in to comment.