mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-16 13:48:44 +00:00
343290a55a
* cleanup unnecessary mocks * refactor document storage location * remove unused function * move ownership to document types to repo package * move types and mappers to repo package * refactor sets to own package
33 lines
923 B
TypeScript
33 lines
923 B
TypeScript
import { defineStore } from "pinia";
|
|
import { LocationOutCount } from "~~/lib/api/types/data-contracts";
|
|
|
|
export const useLocationStore = defineStore("locations", {
|
|
state: () => ({
|
|
allLocations: null as LocationOutCount[] | null,
|
|
client: useUserApi(),
|
|
}),
|
|
getters: {
|
|
/**
|
|
* locations represents the locations that are currently in the store. The store is
|
|
* synched with the server by intercepting the API calls and updating on the
|
|
* response
|
|
*/
|
|
locations(state): LocationOutCount[] {
|
|
if (state.allLocations === null) {
|
|
Promise.resolve(this.refresh());
|
|
}
|
|
return state.allLocations;
|
|
},
|
|
},
|
|
actions: {
|
|
async refresh(): Promise<LocationOutCount[]> {
|
|
const result = await this.client.locations.getAll();
|
|
if (result.error) {
|
|
return result;
|
|
}
|
|
|
|
this.allLocations = result.data.items;
|
|
return result;
|
|
},
|
|
},
|
|
});
|