You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
743 B

4 years ago
  1. import { writable } from "svelte/store";
  2. import stuffLogClient from "../clients/stufflog";
  3. import type { GroupResult } from "../models/group";
  4. interface GroupStoreData {
  5. loading: boolean
  6. stale: boolean
  7. groups: GroupResult[]
  8. }
  9. function createGroupStore() {
  10. const {update, subscribe} = writable<GroupStoreData>({
  11. loading: false,
  12. stale: true,
  13. groups: [],
  14. });
  15. return {
  16. subscribe,
  17. markStale() {
  18. update(v => ({...v, stale: true}));
  19. },
  20. async load() {
  21. update(v => ({...v, loading: true}));
  22. const groups = await stuffLogClient.listGroups();
  23. update(v => ({...v, loading: false, stale: false, groups}));
  24. },
  25. }
  26. }
  27. const groupStore = createGroupStore();
  28. export default groupStore;