Update src/lib/data.ts with necessary changes.

Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com>
This commit is contained in:
Bram Suurd 2024-11-06 21:53:23 +01:00
parent ada264ecb8
commit e5c7df88a6

View File

@ -1,7 +1,7 @@
import { Category } from "./types";
const sortCategories = (categories: Category[]) => {
const sortedCategories = categories.sort((a, b) => {
return categories.sort((a, b) => {
if (a.name === "Proxmox VE Tools") {
return -1;
} else if (b.name === "Proxmox VE Tools") {
@ -14,13 +14,10 @@ const sortCategories = (categories: Category[]) => {
return a.name.localeCompare(b.name);
}
});
return sortedCategories;
};
export const fetchCategories = async () => {
const categories = await fetch(`api/categories`).then((response) =>
response.json(),
);
export const fetchCategories = async (): Promise<Category[]> => {
const response = await fetch("api/categories");
const categories = await response.json();
return sortCategories(categories);
};