Refactor to replace PocketBase with a new data module across components

This commit is contained in:
Bram Suurd 2024-11-06 21:23:10 +01:00
parent 9b20f49bfe
commit ec12789b15
3 changed files with 2 additions and 36 deletions

View File

@ -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");

View File

@ -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";

View File

@ -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)
}