}
- onClick={() => {
- if (confirm(Locale.Settings.Actions.ConfirmClearAll)) {
+ onClick={async () => {
+ if (
+ await showConfirm(Locale.Settings.Actions.ConfirmClearAll)
+ ) {
chatStore.clearAllData();
}
}}
@@ -389,8 +392,10 @@ export function Settings() {
}
- onClick={() => {
- if (confirm(Locale.Settings.Actions.ConfirmResetAll)) {
+ onClick={async () => {
+ if (
+ await showConfirm(Locale.Settings.Actions.ConfirmResetAll)
+ ) {
resetConfig();
}
}}
diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx
index 038ca86f..d9d861d5 100644
--- a/app/components/sidebar.tsx
+++ b/app/components/sidebar.tsx
@@ -26,7 +26,7 @@ import {
import { Link, useNavigate } from "react-router-dom";
import { useMobileScreen } from "../utils";
import dynamic from "next/dynamic";
-import { showToast } from "./ui-lib";
+import { showConfirm, showToast } from "./ui-lib";
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, {
loading: () => null,
@@ -160,8 +160,8 @@ export function SideBar(props: { className?: string }) {
}
- onClick={() => {
- if (confirm(Locale.Home.DeleteChat)) {
+ onClick={async () => {
+ if (await showConfirm(Locale.Home.DeleteChat)) {
chatStore.deleteSession(chatStore.currentSessionIndex);
}
}}
diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx
index be9b30a6..156eecfa 100644
--- a/app/components/ui-lib.tsx
+++ b/app/components/ui-lib.tsx
@@ -4,6 +4,7 @@ import CloseIcon from "../icons/close.svg";
import EyeIcon from "../icons/eye.svg";
import EyeOffIcon from "../icons/eye-off.svg";
import DownIcon from "../icons/down.svg";
+import Locale from "../locales";
import { createRoot } from "react-dom/client";
import React, { HTMLProps, useEffect, useState } from "react";
@@ -87,7 +88,7 @@ export function Loading() {
interface ModalProps {
title: string;
- children?: JSX.Element | JSX.Element[];
+ children?: any;
actions?: JSX.Element[];
onClose?: () => void;
}
@@ -262,3 +263,45 @@ export function Select(
);
}
+
+export function showConfirm(content: any) {
+ const div = document.createElement("div");
+ div.className = "modal-mask";
+ document.body.appendChild(div);
+
+ const root = createRoot(div);
+ const closeModal = () => {
+ root.unmount();
+ div.remove();
+ };
+
+ return new Promise
((resolve) => {
+ root.render(
+ {
+ resolve(false);
+ closeModal();
+ }}
+ >,
+ {
+ resolve(true);
+ closeModal();
+ }}
+ >,
+ ]}
+ onClose={closeModal}
+ >
+ {content}
+ ,
+ );
+ });
+}