Skip to content

Commit

Permalink
Get full list of pinned projects
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Dec 3, 2024
1 parent 77cf79d commit 4fa8a7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ export async function getShared(
return projects.filter((project) => project.user !== userId);
}

/**
* Get all pinned projects for a user
*/
export async function getPinnedProjects(fetch = globalThis.fetch) {
const endpoint = new URL("projects/", BASE_API_URL);
endpoint.searchParams.set("pinned", "true");
return getAll<Project>(endpoint, undefined, fetch);
}

/**
* Set the pinned status of a project.
* When requesting PATCH on the project endpoint,
Expand Down
12 changes: 5 additions & 7 deletions src/routes/(app)/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
import { getMe, orgUsers, userOrgs } from "$lib/api/accounts";
import { getTipOfDay } from "$lib/api/flatpages";
import { getPinnedAddons } from "$lib/api/addons";
import { list as listProjects } from "$lib/api/projects";
import { getPinnedProjects } from "$lib/api/projects";

export const trailingSlash = "always";

Expand Down Expand Up @@ -42,12 +42,10 @@ export async function load({ fetch }) {
console.error(e);
return null;
});
pinnedProjects = listProjects({ pinned: true }, fetch)
.then((r) => r.data?.results ?? [])
.catch((e) => {
console.error(e);
return [];
});
pinnedProjects = getPinnedProjects(fetch).catch((e) => {
console.error(e);
return [];
});
}

return {
Expand Down

0 comments on commit 4fa8a7f

Please sign in to comment.