mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-19 16:32:58 +00:00
fix: duplicate chords crash
fix: duplicate confirm dialog does not show affected chord fixes #137 fixes #163
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<script lang="ts">
|
||||
import Dialog from "$lib/dialogs/Dialog.svelte";
|
||||
import ActionString from "$lib/components/ActionString.svelte";
|
||||
import type { Chord } from "$lib/serial/chord";
|
||||
import ChordActionEdit from "../../routes/(app)/config/chords/ChordActionEdit.svelte";
|
||||
|
||||
let {
|
||||
title,
|
||||
message,
|
||||
abortTitle,
|
||||
confirmTitle,
|
||||
actions = [],
|
||||
chord,
|
||||
onabort,
|
||||
onconfirm,
|
||||
}: {
|
||||
@@ -15,7 +16,7 @@
|
||||
message?: string;
|
||||
abortTitle: string;
|
||||
confirmTitle: string;
|
||||
actions: number[];
|
||||
chord: Chord & { deleted: boolean };
|
||||
onabort: () => void;
|
||||
onconfirm: () => void;
|
||||
} = $props();
|
||||
@@ -26,7 +27,20 @@
|
||||
{#if message}
|
||||
<p>{@html message}</p>
|
||||
{/if}
|
||||
<p><ActionString {actions} /></p>
|
||||
<p>
|
||||
<ChordActionEdit
|
||||
chord={{
|
||||
...chord,
|
||||
isApplied: false,
|
||||
phraseChanged: false,
|
||||
actionsChanged: false,
|
||||
sortBy: "",
|
||||
id: chord.actions,
|
||||
}}
|
||||
interactive={false}
|
||||
onsubmit={() => {}}
|
||||
/>
|
||||
</p>
|
||||
<div class="buttons">
|
||||
<button onclick={onabort}>{abortTitle}</button>
|
||||
<button class="primary" onclick={onconfirm}>{confirmTitle}</button>
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
import ConfirmDialog from "$lib/dialogs/ConfirmDialog.svelte";
|
||||
import { mount, unmount } from "svelte";
|
||||
import type { Chord } from "$lib/serial/chord";
|
||||
|
||||
export async function askForConfirmation(
|
||||
title: string,
|
||||
message: string,
|
||||
confirmTitle: string,
|
||||
abortTitle: string,
|
||||
actions: number[],
|
||||
chord: Chord,
|
||||
): Promise<boolean> {
|
||||
const dialog = new ConfirmDialog({
|
||||
let resolvePromise: (value: boolean) => void;
|
||||
const resultPromise = new Promise<boolean>((resolve) => {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
|
||||
const dialog = mount(ConfirmDialog, {
|
||||
target: document.body,
|
||||
props: {
|
||||
title,
|
||||
message,
|
||||
confirmTitle,
|
||||
abortTitle,
|
||||
actions,
|
||||
chord,
|
||||
onabort: () => resolvePromise(false),
|
||||
onconfirm: () => resolvePromise(true),
|
||||
},
|
||||
});
|
||||
|
||||
let resolvePromise: (value: boolean) => void;
|
||||
const resultPromise = new Promise<boolean>((resolve) => {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
|
||||
dialog.$on("abort", () => resolvePromise(false));
|
||||
dialog.$on("confirm", () => resolvePromise(true));
|
||||
|
||||
const result = await resultPromise;
|
||||
dialog.$destroy();
|
||||
unmount(dialog);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user