From 27f90f41d67ec671094724bf79c128d53de22dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9F=83=E6=8B=89?= Date: Thu, 16 Jan 2025 12:10:35 +0800 Subject: [PATCH] wip: update --- src/components/core/Dialog/Dialog.tsx | 31 ++++++------------- src/components/core/Popover/Popover.tsx | 23 +++----------- src/components/core/Tooltip/Tooltip.tsx | 23 +++----------- .../ChallengeDeleteModal.tsx | 24 +++++++++++++- 4 files changed, 40 insertions(+), 61 deletions(-) diff --git a/src/components/core/Dialog/Dialog.tsx b/src/components/core/Dialog/Dialog.tsx index 20f96cb..6508730 100644 --- a/src/components/core/Dialog/Dialog.tsx +++ b/src/components/core/Dialog/Dialog.tsx @@ -1,7 +1,6 @@ import styles from "./Dialog.module.scss"; -import React, { ComponentProps, useEffect, useRef } from "react"; +import React, { ComponentProps, useRef } from "react"; import { Dialog as ArkDialog, Portal } from "@ark-ui/react"; -import { nanoid } from "nanoid"; export interface DialogProps extends ComponentProps<"dialog"> { open: boolean; @@ -11,28 +10,16 @@ export interface DialogProps extends ComponentProps<"dialog"> { export function Dialog(props: DialogProps) { const { children, open, onClose } = props; - const portal = useRef(null); - - useEffect(() => { - const ctn = document.createElement("div"); - ctn.id = `dialog-portal-${nanoid()}`; - document.getElementById("portals")!.appendChild(ctn); - portal.current = ctn; - - return () => { - if (portal.current) { - document.getElementById("portals")!.removeChild(portal.current); - portal.current = null; - } - }; - }, []); - - if (!portal.current) { - return; - } + const portal = useRef( + document.getElementById("portals") + ); return ( - onClose()}> + onClose()} + lazyMount + > diff --git a/src/components/core/Popover/Popover.tsx b/src/components/core/Popover/Popover.tsx index 2272380..fe25ac6 100644 --- a/src/components/core/Popover/Popover.tsx +++ b/src/components/core/Popover/Popover.tsx @@ -45,25 +45,9 @@ export function Popover(props: PopoverProps) { } } - const portal = useRef(null); - - useEffect(() => { - const ctn = document.createElement("div"); - ctn.id = `popover-portal-${nanoid()}`; - document.getElementById("portals")!.appendChild(ctn); - portal.current = ctn; - - return () => { - if (portal.current) { - document.getElementById("portals")!.removeChild(portal.current); - portal.current = null; - } - }; - }, []); - - if (!portal.current) { - return; - } + const portal = useRef( + document.getElementById("portals") + ); return ( { handleOpenChange(v.open); }} + lazyMount > {children} diff --git a/src/components/core/Tooltip/Tooltip.tsx b/src/components/core/Tooltip/Tooltip.tsx index f0b2b62..0825df0 100644 --- a/src/components/core/Tooltip/Tooltip.tsx +++ b/src/components/core/Tooltip/Tooltip.tsx @@ -26,25 +26,9 @@ export function Tooltip(props: TooltipProps) { children, } = props; - const portal = useRef(null); - - useEffect(() => { - const ctn = document.createElement("div"); - ctn.id = `tooltip-portal-${nanoid()}`; - document.getElementById("portals")!.appendChild(ctn); - portal.current = ctn; - - return () => { - if (portal.current) { - document.getElementById("portals")!.removeChild(portal.current); - portal.current = null; - } - }; - }, []); - - if (!portal.current) { - return; - } + const portal = useRef( + document.getElementById("portals") + ); return ( {children} diff --git a/src/pages/settings/challenges/_blocks/ChallengeDeleteModal/ChallengeDeleteModal.tsx b/src/pages/settings/challenges/_blocks/ChallengeDeleteModal/ChallengeDeleteModal.tsx index 5c436ed..98391db 100644 --- a/src/pages/settings/challenges/_blocks/ChallengeDeleteModal/ChallengeDeleteModal.tsx +++ b/src/pages/settings/challenges/_blocks/ChallengeDeleteModal/ChallengeDeleteModal.tsx @@ -1,10 +1,11 @@ -import { Box, Button, Flex, Stack } from "@/components/core"; +import { Box, Button, Dialog, Flex, Stack } from "@/components/core"; import { Challenge } from "@/models/challenge"; import TrashBinTrashBold from "~icons/solar/trash-bin-trash-bold"; import styles from "./ChallengeDeleteModal.module.scss"; import { deleteChallenge } from "@/api/challenge"; import { useToastStore } from "@/stores/toast"; import { useSharedStore } from "@/stores/shared"; +import { useState } from "react"; export interface ChallengeDeleteModalProps { challenge?: Challenge; @@ -16,6 +17,8 @@ export function ChallengeDeleteModal(props: ChallengeDeleteModalProps) { const toastStore = useToastStore(); const sharedStore = useSharedStore(); + const [open2, setOpen2] = useState(false); + function handleChallengeDelete() { deleteChallenge({ id: challenge?.id, @@ -58,7 +61,26 @@ export function ChallengeDeleteModal(props: ChallengeDeleteModalProps) { 将从题库中软删除,但无法恢复。所有与之相关的数据会得到保留。请问你确定要删除这道题目吗? + setOpen2(false)}> + + test + + +