Spools to print are now stored using query parameters

This commit is contained in:
Donkie
2024-08-05 15:41:07 +02:00
parent 9318ef5c19
commit b764e9ecd9
3 changed files with 58 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import { ISpool } from "./model";
import { IFilament } from "../filaments/model";
import { SpoolType, useGetExternalDBFilaments } from "../../utils/queryExternalDB";
import { useMemo } from "react";
import { useQueries } from "@tanstack/react-query";
export async function setSpoolArchived(spool: ISpool, archived: boolean) {
const init: RequestInit = {
@@ -20,6 +21,27 @@ export async function setSpoolArchived(spool: ISpool, archived: boolean) {
await fetch(request, init);
}
/**
* Returns an array of queries using the useQueries hook from @tanstack/react-query.
* Each query fetches a spool by its ID from the server.
*
* @param {number[]} ids - An array of spool IDs to fetch.
* @return An array of query results, each containing the fetched spool data.
*/
export function useGetSpoolsByIds(ids: number[]) {
return useQueries({
queries: ids.map((id) => {
return {
queryKey: ["spool", id],
queryFn: async () => {
const res = await fetch(getAPIURL() + "/spool/" + id);
return (await res.json()) as ISpool;
},
};
}),
});
}
/**
* Formats a filament label with the given parameters.
*/