Added reading and using of spool orders in locations

This commit is contained in:
Donkie
2024-11-20 21:57:01 +01:00
parent ce42d687ed
commit bf06408368
5 changed files with 85 additions and 26 deletions

View File

@@ -19,21 +19,6 @@ export async function setSpoolLocation(spool_id: number, location: string | null
return response.json();
}
export function useLocations(): string[] {
const query = useGetSetting("locations");
return useMemo(() => {
if (!query.data) return [];
try {
return JSON.parse(query.data.value) as string[];
} catch {
console.warn("Failed to parse locations", query.data.value);
return [];
}
}, [query.data]);
}
export async function renameSpoolLocation(location: string, newName: string): Promise<string> {
const response = await fetch(getAPIURL() + "/location/" + location, {
method: "PATCH",
@@ -49,3 +34,33 @@ export async function renameSpoolLocation(location: string, newName: string): Pr
}
return await response.text();
}
export function useLocations(): string[] {
const query = useGetSetting("locations");
return useMemo(() => {
if (!query.data) return [];
try {
return JSON.parse(query.data.value) as string[];
} catch {
console.warn("Failed to parse locations", query.data.value);
return [];
}
}, [query.data]);
}
export function useLocationsSpoolOrders(): Record<string, number[]> {
const query = useGetSetting("locations_spoolorders");
return useMemo(() => {
if (!query.data) return {};
try {
return JSON.parse(query.data.value) as Record<string, number[]>;
} catch {
console.warn("Failed to parse locations spool orders", query.data.value);
return {};
}
}, [query.data]);
}