upend/webui/src/util/labels.ts

29 lines
771 B
TypeScript

import { readable, type Readable } from "svelte/store";
import { fetchAllAttributes } from "../lib/api";
const DEFAULT_ATTRIBUTE_LABELS = {
FILE_MIME: "MIME type",
FILE_MTIME: "Last modified",
FILE_SIZE: "File size",
ADDED: "Added at",
LAST_VISITED: "Last visited at",
NUM_VISITED: "Times visited",
LBL: "Label",
IS: "Type",
};
export const attributeLabels: Readable<{ [key: string]: string }> = readable(
DEFAULT_ATTRIBUTE_LABELS,
(set) => {
const result = Object.assign(DEFAULT_ATTRIBUTE_LABELS);
fetchAllAttributes().then((attributes) => {
attributes.forEach((attribute) => {
if (attribute.labels.length) {
result[attribute.name] = attribute.labels.sort()[0];
}
});
set(result);
});
}
);