20 lines
637 B
TypeScript
20 lines
637 B
TypeScript
|
import { createSignal } from "solid-js";
|
||
|
import { CustomLabel } from "../types/CustomLabel";
|
||
|
|
||
|
type CustomLabelsMap = {[k: number]: CustomLabel};
|
||
|
|
||
|
export const [customLabelsMap, setCustomLabelsMap] = createSignal<{[k: number]: CustomLabel}>({});
|
||
|
|
||
|
(() => {
|
||
|
// Get all labels from the API
|
||
|
fetch(`${import.meta.env.VITE_BACKEND_URL}/api/labels`)
|
||
|
.then((res) => res.json())
|
||
|
.then((data: Array<CustomLabel>) => {
|
||
|
const map: CustomLabelsMap = {};
|
||
|
for (const label of data) {
|
||
|
map[label.custom_label_id] = label;
|
||
|
}
|
||
|
setCustomLabelsMap(map);
|
||
|
});
|
||
|
})();
|