From ec12789b151f227fb5b6a15d8c7a0c58ed0c7277 Mon Sep 17 00:00:00 2001 From: Bram Suurd <78373894+BramSuurdje@users.noreply.github.com> Date: Wed, 6 Nov 2024 21:23:10 +0100 Subject: [PATCH] Refactor to replace PocketBase with a new data module across components --- frontend/src/app/scripts/page.tsx | 2 +- frontend/src/components/CommandMenu.tsx | 2 +- frontend/src/lib/pocketbase.ts | 34 ------------------------- 3 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 frontend/src/lib/pocketbase.ts diff --git a/frontend/src/app/scripts/page.tsx b/frontend/src/app/scripts/page.tsx index 5aa8391c..2e82a314 100644 --- a/frontend/src/app/scripts/page.tsx +++ b/frontend/src/app/scripts/page.tsx @@ -12,7 +12,7 @@ import { LatestScripts, MostViewedScripts, } from "./_components/ScriptInfoBlocks"; -import { fetchCategories } from "@/lib/pocketbase"; +import { fetchCategories } from "@/lib/data"; function ScriptContent() { const [selectedScript, setSelectedScript] = useQueryState("id"); diff --git a/frontend/src/components/CommandMenu.tsx b/frontend/src/components/CommandMenu.tsx index a1b8efd2..576197bd 100644 --- a/frontend/src/components/CommandMenu.tsx +++ b/frontend/src/components/CommandMenu.tsx @@ -6,7 +6,7 @@ import { CommandItem, CommandList, } from "@/components/ui/command"; -import { fetchCategories } from "@/lib/pocketbase"; +import { fetchCategories } from "@/lib/data"; import { Category, Script } from "@/lib/types"; import { cn } from "@/lib/utils"; import Image from "next/image"; diff --git a/frontend/src/lib/pocketbase.ts b/frontend/src/lib/pocketbase.ts deleted file mode 100644 index 5f291344..00000000 --- a/frontend/src/lib/pocketbase.ts +++ /dev/null @@ -1,34 +0,0 @@ -import PocketBase from "pocketbase"; -import { Category } from "./types"; - -export const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL); -export const pbBackup = new PocketBase( - process.env.NEXT_PUBLIC_POCKETBASE_URL_BACKUP, -); - -export const getImageURL = (recordId: string, fileName: string) => { - return `${process.env.NEXT_PUBLIC_POCKETBASE_URL}/${recordId}/${fileName}`; -}; - -const sortCategories = (categories: Category[]) => { - const sortedCategories = categories.sort((a, b) => { - if (a.name === "Proxmox VE Tools") { - return -1; - } else if (b.name === "Proxmox VE Tools") { - return 1; - } else if (a.name === "Miscellaneous") { - return 1; - } else if (b.name === "Miscellaneous") { - return -1; - } else { - return a.name.localeCompare(b.name); - } - }); - - return sortedCategories; -}; - -export const fetchCategories = async () => { - const categories = await fetch(`api/categories`).then((response) => response.json()); - return sortCategories(categories) -}