mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 00:30:27 +00:00
remove item store
This commit is contained in:
parent
68147e4426
commit
04cadd7094
2 changed files with 0 additions and 47 deletions
|
@ -9,7 +9,6 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useItemStore } from "~~/stores/items";
|
||||
import { useLabelStore } from "~~/stores/labels";
|
||||
import { useLocationStore } from "~~/stores/locations";
|
||||
|
||||
|
@ -39,23 +38,11 @@
|
|||
},
|
||||
});
|
||||
|
||||
const itemStore = useItemStore();
|
||||
const reItem = /\/api\/v1\/items\/.*/gm;
|
||||
const rmItemStoreObserver = defineObserver("itemStore", {
|
||||
handler: r => {
|
||||
if (r.status === 201 || r.url.match(reItem)) {
|
||||
itemStore.refresh();
|
||||
}
|
||||
console.debug("itemStore handler called by observer");
|
||||
},
|
||||
});
|
||||
|
||||
const eventBus = useEventBus();
|
||||
eventBus.on(
|
||||
EventTypes.ClearStores,
|
||||
() => {
|
||||
labelStore.refresh();
|
||||
itemStore.refresh();
|
||||
locationStore.refresh();
|
||||
},
|
||||
"stores"
|
||||
|
@ -64,7 +51,6 @@
|
|||
onUnmounted(() => {
|
||||
rmLabelStoreObserver();
|
||||
rmLocationStoreObserver();
|
||||
rmItemStoreObserver();
|
||||
eventBus.off(EventTypes.ClearStores, "stores");
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { ItemOut } from "~~/lib/api/types/data-contracts";
|
||||
|
||||
export const useItemStore = defineStore("items", {
|
||||
state: () => ({
|
||||
allItems: null as ItemOut[] | null,
|
||||
client: useUserApi(),
|
||||
}),
|
||||
getters: {
|
||||
/**
|
||||
* items represents the items that are currently in the store. The store is
|
||||
* synched with the server by intercepting the API calls and updating on the
|
||||
* response.
|
||||
*/
|
||||
items(state): ItemOut[] {
|
||||
if (state.allItems === null) {
|
||||
Promise.resolve(this.refresh());
|
||||
}
|
||||
return state.allItems;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
async refresh(): Promise<ItemOut[]> {
|
||||
const result = await this.client.items.getAll();
|
||||
if (result.error) {
|
||||
return result;
|
||||
}
|
||||
|
||||
this.allItems = result.data.items;
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue