mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-14 11:49:16 +00:00
Refactor to replace PocketBase with a new data module across components
This commit is contained in:
parent
9b20f49bfe
commit
ec12789b15
@ -12,7 +12,7 @@ import {
|
|||||||
LatestScripts,
|
LatestScripts,
|
||||||
MostViewedScripts,
|
MostViewedScripts,
|
||||||
} from "./_components/ScriptInfoBlocks";
|
} from "./_components/ScriptInfoBlocks";
|
||||||
import { fetchCategories } from "@/lib/pocketbase";
|
import { fetchCategories } from "@/lib/data";
|
||||||
|
|
||||||
function ScriptContent() {
|
function ScriptContent() {
|
||||||
const [selectedScript, setSelectedScript] = useQueryState("id");
|
const [selectedScript, setSelectedScript] = useQueryState("id");
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
CommandItem,
|
CommandItem,
|
||||||
CommandList,
|
CommandList,
|
||||||
} from "@/components/ui/command";
|
} from "@/components/ui/command";
|
||||||
import { fetchCategories } from "@/lib/pocketbase";
|
import { fetchCategories } from "@/lib/data";
|
||||||
import { Category, Script } from "@/lib/types";
|
import { Category, Script } from "@/lib/types";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
@ -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)
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user