This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { NextResponse } from "next/server"; | ||
import { prisma } from "@/app/lib/config/prisma"; | ||
import { StatusCodes } from "http-status-codes"; | ||
|
||
export async function GET(_request: Request) { | ||
try { | ||
// Get all root tags (with no parent) | ||
const tags = await prisma.tag.findMany({ | ||
where: { parent: null }, | ||
}); | ||
|
||
return NextResponse.json(tags); | ||
} catch (error) { | ||
console.error("Error fetching root tags:", error); | ||
return NextResponse.json( | ||
{ error: "Error fetching root tags" }, | ||
{ status: StatusCodes.INTERNAL_SERVER_ERROR } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import { useState, useEffect } from "react"; | ||
import { Breadcrumbs, Button, Link, Typography } from "@mui/material"; | ||
import { Tag, TagRelationChain, SimpleTag } from "@/app/lib/types"; | ||
import LocalOfferIcon from "@mui/icons-material/LocalOffer"; | ||
import { useTagTreeState } from "@/app/store/tagTree"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
export default function Page() { | ||
const [rootTags, setRootTags] = useState<Tag[]>([]); | ||
const { updateSelectedTagId } = useTagTreeState(); | ||
|
||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
updateTag(); | ||
}, []); | ||
|
||
const updateTag = async () => { | ||
const response = await fetch(`/api/tags/root`, { | ||
method: "GET", | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
|
||
if (!response.ok) { | ||
return; | ||
} | ||
|
||
const data: Tag[] = await response.json(); | ||
setRootTags(data); | ||
}; | ||
|
||
const onChildClick = (id: number) => { | ||
updateSelectedTagId(id); | ||
router.push(`/explorer/${id}`); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{rootTags.map((c, i) => ( | ||
<Button | ||
key={i} | ||
startIcon={<LocalOfferIcon />} | ||
onClick={() => onChildClick(c.id)} | ||
> | ||
{c.name} | ||
</Button> | ||
))} | ||
</div> | ||
); | ||
} |