Skip to content

Commit 85ea227

Browse files
dudina-macapcom6
authored andcommitted
[frontend] fix missing projects in task form dropdown
1 parent 1e0f6e7 commit 85ea227

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

frontend/src/lib/api/projects.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ export function listProjects(limit = 20, offset = 0, search?: string): Promise<P
77
return apiRequest<PaginatedResponse<Project>>('GET', `/projects?${params}`)
88
}
99

10+
const LIST_ALL_PROJECTS_MAX_PAGES = 100
11+
12+
export async function listAllProjects(search?: string): Promise<Project[]> {
13+
const pageSize = 100
14+
const items: Project[] = []
15+
let offset = 0
16+
let total = Number.POSITIVE_INFINITY
17+
let pagesFetched = 0
18+
19+
while (offset < total && pagesFetched < LIST_ALL_PROJECTS_MAX_PAGES) {
20+
const page = await listProjects(pageSize, offset, search)
21+
items.push(...page.items)
22+
total = page.total
23+
offset += page.items.length
24+
pagesFetched++
25+
if (page.items.length === 0) break
26+
}
27+
28+
return items
29+
}
30+
1031
export function getProject(slug: string): Promise<Project> {
1132
return apiRequest<Project>('GET', `/projects/${encodeURIComponent(slug)}`)
1233
}

frontend/src/lib/pages/task-edit.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import { getTask, updateTask } from "$lib/api/tasks";
3-
import { listProjects } from "$lib/api/projects";
3+
import { listAllProjects } from "$lib/api/projects";
44
import { navigate } from "$lib/router/routes";
55
import TaskForm from "$lib/components/TaskForm.svelte";
66
import type { TaskDetails, Project } from "$lib/types/api";
@@ -16,10 +16,10 @@
1616
1717
onMount(() => {
1818
if (!id) return;
19-
Promise.all([getTask(id), listProjects(100, 0)])
19+
Promise.all([getTask(id), listAllProjects()])
2020
.then(([t, p]) => {
2121
task = t;
22-
projects = p.items;
22+
projects = p;
2323
})
2424
.catch((e) => {
2525
error = e.message || "Failed to load task";

frontend/src/lib/pages/task-new.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { listProjects } from "$lib/api/projects";
2+
import { listAllProjects } from "$lib/api/projects";
33
import { createTask } from "$lib/api/tasks";
44
import { navigate } from "$lib/router/routes";
55
import { touchProject } from "$lib/stores/recent-projects.svelte";
@@ -21,9 +21,9 @@
2121
2222
onMount(() => {
2323
loading = true;
24-
listProjects(100, 0)
25-
.then((r) => {
26-
projects = r.items;
24+
listAllProjects()
25+
.then((items) => {
26+
projects = items;
2727
if (initialProject) {
2828
const match = projects.find((p) => p.id === initialProject);
2929
if (match) initialProjectSlug = match.id;

0 commit comments

Comments
 (0)