Skip to content

Commit

Permalink
Add "Private" checkbox to ProjectDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Feb 20, 2024
1 parent 96baa0e commit 90f21f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/api/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ import { queryBuilder } from "../util/url.js";
import type { Page, Project, User, Document, DocumentAccess } from "./types";

// Create a project
export async function newProject(title, description): Promise<Project> {
export async function newProject(
title: string,
description: string,
isPrivate: boolean,
): Promise<Project> {
const { data } = await session.post(apiUrl("projects/"), {
title,
description,
private: isPrivate,
});
return data;
}
Expand All @@ -28,10 +33,12 @@ export async function updateProject(
projectId: number,
title: string,
description: string,
isPrivate: boolean,
): Promise<Project> {
const { data } = await session.patch(apiUrl(`projects/${projectId}/`), {
title,
description,
private: isPrivate,
});
return data;
}
Expand Down
20 changes: 18 additions & 2 deletions src/common/dialog/ProjectDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
let name = layout.projectEdit == null ? "" : layout.projectEdit.title;
let description =
layout.projectEdit == null ? "" : layout.projectEdit.description;
let isPrivate =
layout.projectEdit == null ? false : layout.projectEdit.private;
let loading = writable(false);
$: editing = $layout.projectEdit != null;
Expand All @@ -46,11 +48,16 @@
if (editing) {
await wrapLoadSeparate(loading, layout, async () => {
await editProject(layout.projectEdit, normalizedName, description);
await editProject(
layout.projectEdit,
normalizedName,
description,
isPrivate,
);
});
} else {
await wrapLoadSeparate(loading, layout, async () => {
await createNewProject(normalizedName, description);
await createNewProject(normalizedName, description, isPrivate);
});
}
$lastUpdated = new Date();
Expand Down Expand Up @@ -101,6 +108,10 @@
use:textAreaResize
/>
</p>
<label class="checkbox">
<input type="checkbox" bind:checked={isPrivate} />
Private
</label>
{#if editing}
<p>
<Button nondescript={true} on:click={showCollaborators}>
Expand Down Expand Up @@ -154,4 +165,9 @@
p {
margin-bottom: 0;
}
.checkbox {
display: flex;
gap: 0.5rem;
}
</style>
13 changes: 9 additions & 4 deletions src/manager/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ export async function initProjects(me) {
projects.projects = newProjects.map((project) => new Project(project));
}

export async function createNewProject(title, description) {
const project = await newProject(title, description);
export async function createNewProject(title, description, isPrivate) {
const project = await newProject(title, description, isPrivate);
projects.projects = [...projects.projects, new Project(project)];
}

export async function editProject(project, title, description) {
const updatedProject = await updateProject(project.id, title, description);
export async function editProject(project, title, description, isPrivate) {
const updatedProject = await updateProject(
project.id,
title,
description,
isPrivate,
);
projects.projects = projects.projects.map((oldProject) => {
if (project.id == oldProject.id) {
return new Project(updatedProject);
Expand Down

0 comments on commit 90f21f2

Please sign in to comment.