From 92f682be4ebcad12f0ab052ea37ad4bc041ef108 Mon Sep 17 00:00:00 2001 From: Bram Suurd <78373894+BramSuurdje@users.noreply.github.com> Date: Fri, 10 May 2024 18:44:28 +0200 Subject: [PATCH] Update UI and fix layout issues in page.tsx, LatestScripts.tsx, and Script.tsx components --- app/scripts/page.tsx | 6 +-- components/LatestScripts.tsx | 2 +- components/Navbar.tsx | 86 ++++++++++++++++++------------------ 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/app/scripts/page.tsx b/app/scripts/page.tsx index f5dd26b..5d90886 100644 --- a/app/scripts/page.tsx +++ b/app/scripts/page.tsx @@ -8,14 +8,14 @@ export default function Page() { return ( <> -
+
-
+
diff --git a/components/LatestScripts.tsx b/components/LatestScripts.tsx index 032b1a4..d7f0bc8 100644 --- a/components/LatestScripts.tsx +++ b/components/LatestScripts.tsx @@ -36,7 +36,7 @@ function LatestScripts() { {latestScripts.map((item) => ( diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 5ec9ebf..53d2471 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -28,9 +28,13 @@ import { } from "@/components/ui/accordion"; import { Input } from "@/components/ui/input"; import { Category } from "@/lib/types"; +import { pb } from "@/lib/pocketbase"; function Navbar() { const [isScrolled, setIsScrolled] = useState(false); + const [links, setLinks] = useState([]); + const [searchTerm, setSearchTerm] = useState(""); + const inputRef = useRef(null); useEffect(() => { const handleScroll = () => { @@ -44,10 +48,6 @@ function Navbar() { }; }, []); - const [links, setLinks] = useState([]); - const [searchTerm, setSearchTerm] = useState(""); - const inputRef = useRef(null); - useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "/") { @@ -62,33 +62,33 @@ function Navbar() { }; }, []); - const fetchLinks = async () => { - try { - const res = await fetch( - `${process.env.NEXT_PUBLIC_POCKETBASE_URL}/api/collections/proxmox_items/records`, - ); - const data = await res.json(); - setLinks(data.items as Category[]); - } catch (error) { - console.error("Error fetching links:", error); - } - }; + const fetchLinks = async () => { + try { + // you can also fetch all records at once via getFullList + const res = await pb.collection("categories").getFullList({ + expand: "items", + }); + setLinks(res as unknown as Category[]); + } catch (error) { + console.error("Error fetching links:", error); + } + }; - useEffect(() => { - fetchLinks(); - }, []); + useEffect(() => { + fetchLinks(); + }, []); - const handleSearch = (value: string) => { - setSearchTerm(value); - }; + const handleSearch = (value: string) => { + setSearchTerm(value); + }; - const filteredLinks = useMemo(() => { - return links.filter((category) => - category.Items.some((script) => - script.title.toLowerCase().includes(searchTerm.toLowerCase()), - ), - ); - }, [links, searchTerm]); + const filteredLinks = useMemo(() => { + return links.filter((category) => + category.expand.items.some((script) => + script.title.toLowerCase().includes(searchTerm.toLowerCase()), + ), + ); + }, [links, searchTerm]); return ( <> @@ -129,33 +129,33 @@ function Navbar() { > {filteredLinks.map((category) => ( - {category.Catagory_Title} + {category.catagoryName} - {category.Items.filter((script) => - script.title - .toLowerCase() - .includes(searchTerm.toLowerCase()), - ).map((script, index) => ( -
- + {category.expand.items + .filter((script) => + script.title + .toLowerCase() + .includes(searchTerm.toLowerCase()), + ) + .map((script, index) => ( +

- {script.title} + {script.title} {script.item_type} - -

- ))} +

+ ))}
))}