Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions frontend/src/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ export function listProjects(limit = 20, offset = 0, search?: string): Promise<P
return apiRequest<PaginatedResponse<Project>>('GET', `/projects?${params}`)
}

const LIST_ALL_PROJECTS_MAX_PAGES = 100

export async function listAllProjects(search?: string): Promise<Project[]> {
const pageSize = 100
const items: Project[] = []
let offset = 0
let total = Number.POSITIVE_INFINITY
let pagesFetched = 0

while (offset < total && pagesFetched < LIST_ALL_PROJECTS_MAX_PAGES) {
const page = await listProjects(pageSize, offset, search)
items.push(...page.items)
total = page.total
offset += page.items.length
pagesFetched++
if (page.items.length === 0) break
}

return items
}

export function getProject(slug: string): Promise<Project> {
return apiRequest<Project>('GET', `/projects/${encodeURIComponent(slug)}`)
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/lib/pages/task-edit.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { getTask, updateTask } from "$lib/api/tasks";
import { listProjects } from "$lib/api/projects";
import { listAllProjects } from "$lib/api/projects";
import { navigate } from "$lib/router/routes";
import TaskForm from "$lib/components/TaskForm.svelte";
import type { TaskDetails, Project } from "$lib/types/api";
Expand All @@ -16,10 +16,10 @@

onMount(() => {
if (!id) return;
Promise.all([getTask(id), listProjects(100, 0)])
Promise.all([getTask(id), listAllProjects()])
.then(([t, p]) => {
task = t;
projects = p.items;
projects = p;
})
.catch((e) => {
error = e.message || "Failed to load task";
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/lib/pages/task-new.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { listProjects } from "$lib/api/projects";
import { listAllProjects } from "$lib/api/projects";
import { createTask } from "$lib/api/tasks";
import { navigate } from "$lib/router/routes";
import { touchProject } from "$lib/stores/recent-projects.svelte";
Expand All @@ -21,9 +21,9 @@

onMount(() => {
loading = true;
listProjects(100, 0)
.then((r) => {
projects = r.items;
listAllProjects()
.then((items) => {
projects = items;
if (initialProject) {
const match = projects.find((p) => p.id === initialProject);
if (match) initialProjectSlug = match.id;
Expand Down
Loading