forked from mirrors/homebox
feat: allow nested relationships for locations and items (#102)
Basic implementation that allows organizing Locations and Items within each other.
This commit is contained in:
parent
fe6cd431a6
commit
a4b4fe3454
37 changed files with 2329 additions and 126 deletions
36
frontend/composables/use-item-search.ts
Normal file
36
frontend/composables/use-item-search.ts
Normal file
|
@ -0,0 +1,36 @@
|
|||
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[]>([]);
|
||||
|
||||
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 });
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
results.value = data.items;
|
||||
}
|
||||
|
||||
if (opts?.immediate) {
|
||||
search();
|
||||
}
|
||||
|
||||
return {
|
||||
query,
|
||||
results,
|
||||
locations,
|
||||
labels,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue