refactor: extract double confirmation logic into reusable function
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
CheckIcon,
|
CheckIcon,
|
||||||
} from "lucide-svelte";
|
} from "lucide-svelte";
|
||||||
import TextAreaInput from "../UI/GUI/TextAreaInput.svelte";
|
import TextAreaInput from "../UI/GUI/TextAreaInput.svelte";
|
||||||
import { alertConfirm } from "../../ts/alert";
|
import { alertConfirm, showHypaV3Alert } from "../../ts/alert";
|
||||||
import { DBState, alertStore, selectedCharID } from "src/ts/stores.svelte";
|
import { DBState, alertStore, selectedCharID } from "src/ts/stores.svelte";
|
||||||
import { summarize } from "src/ts/process/memory/hypav3";
|
import { summarize } from "src/ts/process/memory/hypav3";
|
||||||
import { translateHTML } from "src/ts/translator/translator";
|
import { translateHTML } from "src/ts/translator/translator";
|
||||||
@@ -65,6 +65,21 @@
|
|||||||
expandedMessageUIState = null;
|
expandedMessageUIState = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function confirmTwice(
|
||||||
|
firstMessage: string,
|
||||||
|
secondMessage: string
|
||||||
|
): Promise<boolean> {
|
||||||
|
let confirmed = await alertConfirm(firstMessage);
|
||||||
|
|
||||||
|
if (confirmed) {
|
||||||
|
confirmed = await alertConfirm(secondMessage);
|
||||||
|
|
||||||
|
if (confirmed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getMessageFromChatMemo(
|
function getMessageFromChatMemo(
|
||||||
chatMemo: string | null
|
chatMemo: string | null
|
||||||
): { role: string; data: string } | null {
|
): { role: string; data: string } | null {
|
||||||
@@ -327,22 +342,19 @@
|
|||||||
<button
|
<button
|
||||||
class="p-2 text-zinc-400 hover:text-zinc-200 hover:text-rose-300 transition-colors"
|
class="p-2 text-zinc-400 hover:text-zinc-200 hover:text-rose-300 transition-colors"
|
||||||
onclick={async () => {
|
onclick={async () => {
|
||||||
let confirmed = await alertConfirm(
|
if (
|
||||||
"This action cannot be undone. Do you want to reset HypaV3 data?"
|
await confirmTwice(
|
||||||
);
|
"This action cannot be undone. Do you want to reset HypaV3 data?",
|
||||||
|
|
||||||
if (confirmed) {
|
|
||||||
confirmed = await alertConfirm(
|
|
||||||
"This action is irreversible. Do you really, really want to reset HypaV3 data?"
|
"This action is irreversible. Do you really, really want to reset HypaV3 data?"
|
||||||
);
|
)
|
||||||
|
) {
|
||||||
if (confirmed) {
|
DBState.db.characters[$selectedCharID].chats[
|
||||||
DBState.db.characters[$selectedCharID].chats[
|
DBState.db.characters[$selectedCharID].chatPage
|
||||||
DBState.db.characters[$selectedCharID].chatPage
|
].hypaV3Data = {
|
||||||
].hypaV3Data = {
|
summaries: [],
|
||||||
summaries: [],
|
};
|
||||||
};
|
} else {
|
||||||
}
|
showHypaV3Alert();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user