eeg_certs/frontend/src/utils/allCustomLabels.ts

22 lines
647 B
TypeScript
Raw Normal View History

2023-09-02 03:50:24 +00:00
import { createSignal } from "solid-js";
import { CustomLabel } from "../types/CustomLabel";
type CustomLabelsMap = {[k: number]: CustomLabel};
export const [customLabelsMap, setCustomLabelsMap] = createSignal<{[k: number]: CustomLabel}>({});
2023-09-03 00:42:57 +00:00
export function loadCustomLabels() {
fetch(`${import.meta.env.VITE_BACKEND_URL}/api/label`)
2023-09-02 03:50:24 +00:00
.then((res) => res.json())
.then((data: Array<CustomLabel>) => {
const map: CustomLabelsMap = {};
for (const label of data) {
map[label.custom_label_id] = label;
}
setCustomLabelsMap(map);
});
2023-09-03 00:42:57 +00:00
}
loadCustomLabels();