diff --git a/components/ClearDataButton.tsx b/components/ClearDataButton.tsx new file mode 100644 index 0000000..a062653 --- /dev/null +++ b/components/ClearDataButton.tsx @@ -0,0 +1,20 @@ +import { useState } from "react"; +import { createPortal } from "react-dom"; +import ClearDataConfirmModal from "./ClearDataConfirmModal"; + +const ClearDataButton = () => { + const [showClearDataConfirmModal, setShowClearDataConfirmModal] = useState(false); + + return ( + <> + + + {showClearDataConfirmModal && + createPortal( setShowClearDataConfirmModal(false)} />, document.body)} + + ); +}; + +export default ClearDataButton; diff --git a/components/SettingModal.tsx b/components/SettingModal.tsx index 89fe98c..01925e2 100644 --- a/components/SettingModal.tsx +++ b/components/SettingModal.tsx @@ -1,68 +1,45 @@ -import { useState } from "react"; -import { createPortal } from "react-dom"; import Icon from "./Icon"; import WeChatQRCodeView from "./WeChatQRCodeView"; -import ClearDataConfirmModal from "./ClearDataConfirmModal"; +import ClearDataButton from "./ClearDataButton"; interface Props { show: boolean; close: () => void; } -interface State { - showClearDataConfirmModal: boolean; -} - const SettingModal = (props: Props) => { const { show, close } = props; - const [state, setState] = useState({ - showClearDataConfirmModal: false, - }); - - const toggleClearDataConfirmModal = (show = true) => { - setState({ - ...state, - showClearDataConfirmModal: show, - }); - }; return ( - <> -
-
-

Setting

- -
- +
+
+

Setting

+ +
+ -

Danger Zone

-
-
- Clear all data - -
+

Danger Zone

+
+
+ Clear all data +
- - {state.showClearDataConfirmModal && - createPortal( toggleClearDataConfirmModal(false)} />, document.body)} - +
); };