diff --git a/src/Components/CreateSchemaDialog.tsx b/src/Components/CreateSchemaDialog.tsx index b8ae2f4..fa3913c 100644 --- a/src/Components/CreateSchemaDialog.tsx +++ b/src/Components/CreateSchemaDialog.tsx @@ -10,7 +10,7 @@ import ExplorerFolder from "./ExplorerFolder"; import Spinner from "./Spinner"; import { invalidCharsRegex, newFileTemplate, tshetUinhExamplesURLPrefix } from "../consts"; import samples from "../samples"; -import { fetchFile, normalizeFileName } from "../utils"; +import { fetchFile, normalizeFileName, stopPropagation } from "../utils"; import type { Folder, Sample, SchemaState } from "../consts"; import type { ChangeEventHandler, FormEvent, RefObject } from "react"; @@ -267,8 +267,8 @@ const CreateSchemaDialog = forwardRef - + + 新增方案
    diff --git a/src/Components/Main.tsx b/src/Components/Main.tsx index a0ee91d..cf25d33 100644 --- a/src/Components/Main.tsx +++ b/src/Components/Main.tsx @@ -14,6 +14,7 @@ import evaluate from "../evaluate"; import { listenArticle } from "../options"; import initialState, { stateStorageLocation } from "../state"; import TooltipLabel from "./TooltipLabel"; +import { stopPropagation } from "../utils"; import type { MainState, Option, ReactNode } from "../consts"; import type { MutableRefObject } from "react"; @@ -161,6 +162,9 @@ export default function Main({ evaluateHandlerRef }: { evaluateHandlerRef: Mutab const [operation, increaseOperation] = useReducer((operation: number) => operation + 1, 0); const dialogRef = useRef(null); + const closeDialog = useCallback(() => { + dialogRef.current?.close(); + }, []); evaluateHandlerRef.current = useCallback(async () => { evaluationResult = []; dialogRef.current?.showModal(); @@ -169,11 +173,11 @@ export default function Main({ evaluateHandlerRef }: { evaluateHandlerRef: Mutab evaluationResult = await evaluate(state); increaseOperation(); } catch { - dialogRef.current?.close(); + closeDialog(); } finally { setLoading(false); } - }, [state]); + }, [state, closeDialog]); const [loading, setLoading] = useState(false); @@ -292,8 +296,8 @@ export default function Main({ evaluateHandlerRef }: { evaluateHandlerRef: Mutab evaluateHandlerRef={evaluateHandlerRef} /> {createPortal( - - + + <span>推導結果</span> {!loading && ( diff --git a/src/Components/Tooltip.tsx b/src/Components/Tooltip.tsx index 8fc4060..da408e0 100644 --- a/src/Components/Tooltip.tsx +++ b/src/Components/Tooltip.tsx @@ -3,6 +3,8 @@ import { createRoot } from "react-dom/client"; import { css as stylesheet } from "@emotion/css"; +import { stopPropagation } from "../utils"; + import type { ReactElement, SyntheticEvent } from "react"; function getPageWidth() { @@ -34,6 +36,7 @@ const fixedWidthStyle = stylesheet` `; const div = document.getElementById("tooltip") ?? document.createElement("div"); +div.addEventListener("click", stopPropagation); div.id = "tooltip"; div.style.visibility = "hidden"; div.className = tooltipStyle; diff --git a/src/utils.tsx b/src/utils.tsx index c016d99..e54dbf4 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -4,6 +4,7 @@ import styled from "@emotion/styled"; import Swal from "./Classes/SwalReact"; import Spinner from "./Components/Spinner"; +import type { SyntheticEvent } from "react"; import type { SweetAlertOptions } from "sweetalert2"; const LoadModal = styled.div` @@ -119,3 +120,7 @@ export function displaySchemaLoadingErrors(errors: unknown[], nSchemas: number) notifyError(nSchemas === 1 ? "無法載入方案" : "1 個方案無法載入", errors[0]); } } + +export function stopPropagation(event: Event | SyntheticEvent) { + event.stopPropagation(); +}