|
9 | 9 | import * as Card from "$lib/components/ui/card"; |
10 | 10 | import type { Task, Project } from "$lib/types/api"; |
11 | 11 | import { ACTIVE_STATUSES } from "$lib/types/api"; |
| 12 | + import { createLatestRequestGuard, runLatest } from "$lib/latest-request"; |
12 | 13 |
|
13 | 14 | let { params = {} }: { params?: Record<string, string> } = $props(); |
14 | 15 |
|
|
25 | 26 | let searchQuery = $state(""); |
26 | 27 | let sort = $state("-created_at"); |
27 | 28 |
|
| 29 | + const requestGuard = createLatestRequestGuard(); |
| 30 | +
|
28 | 31 | function toggleStatus(s: string) { |
29 | 32 | if (filterStatuses.includes(s)) { |
30 | 33 | filterStatuses = filterStatuses.filter((x) => x !== s); |
|
73 | 76 | filters.priorities = filterPriorities.join(","); |
74 | 77 | if (searchQuery) filters.search = searchQuery; |
75 | 78 |
|
76 | | - Promise.all([ |
77 | | - listProjects(100, 0).then((r) => { |
78 | | - projects = r.items; |
79 | | - }), |
80 | | - getMyTasks({ limit: 50, ...filters }).then((res) => { |
81 | | - const currentUserId = getUser()?.id; |
82 | | - createdTasks = res.items.filter((t) => t.author.id === currentUserId); |
83 | | - assignedTasks = res.items.filter( |
84 | | - (t) => t.assignee?.id === currentUserId, |
85 | | - ); |
86 | | - }), |
87 | | - ]) |
88 | | - .catch((e) => { |
89 | | - error = e.message || "Failed to load tasks"; |
90 | | - }) |
91 | | - .finally(() => { |
92 | | - loading = false; |
93 | | - }); |
| 79 | + runLatest( |
| 80 | + requestGuard, |
| 81 | + () => |
| 82 | + Promise.all([ |
| 83 | + listProjects(100, 0).then((r) => r.items), |
| 84 | + getMyTasks({ limit: 50, ...filters }).then((res) => res.items), |
| 85 | + ]), |
| 86 | + { |
| 87 | + onSuccess: ([projectItems, taskItems]) => { |
| 88 | + projects = projectItems; |
| 89 | + const currentUserId = getUser()?.id; |
| 90 | + createdTasks = taskItems.filter((t) => t.author.id === currentUserId); |
| 91 | + assignedTasks = taskItems.filter( |
| 92 | + (t) => t.assignee?.id === currentUserId, |
| 93 | + ); |
| 94 | + }, |
| 95 | + onError: (e) => { |
| 96 | + error = (e as Error).message || "Failed to load tasks"; |
| 97 | + }, |
| 98 | + onFinally: () => { |
| 99 | + loading = false; |
| 100 | + }, |
| 101 | + }, |
| 102 | + ); |
94 | 103 | }); |
95 | 104 | </script> |
96 | 105 |
|
|
0 commit comments