Loggest thine Stuff
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.

66 lines
1.7 KiB

  1. <script lang="ts" context="module">
  2. const contextKey = {ctx: "projectListCtx"};
  3. interface SprintListContextData {
  4. sprints: Readable<Sprint[]>,
  5. reloadSprintList(): Promise<void>,
  6. };
  7. const fallback: SprintListContextData = {
  8. sprints: readable([]),
  9. reloadSprintList: () => Promise.resolve()
  10. };
  11. export function getSprintListContext() {
  12. return getContext(contextKey) as SprintListContextData || fallback
  13. }
  14. </script>
  15. <script lang="ts">
  16. import { readable, writable, type Readable } from "svelte/store";
  17. import { getContext, setContext } from "svelte";
  18. import { sl3 } from "$lib/clients/sl3";
  19. import { getScopeContext } from "./ScopeContext.svelte";
  20. import type Sprint from "$lib/models/sprint";
  21. import parseInterval from "$lib/utils/timeinterval";
  22. import { getTimeContext } from "./TimeContext.svelte";
  23. import { getStores } from "$app/stores";
  24. export let sprints: Sprint[];
  25. export let intervalString: string;
  26. export let global: boolean = false;
  27. const {scope} = getScopeContext();
  28. const {now} = getTimeContext();
  29. const {page} = getStores();
  30. let sprintsWritable = writable<Sprint[]>(sprints);
  31. let loading = false;
  32. let lastSet = sprints;
  33. setContext<SprintListContextData>(contextKey, {
  34. sprints: {subscribe: sprintsWritable.subscribe},
  35. reloadSprintList,
  36. });
  37. async function reloadSprintList() {
  38. if (loading) {
  39. return
  40. }
  41. try {
  42. const newSprints = await sl3(fetch, $page.stuff.idToken).listSprints(global ? "ALL" : $scope.id, parseInterval(intervalString, $now));
  43. sprintsWritable.set(newSprints);
  44. } catch(_) {}
  45. loading = false;
  46. }
  47. $: {
  48. if (lastSet !== sprints) {
  49. sprintsWritable.set(sprints);
  50. lastSet = sprints;
  51. }
  52. }
  53. </script>
  54. <slot></slot>