From 50f1cb0562f642e1533493280b17499d1a33b77c Mon Sep 17 00:00:00 2001 From: MrKBear Date: Thu, 24 Mar 2022 17:23:01 +0800 Subject: [PATCH] Show confim popup when delete objects --- source/Component/CommandBar/CommandBar.tsx | 2 +- .../Component/ConfirmPopup/ConfirmPopup.scss | 2 +- .../Component/ConfirmPopup/ConfirmPopup.tsx | 40 +++++++++++++++---- source/Component/Popup/Popup.scss | 1 - .../Component/TogglesInput/TogglesInput.scss | 4 ++ .../Component/TogglesInput/TogglesInput.tsx | 3 +- source/Localization/EN-US.ts | 6 +++ source/Localization/ZH-CN.ts | 6 +++ source/Panel/GroupDetails/GroupDetails.tsx | 18 +++++++-- source/Panel/LabelDetails/LabelDetails.tsx | 18 +++++++-- source/Panel/LabelList/LabelList.tsx | 14 ++++++- source/Panel/ObjectList/ObjectCommand.tsx | 24 +++++++---- source/Panel/ObjectList/ObjectList.scss | 4 ++ source/Panel/RangeDetails/RangeDetails.tsx | 19 ++++++--- 14 files changed, 129 insertions(+), 32 deletions(-) diff --git a/source/Component/CommandBar/CommandBar.tsx b/source/Component/CommandBar/CommandBar.tsx index e29e680..e6d38be 100644 --- a/source/Component/CommandBar/CommandBar.tsx +++ b/source/Component/CommandBar/CommandBar.tsx @@ -73,7 +73,7 @@ class CommandBar extends Component { - this.props.status?.popup.showPopup(ConfirmPopup, {}); + // this.props.status?.popup.showPopup(ConfirmPopup, {}); } })} diff --git a/source/Component/ConfirmPopup/ConfirmPopup.scss b/source/Component/ConfirmPopup/ConfirmPopup.scss index 50c3869..76e46ae 100644 --- a/source/Component/ConfirmPopup/ConfirmPopup.scss +++ b/source/Component/ConfirmPopup/ConfirmPopup.scss @@ -32,7 +32,7 @@ div.confirm-root { user-select: none; } - div.action-button.yes-button:hover { + div.action-button.red { color: $lt-red; } } diff --git a/source/Component/ConfirmPopup/ConfirmPopup.tsx b/source/Component/ConfirmPopup/ConfirmPopup.tsx index dbeec69..b530ea8 100644 --- a/source/Component/ConfirmPopup/ConfirmPopup.tsx +++ b/source/Component/ConfirmPopup/ConfirmPopup.tsx @@ -2,11 +2,17 @@ import { Popup } from "@Context/Popups"; import { ReactNode } from "react"; import { Message } from "@Component/Message/Message"; import { Theme } from "@Component/Theme/Theme"; -import { Localization } from "@Component/Localization/Localization"; +import { AllI18nKeys, Localization } from "@Component/Localization/Localization"; import "./ConfirmPopup.scss"; interface IConfirmPopupProps { - + titleI18N?: AllI18nKeys; + infoI18n: AllI18nKeys; + yesI18n?: AllI18nKeys; + noI18n?: AllI18nKeys; + yes?: () => any; + no?: () => any; + red?: "yes" | "no"; } class ConfirmPopup extends Popup { @@ -14,17 +20,37 @@ class ConfirmPopup extends Popup { public height: number = 180; + public onRenderHeader(): ReactNode { + return + } + public render(): ReactNode { + + const yesClassList: string[] = ["action-button", "yes-button"]; + const noClassList: string[] = ["action-button", "no-button"]; + if (this.props.red === "no") { + noClassList.push("red"); + } + if (this.props.red === "yes") { + yesClassList.push("red"); + } + return
- +
-
- +
{ + this.props.yes ? this.props.yes() : null; + this.close(); + }}> +
-
- +
{ + this.props.no ? this.props.no() : null; + this.close(); + }}> +
; diff --git a/source/Component/Popup/Popup.scss b/source/Component/Popup/Popup.scss index 39de7c4..77203ec 100644 --- a/source/Component/Popup/Popup.scss +++ b/source/Component/Popup/Popup.scss @@ -34,7 +34,6 @@ div.popup-layer.show-scale { div.popup-mask { position: absolute; - cursor: pointer; width: 100%; height: 100%; } diff --git a/source/Component/TogglesInput/TogglesInput.scss b/source/Component/TogglesInput/TogglesInput.scss index b89fa89..adb948c 100644 --- a/source/Component/TogglesInput/TogglesInput.scss +++ b/source/Component/TogglesInput/TogglesInput.scss @@ -15,6 +15,10 @@ div.toggles-input { cursor: pointer; user-select: none; } + + div.checkbox.red:hover { + color: $lt-red !important; + } } div.dark.text-field-root { diff --git a/source/Component/TogglesInput/TogglesInput.tsx b/source/Component/TogglesInput/TogglesInput.tsx index a355ddb..bf96f22 100644 --- a/source/Component/TogglesInput/TogglesInput.tsx +++ b/source/Component/TogglesInput/TogglesInput.tsx @@ -8,6 +8,7 @@ interface ITogglesInputProps extends ITextFieldProps { onIconName?: string; offIconName?: string; valueChange?: (value: boolean) => any; + red?: boolean; } class TogglesInput extends Component { @@ -20,7 +21,7 @@ class TogglesInput extends Component { customStyle >
{ /> { if (this.props.status) { - this.props.status.model.deleteObject([group]); - this.props.status.setFocusObject(new Set()); + const status = this.props.status; + status.popup.showPopup(ConfirmPopup, { + infoI18n: "Popup.Delete.Objects.Confirm", + titleI18N: "Popup.Action.Objects.Confirm.Title", + yesI18n: "Popup.Action.Objects.Confirm.Delete", + red: "yes", + yes: () => { + status.model.deleteObject([group]); + status.setFocusObject(new Set()); + } + }) } }} /> @@ -147,7 +157,7 @@ class GroupDetails extends Component { /> { group.killIndividuals() diff --git a/source/Panel/LabelDetails/LabelDetails.tsx b/source/Panel/LabelDetails/LabelDetails.tsx index 28691db..5b55fba 100644 --- a/source/Panel/LabelDetails/LabelDetails.tsx +++ b/source/Panel/LabelDetails/LabelDetails.tsx @@ -5,6 +5,7 @@ import { Message } from "@Component/Message/Message"; import { ColorInput } from "@Component/ColorInput/ColorInput"; import { Label } from "@Model/Label"; import { TogglesInput } from "@Component/TogglesInput/TogglesInput"; +import { ConfirmPopup } from "@Component/ConfirmPopup/ConfirmPopup"; import "./LabelDetails.scss"; @useStatusWithEvent("focusLabelChange", "labelAttrChange", "labelChange") @@ -27,10 +28,21 @@ class LabelDetails extends Component { } }}/> - { + { if (this.props.status) { - this.props.status.model.deleteLabel(label); - this.props.status.setLabelObject(); + const status = this.props.status; + status.popup.showPopup(ConfirmPopup, { + infoI18n: "Popup.Delete.Objects.Confirm", + titleI18N: "Popup.Action.Objects.Confirm.Title", + yesI18n: "Popup.Action.Objects.Confirm.Delete", + red: "yes", + yes: () => { + status.model.deleteLabel(label); + status.setLabelObject(); + } + }) } }}/> diff --git a/source/Panel/LabelList/LabelList.tsx b/source/Panel/LabelList/LabelList.tsx index f1f9a80..51704a5 100644 --- a/source/Panel/LabelList/LabelList.tsx +++ b/source/Panel/LabelList/LabelList.tsx @@ -4,6 +4,7 @@ import { useStatusWithEvent, IMixinStatusProps } from "@Context/Status"; import { useSetting, IMixinSettingProps } from "@Context/Setting"; import { Label } from "@Model/Label"; import { Message } from "@Component/Message/Message"; +import { ConfirmPopup } from "@Component/ConfirmPopup/ConfirmPopup"; import "./LabelList.scss"; interface ILabelListProps { @@ -47,8 +48,17 @@ class LabelList extends Component { if (this.props.status) { - this.props.status.model.deleteLabel(label); - this.props.status.setLabelObject(); + const status = this.props.status; + status.popup.showPopup(ConfirmPopup, { + infoI18n: "Popup.Delete.Objects.Confirm", + titleI18N: "Popup.Action.Objects.Confirm.Title", + yesI18n: "Popup.Action.Objects.Confirm.Delete", + red: "yes", + yes: () => { + status.model.deleteLabel(label); + status.setLabelObject(); + } + }) } this.labelInnerClick = true; }} diff --git a/source/Panel/ObjectList/ObjectCommand.tsx b/source/Panel/ObjectList/ObjectCommand.tsx index 71cbe42..0450399 100644 --- a/source/Panel/ObjectList/ObjectCommand.tsx +++ b/source/Panel/ObjectList/ObjectCommand.tsx @@ -1,5 +1,6 @@ import { BackgroundLevel, FontLevel, Theme } from "@Component/Theme/Theme"; import { useStatus, IMixinStatusProps } from "../../Context/Status"; +import { ConfirmPopup } from "@Component/ConfirmPopup/ConfirmPopup"; import { Icon } from "@fluentui/react"; import { Component, ReactNode } from "react"; import { ObjectID } from "@Model/Renderer"; @@ -54,15 +55,24 @@ class ObjectCommand extends Component {
{ - if (this.props.status) { - let deleteId: ObjectID[] = []; - this.props.status.focusObject.forEach((obj) => { - deleteId.push(obj); + if (this.props.status && this.props.status.focusObject.size > 0) { + const status = this.props.status; + status.popup.showPopup(ConfirmPopup, { + infoI18n: "Popup.Delete.Objects.Confirm", + titleI18N: "Popup.Action.Objects.Confirm.Title", + yesI18n: "Popup.Action.Objects.Confirm.Delete", + red: "yes", + yes: () => { + let deleteId: ObjectID[] = []; + status.focusObject.forEach((obj) => { + deleteId.push(obj); + }) + status.model.deleteObject(deleteId); + status.setFocusObject(new Set()); + } }) - this.props.status.model.deleteObject(deleteId); - this.props.status.setFocusObject(new Set()); } }} > diff --git a/source/Panel/ObjectList/ObjectList.scss b/source/Panel/ObjectList/ObjectList.scss index b98f127..e0e197a 100644 --- a/source/Panel/ObjectList/ObjectList.scss +++ b/source/Panel/ObjectList/ObjectList.scss @@ -59,6 +59,10 @@ div.object-list-command-bar { user-select: none; cursor: pointer; } + + div.command-item.red:hover { + color: $lt-red; + } } div.dark.object-list-command-bar { diff --git a/source/Panel/RangeDetails/RangeDetails.tsx b/source/Panel/RangeDetails/RangeDetails.tsx index ff9adb3..f5aeee9 100644 --- a/source/Panel/RangeDetails/RangeDetails.tsx +++ b/source/Panel/RangeDetails/RangeDetails.tsx @@ -1,13 +1,13 @@ import { Component, ReactNode } from "react"; import { AttrInput } from "@Component/AttrInput/AttrInput"; import { useStatusWithEvent, IMixinStatusProps, Status } from "@Context/Status"; -import { AllI18nKeys } from "@Component/Localization/Localization"; import { Message } from "@Component/Message/Message"; import { Range } from "@Model/Range"; import { ObjectID } from "@Model/Renderer"; import { ColorInput } from "@Component/ColorInput/ColorInput"; import { TogglesInput } from "@Component/TogglesInput/TogglesInput"; import { LabelPicker } from "@Component/LabelPicker/LabelPicker"; +import { ConfirmPopup } from "@Component/ConfirmPopup/ConfirmPopup"; import "./RangeDetails.scss"; @useStatusWithEvent("rangeAttrChange", "focusObjectChange", "rangeLabelChange") @@ -53,12 +53,21 @@ class RangeDetails extends Component { /> { - if (this.props.status) { - this.props.status.model.deleteObject([range]); - this.props.status.setFocusObject(new Set()); + if (this.props.status) { + const status = this.props.status; + status.popup.showPopup(ConfirmPopup, { + infoI18n: "Popup.Delete.Objects.Confirm", + titleI18N: "Popup.Action.Objects.Confirm.Title", + yesI18n: "Popup.Action.Objects.Confirm.Delete", + red: "yes", + yes: () => { + status.model.deleteObject([range]); + status.setFocusObject(new Set()); + } + }) } }} />