-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
confirm deleting fwlite entries (#1337)
* enable detailed errors in web circuit * disable prerendering * allow accessing the project testing page to streamline ui dev * create a delete dialog in the project root to reuse across components * confirm deletes * fix the height of delete dialog so it's not full screen, also change the confirm button to show a trash can and style it appropriately * allow opening dialog again after dismissing by clicking outside * simplify delete dialog closing
- Loading branch information
Showing
7 changed files
with
92 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@page "/testing/project-view" | ||
@using FwLiteShared.Layout | ||
@layout SvelteLayout; |
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
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,43 @@ | ||
<script lang="ts"> | ||
import {Button, Dialog} from 'svelte-ux'; | ||
import {mdiTrashCanOutline} from '@mdi/js'; | ||
let subject: string; | ||
let open = false; | ||
let loading = false; | ||
let requester: { | ||
resolve: (result: boolean) => void | ||
} | undefined = undefined; | ||
function confirm() { | ||
resolve(true); | ||
} | ||
function cancel() { | ||
resolve(false); | ||
} | ||
function resolve(shouldDelete: boolean) { | ||
requester?.resolve(shouldDelete); | ||
requester = undefined; | ||
open = false; | ||
} | ||
export function prompt(promptSubject: string): Promise<boolean> { | ||
if (requester) throw new Error('already prompting for a delete'); | ||
return new Promise((resolve) => { | ||
requester = { resolve }; | ||
subject = promptSubject; | ||
open = true; | ||
}); | ||
} | ||
</script> | ||
<Dialog {open} on:close={cancel} {loading} persistent={loading} style="height: auto"> | ||
<div slot="title">Delete {subject}</div> | ||
<div class="m-6"> | ||
<p>Are you sure you want to delete {subject}?</p> | ||
</div> | ||
<div slot="actions"> | ||
<Button on:click={() => cancel()}>Don't delete</Button> | ||
<Button variant="fill-light" color="danger" icon={mdiTrashCanOutline} on:click={_ => confirm()}>Delete {subject}</Button> | ||
</div> | ||
</Dialog> |
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,28 @@ | ||
import type DeleteDialog from '$lib/entry-editor/DeleteDialog.svelte'; | ||
import {getContext, setContext} from 'svelte'; | ||
|
||
export function initDialogService(rootDialog: () => DeleteDialog | undefined): DialogService { | ||
const dialogService = new DialogService(rootDialog); | ||
setContext('DialogService', dialogService); | ||
return dialogService; | ||
} | ||
|
||
export function useDialogService(): DialogService { | ||
const rootDialog = getContext('DialogService'); | ||
if (!rootDialog) { | ||
throw new Error('DialogService not found'); | ||
} | ||
return rootDialog as DialogService; | ||
} | ||
|
||
export class DialogService { | ||
|
||
constructor(private deleteDialog: () => DeleteDialog | undefined) { | ||
} | ||
|
||
promptDelete(subject: string): Promise<boolean> { | ||
const deleteDialog = this.deleteDialog(); | ||
if (!deleteDialog) throw new Error('no deleted dialog found'); | ||
return deleteDialog.prompt(subject); | ||
} | ||
} |
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