mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-02-12 02:39:17 +00:00
Add category sorting and fetching logic in data.ts
This commit is contained in:
parent
d9a6b8bdd3
commit
70ae6ae8d1
26
frontend/src/lib/data.ts
Normal file
26
frontend/src/lib/data.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Category } from "./types";
|
||||||
|
|
||||||
|
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