|
10 | 10 | import type { Task, Project } from "$lib/types/api"; |
11 | 11 | import { ACTIVE_STATUSES } from "$lib/types/api"; |
12 | 12 | import { getSnapshot, saveSnapshot } from "$lib/stores/task-filters.svelte"; |
| 13 | + import { createLatestRequestGuard, runLatest } from "$lib/latest-request"; |
13 | 14 |
|
14 | 15 | let { params = {} }: { params?: Record<string, string> } = $props(); |
15 | 16 |
|
|
36 | 37 | sort = saved.sort; |
37 | 38 | } |
38 | 39 |
|
| 40 | + const requestGuard = createLatestRequestGuard(); |
| 41 | +
|
39 | 42 | function toggleStatus(s: string) { |
40 | 43 | if (filterStatuses.includes(s)) { |
41 | 44 | filterStatuses = filterStatuses.filter((x) => x !== s); |
|
94 | 97 | filters.priorities = filterPriorities.join(","); |
95 | 98 | if (searchQuery) filters.search = searchQuery; |
96 | 99 |
|
97 | | - Promise.all([ |
98 | | - listProjects(100, 0).then((r) => { |
99 | | - projects = r.items; |
100 | | - }), |
101 | | - getMyTasks({ limit: 50, ...filters }).then((res) => { |
102 | | - const currentUserId = getUser()?.id; |
103 | | - createdTasks = res.items.filter((t) => t.author.id === currentUserId); |
104 | | - assignedTasks = res.items.filter( |
105 | | - (t) => t.assignee?.id === currentUserId, |
106 | | - ); |
107 | | - }), |
108 | | - ]) |
109 | | - .catch((e) => { |
110 | | - error = e.message || "Failed to load tasks"; |
111 | | - }) |
112 | | - .finally(() => { |
113 | | - loading = false; |
114 | | - }); |
| 100 | + runLatest( |
| 101 | + requestGuard, |
| 102 | + () => |
| 103 | + Promise.all([ |
| 104 | + listProjects(100, 0).then((r) => r.items), |
| 105 | + getMyTasks({ limit: 50, ...filters }).then((res) => res.items), |
| 106 | + ]), |
| 107 | + { |
| 108 | + onSuccess: ([projectItems, taskItems]) => { |
| 109 | + projects = projectItems; |
| 110 | + const currentUserId = getUser()?.id; |
| 111 | + createdTasks = taskItems.filter((t) => t.author.id === currentUserId); |
| 112 | + assignedTasks = taskItems.filter( |
| 113 | + (t) => t.assignee?.id === currentUserId, |
| 114 | + ); |
| 115 | + }, |
| 116 | + onError: (e) => { |
| 117 | + error = (e as Error).message || "Failed to load tasks"; |
| 118 | + }, |
| 119 | + onFinally: () => { |
| 120 | + loading = false; |
| 121 | + }, |
| 122 | + }, |
| 123 | + ); |
115 | 124 | }); |
116 | 125 | </script> |
117 | 126 |
|
|
0 commit comments