Skip to content

Commit

Permalink
Support query param on project list
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Apr 24, 2024
1 parent 44ca521 commit c7bc5bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,27 @@ export async function list(
/**
* Get a list of all projects owned by the user
*/
export async function getOwned(userId: number): Promise<Project[]> {
export async function getOwned(
userId: number,
query?: string,
): Promise<Project[]> {
const endpoint = new URL("projects/", BASE_API_URL);
endpoint.searchParams.set("user", String(userId));
endpoint.searchParams.set("query", query);
const projects = await getAll<Project>(endpoint);
return projects.filter((project) => project.user === userId);
}

/**
* Get a list of all projects shared with the user
*/
export async function getShared(userId: number): Promise<Project[]> {
export async function getShared(
userId: number,
query?: string,
): Promise<Project[]> {
const endpoint = new URL("projects/", BASE_API_URL);
endpoint.searchParams.set("user", String(userId));
endpoint.searchParams.set("query", query);
const projects = await getAll<Project>(endpoint);
return projects.filter((project) => project.user !== userId);
}
Expand Down
5 changes: 3 additions & 2 deletions src/routes/app/projects/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ export async function load({ url, parent, fetch }) {
const { me } = await parent();
const params = Object.fromEntries(url.searchParams.entries());
const list = params.list ?? "owned";
const query = params.query;
let projects: Project[];
if (list === "owned") {
projects = await getOwned(me.id);
projects = await getOwned(me.id, query);
} else if (list === "shared") {
projects = await getShared(me.id);
projects = await getShared(me.id, query);
}

return {
Expand Down

0 comments on commit c7bc5bd

Please sign in to comment.