mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 13:06:32 +00:00
a886fa86ca
Add archive option feature. Archived items can only be seen on the items page when including archived is selected. Archived items are excluded from the count and from other views
42 lines
1 KiB
TypeScript
42 lines
1 KiB
TypeScript
import { ItemSummary, LabelSummary, LocationSummary } from "~~/lib/api/types/data-contracts";
|
|
import { UserClient } from "~~/lib/api/user";
|
|
|
|
type SearchOptions = {
|
|
immediate?: boolean;
|
|
};
|
|
|
|
export function useItemSearch(client: UserClient, opts?: SearchOptions) {
|
|
const query = ref("");
|
|
const locations = ref<LocationSummary[]>([]);
|
|
const labels = ref<LabelSummary[]>([]);
|
|
const results = ref<ItemSummary[]>([]);
|
|
const includeArchived = ref(false);
|
|
|
|
watchDebounced(query, search, { debounce: 250, maxWait: 1000 });
|
|
async function search() {
|
|
const locIds = locations.value.map(l => l.id);
|
|
const labelIds = labels.value.map(l => l.id);
|
|
|
|
const { data, error } = await client.items.getAll({
|
|
q: query.value,
|
|
locations: locIds,
|
|
labels: labelIds,
|
|
includeArchived: includeArchived.value,
|
|
});
|
|
if (error) {
|
|
return;
|
|
}
|
|
results.value = data.items;
|
|
}
|
|
|
|
if (opts?.immediate) {
|
|
search();
|
|
}
|
|
|
|
return {
|
|
query,
|
|
results,
|
|
locations,
|
|
labels,
|
|
};
|
|
}
|