remove item store

This commit is contained in:
Hayden 2022-11-01 00:09:18 -08:00
parent 68147e4426
commit 04cadd7094
No known key found for this signature in database
GPG key ID: 17CF79474E257545
2 changed files with 0 additions and 47 deletions

View file

@ -9,7 +9,6 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useItemStore } from "~~/stores/items";
import { useLabelStore } from "~~/stores/labels"; import { useLabelStore } from "~~/stores/labels";
import { useLocationStore } from "~~/stores/locations"; 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(); const eventBus = useEventBus();
eventBus.on( eventBus.on(
EventTypes.ClearStores, EventTypes.ClearStores,
() => { () => {
labelStore.refresh(); labelStore.refresh();
itemStore.refresh();
locationStore.refresh(); locationStore.refresh();
}, },
"stores" "stores"
@ -64,7 +51,6 @@
onUnmounted(() => { onUnmounted(() => {
rmLabelStoreObserver(); rmLabelStoreObserver();
rmLocationStoreObserver(); rmLocationStoreObserver();
rmItemStoreObserver();
eventBus.off(EventTypes.ClearStores, "stores"); eventBus.off(EventTypes.ClearStores, "stores");
}); });
</script> </script>

View file

@ -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;
},
},
});