feat: confirm_before clear rules
This commit is contained in:
@@ -20,6 +20,7 @@ import { isValidWord } from "../../libs/utils";
|
|||||||
import { kissLog } from "../../libs/log";
|
import { kissLog } from "../../libs/log";
|
||||||
import { apiTranslate } from "../../apis";
|
import { apiTranslate } from "../../apis";
|
||||||
import { OPT_TRANS_BAIDU, PHONIC_MAP } from "../../config";
|
import { OPT_TRANS_BAIDU, PHONIC_MAP } from "../../config";
|
||||||
|
import { useConfirm } from "../../hooks/Confirm";
|
||||||
|
|
||||||
function FavAccordion({ word, index }) {
|
function FavAccordion({ word, index }) {
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
@@ -51,6 +52,7 @@ function FavAccordion({ word, index }) {
|
|||||||
export default function FavWords() {
|
export default function FavWords() {
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
const { favList, wordList, mergeWords, clearWords } = useFavWords();
|
const { favList, wordList, mergeWords, clearWords } = useFavWords();
|
||||||
|
const confirm = useConfirm();
|
||||||
|
|
||||||
const handleImport = (data) => {
|
const handleImport = (data) => {
|
||||||
try {
|
try {
|
||||||
@@ -64,6 +66,16 @@ export default function FavWords() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClearWords = async () => {
|
||||||
|
const isConfirmed = await confirm({
|
||||||
|
confirmText: i18n("confirm_title"),
|
||||||
|
cancelText: i18n("cancel"),
|
||||||
|
});
|
||||||
|
if (isConfirmed) {
|
||||||
|
clearWords();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleTranslation = async () => {
|
const handleTranslation = async () => {
|
||||||
const tranList = [];
|
const tranList = [];
|
||||||
for (const text of wordList) {
|
for (const text of wordList) {
|
||||||
@@ -133,9 +145,7 @@ export default function FavWords() {
|
|||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={() => {
|
onClick={handleClearWords}
|
||||||
clearWords();
|
|
||||||
}}
|
|
||||||
startIcon={<ClearAllIcon />}
|
startIcon={<ClearAllIcon />}
|
||||||
>
|
>
|
||||||
{i18n("clear_all")}
|
{i18n("clear_all")}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ import SaveIcon from "@mui/icons-material/Save";
|
|||||||
import { kissLog } from "../../libs/log";
|
import { kissLog } from "../../libs/log";
|
||||||
import { useApiList } from "../../hooks/Api";
|
import { useApiList } from "../../hooks/Api";
|
||||||
import ShowMoreButton from "./ShowMoreButton";
|
import ShowMoreButton from "./ShowMoreButton";
|
||||||
|
import { useConfirm } from "../../hooks/Confirm";
|
||||||
|
|
||||||
const calculateInitialValues = (rule) => {
|
const calculateInitialValues = (rule) => {
|
||||||
const base = rule?.pattern === "*" ? GLOBLA_RULE : DEFAULT_RULE;
|
const base = rule?.pattern === "*" ? GLOBLA_RULE : DEFAULT_RULE;
|
||||||
@@ -773,6 +774,7 @@ function UserRules({ subRules, rules }) {
|
|||||||
const [showAdd, setShowAdd] = useState(false);
|
const [showAdd, setShowAdd] = useState(false);
|
||||||
const { setting, updateSetting } = useSetting();
|
const { setting, updateSetting } = useSetting();
|
||||||
const [keyword, setKeyword] = useState("");
|
const [keyword, setKeyword] = useState("");
|
||||||
|
const confirm = useConfirm();
|
||||||
|
|
||||||
const injectRules = !!setting?.injectRules;
|
const injectRules = !!setting?.injectRules;
|
||||||
const { selectedUrl, selectedRules } = subRules;
|
const { selectedUrl, selectedRules } = subRules;
|
||||||
@@ -791,6 +793,16 @@ function UserRules({ subRules, rules }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClearAll = async () => {
|
||||||
|
const isConfirmed = await confirm({
|
||||||
|
confirmText: i18n("confirm_title"),
|
||||||
|
cancelText: i18n("cancel"),
|
||||||
|
});
|
||||||
|
if (isConfirmed) {
|
||||||
|
rules.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!showAdd) {
|
if (!showAdd) {
|
||||||
setKeyword("");
|
setKeyword("");
|
||||||
@@ -844,9 +856,7 @@ function UserRules({ subRules, rules }) {
|
|||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={() => {
|
onClick={handleClearAll}
|
||||||
rules.clear();
|
|
||||||
}}
|
|
||||||
startIcon={<ClearAllIcon />}
|
startIcon={<ClearAllIcon />}
|
||||||
>
|
>
|
||||||
{i18n("clear_all")}
|
{i18n("clear_all")}
|
||||||
|
|||||||
Reference in New Issue
Block a user