-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decouples ProjectDialog from application state
- Creates container component for connecting with application state - Creates presentational component with corresponding storybook
- Loading branch information
1 parent
90f21f2
commit e17149d
Showing
4 changed files
with
234 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<script lang="ts"> | ||
import { writable } from "svelte/store"; | ||
import emitter from "../../emit.js"; | ||
import { wrapLoadSeparate } from "../../util/wrapLoad.js"; | ||
import { lastUpdated } from "../../projects/Browser.svelte"; | ||
import { | ||
createNewProject, | ||
editProject, | ||
removeProject, | ||
} from "../../manager/projects"; | ||
import { | ||
layout, | ||
showCollaborators, | ||
embedProject, | ||
} from "../../manager/layout.js"; | ||
import { showConfirm } from "../../manager/confirmDialog.js"; | ||
import ProjectDialog, { type FormData } from "./ProjectDialog.svelte"; | ||
const emit = emitter({ | ||
dismiss() {}, | ||
}); | ||
let loading = writable(false); | ||
async function upsertProject(data: FormData, isValid: boolean) { | ||
if (!isValid) return; | ||
if (editing) { | ||
await wrapLoadSeparate(loading, layout, async () => { | ||
await editProject( | ||
layout.projectEdit, | ||
data.name, | ||
data.description, | ||
data.private, | ||
); | ||
}); | ||
} else { | ||
await wrapLoadSeparate(loading, layout, async () => { | ||
await createNewProject(data.name, data.description, data.private); | ||
}); | ||
} | ||
$lastUpdated = new Date(); | ||
emit.dismiss(); | ||
} | ||
async function deleteProject() { | ||
showConfirm( | ||
"dialogProjectDialog.confirmDelete", | ||
"dialogProjectDialog.deleteProject", | ||
"dialog.delete", | ||
async () => { | ||
await wrapLoadSeparate(loading, layout, async () => { | ||
await removeProject(layout.projectEdit); | ||
}); | ||
emit.dismiss(); | ||
}, | ||
{ project: layout.projectEdit.title }, | ||
); | ||
} | ||
function cancel() { | ||
emit.dismiss(); | ||
} | ||
$: editing = $layout.projectEdit != null; | ||
$: initialData = { | ||
name: $layout.projectEdit?.title ?? "", | ||
description: $layout.projectEdit?.description ?? "", | ||
private: $layout.projectEdit?.private ?? false, | ||
}; | ||
</script> | ||
|
||
<ProjectDialog | ||
loading={$loading} | ||
{editing} | ||
{initialData} | ||
{showCollaborators} | ||
{embedProject} | ||
onSave={upsertProject} | ||
onDelete={deleteProject} | ||
onCancel={cancel} | ||
/> |
Oops, something went wrong.