Skip to content

Commit

Permalink
fix: edit quick popup
Browse files Browse the repository at this point in the history
  • Loading branch information
sylingd committed Jun 20, 2023
1 parent 9e7f226 commit 4131c37
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/pages/options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Options = () => {
const responsive = useResponsive();

useEffect(() => {
document.body.setAttribute('data-page-name', 'options');
prefs.ready(() => {
if (isDarkMode()) {
document.body.setAttribute('theme-mode', 'dark');
Expand Down
1 change: 1 addition & 0 deletions src/pages/popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const Popup = () => {
const [enable, setEnable] = useState(true);

useEffect(() => {
document.body.setAttribute('data-page-name', 'popup');
prefs.ready(() => {
setEnable(!prefs.get('disable-all'));
// Get dark mode setting
Expand Down
20 changes: 11 additions & 9 deletions src/share/components/rule-content-switcher.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrayField, Button, Dropdown, Form, Modal, Space, Toast, ToastFactory } from '@douyinfe/semi-ui';
import { ArrayField, Button, Dropdown, Form, Modal, Space } from '@douyinfe/semi-ui';
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
import { css } from '@emotion/css';
import { useLatest } from 'ahooks';
Expand All @@ -8,14 +8,15 @@ import type { RULE_ACTION_OBJ, Rule } from '@/share/core/types';
import useStorage from '@/share/hooks/use-storage';
import Api from '@/share/pages/api';
import { getVirtualKey, t } from '@/share/core/utils';
import { Toast } from '@/share/pages/toast';
import type { DropdownProps } from '@douyinfe/semi-ui/lib/es/dropdown';

interface RuleContentSwitcherEditProps {
initValue: string[];
onChange: (v: string[]) => void;
}
const RuleContentSwitcherEdit: FC<RuleContentSwitcherEditProps> = (props) => {
const { initValue, onChange } = props;
const { initValue = [''], onChange } = props;

return (
<Form
Expand All @@ -24,12 +25,17 @@ const RuleContentSwitcherEdit: FC<RuleContentSwitcherEditProps> = (props) => {
}}
onValueChange={(v) => onChange(v.value)}
>
<ArrayField field="value" initValue={['']}>
<ArrayField field="value" initValue={initValue}>
{({ add, arrayFields }) => (
<div
className={css`
display: flex;
flex-direction: column;
.semi-space > .semi-form-field {
flex-grow: 1;
flex-shrink: 1;
}
`}
>
{arrayFields.map(({ key, field, remove }) => (
Expand Down Expand Up @@ -64,15 +70,11 @@ const RuleContentSwitcher: FC<RuleContentSwitcherProps> = (props) => {
const updateRule = async (k: string, v: any) => {
const newRule = { ...newestRule.current };
newRule[k] = v;
const myToast = add ? Toast : ToastFactory.create({
top: 'auto',
bottom: 0,
});
try {
await Api.saveRule(newRule);
myToast.success(t('switch_success'));
Toast().success(t('switch_success'));
} catch (e) {
myToast.error(e.message);
Toast().error(e.message);
}
};

Expand Down
13 changes: 13 additions & 0 deletions src/share/pages/toast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Toast as SemiToast, ToastFactory } from '@douyinfe/semi-ui';

export const BottomToast = ToastFactory.create({
top: 'auto',
bottom: 0,
});

export const Toast = () => {
if (document.body.getAttribute('data-page-name') === 'popup') {
return BottomToast;
}
return SemiToast;
};

0 comments on commit 4131c37

Please sign in to comment.