From ebfc0ce6720718dc2d1c73b8d6c4d9d72f84abee Mon Sep 17 00:00:00 2001 From: josc146 Date: Tue, 6 Jun 2023 00:12:58 +0800 Subject: [PATCH] add ResetConfigsButton to Home Page --- frontend/src/components/DialogButton.tsx | 46 +++++++++++++++ .../src/components/ResetConfigsButton.tsx | 17 ++++++ frontend/src/pages/Configs.tsx | 56 +++---------------- frontend/src/pages/Home.tsx | 5 +- 4 files changed, 74 insertions(+), 50 deletions(-) create mode 100644 frontend/src/components/DialogButton.tsx create mode 100644 frontend/src/components/ResetConfigsButton.tsx diff --git a/frontend/src/components/DialogButton.tsx b/frontend/src/components/DialogButton.tsx new file mode 100644 index 0000000..c22c951 --- /dev/null +++ b/frontend/src/components/DialogButton.tsx @@ -0,0 +1,46 @@ +import { FC, ReactElement } from 'react'; +import { + Button, + Dialog, + DialogActions, + DialogBody, + DialogContent, + DialogSurface, + DialogTitle, + DialogTrigger +} from '@fluentui/react-components'; +import { ToolTipButton } from './ToolTipButton'; +import { useTranslation } from 'react-i18next'; + +export const DialogButton: FC<{ + icon: ReactElement, + tooltip: string, + title: string, + contentText: string, + onConfirm: () => void +}> = ({ tooltip, icon, title, contentText, onConfirm }) => { + const { t } = useTranslation(); + + return + + + + + + {title} + + {contentText} + + + + + + + + + + + + ; +}; \ No newline at end of file diff --git a/frontend/src/components/ResetConfigsButton.tsx b/frontend/src/components/ResetConfigsButton.tsx new file mode 100644 index 0000000..748c934 --- /dev/null +++ b/frontend/src/components/ResetConfigsButton.tsx @@ -0,0 +1,17 @@ +import React, { FC } from 'react'; +import { DialogButton } from './DialogButton'; +import { useTranslation } from 'react-i18next'; +import { ArrowReset20Regular } from '@fluentui/react-icons'; +import commonStore from '../stores/commonStore'; +import { defaultModelConfigs } from '../pages/Configs'; + +export const ResetConfigsButton: FC<{ afterConfirm?: () => void }> = ({ afterConfirm }) => { + const { t } = useTranslation(); + return } tooltip={t('Reset All Configs')} title={t('Reset All Configs')} + contentText={t('Are you sure you want to reset all configs? This will obtain the latest preset configs, but will override your custom configs and cannot be undone.')} + onConfirm={() => { + commonStore.setModelConfigs(defaultModelConfigs, false); + commonStore.setCurrentConfigIndex(0, true); + afterConfirm?.(); + }} />; +}; \ No newline at end of file diff --git a/frontend/src/pages/Configs.tsx b/frontend/src/pages/Configs.tsx index c59691c..168e339 100644 --- a/frontend/src/pages/Configs.tsx +++ b/frontend/src/pages/Configs.tsx @@ -1,27 +1,5 @@ -import { - Button, - Dialog, - DialogActions, - DialogBody, - DialogContent, - DialogSurface, - DialogTitle, - DialogTrigger, - Dropdown, - Input, - Label, - Option, - Select, - Switch, - Text -} from '@fluentui/react-components'; -import { - AddCircle20Regular, - ArrowReset20Regular, - DataUsageSettings20Regular, - Delete20Regular, - Save20Regular -} from '@fluentui/react-icons'; +import { Dropdown, Input, Label, Option, Select, Switch, Text } from '@fluentui/react-components'; +import { AddCircle20Regular, DataUsageSettings20Regular, Delete20Regular, Save20Regular } from '@fluentui/react-icons'; import React, { FC } from 'react'; import { Section } from '../components/Section'; import { Labeled } from '../components/Labeled'; @@ -41,6 +19,7 @@ import { useTranslation } from 'react-i18next'; import { WindowShow } from '../../wailsjs/runtime/runtime'; import strategyImg from '../assets/images/strategy.jpg'; import strategyZhImg from '../assets/images/strategy_zh.jpg'; +import { ResetConfigsButton } from '../components/ResetConfigsButton'; export type ApiParameters = { apiPort: number @@ -704,31 +683,10 @@ export const Configs: FC = observer(() => { commonStore.deleteModelConfig(selectedIndex); updateSelectedIndex(Math.min(selectedIndex, commonStore.modelConfigs.length - 1)); }} /> - - - } /> - - - - {t('Reset All Configs')} - - {t('Are you sure you want to reset all configs? This will obtain the latest preset configs, but will override your custom configs and cannot be undone.')} - - - - - - - - - - - - + { + setSelectedIndex(0); + setSelectedConfig(commonStore.modelConfigs[0]); + }} /> } onClick={onClickSave} />
diff --git a/frontend/src/pages/Home.tsx b/frontend/src/pages/Home.tsx index b7e4064..d37634a 100644 --- a/frontend/src/pages/Home.tsx +++ b/frontend/src/pages/Home.tsx @@ -17,6 +17,7 @@ import { ConfigSelector } from '../components/ConfigSelector'; import MarkdownRender from '../components/MarkdownRender'; import commonStore from '../stores/commonStore'; import { Completion } from './Completion'; +import { ResetConfigsButton } from '../components/ResetConfigsButton'; export type IntroductionContent = { [lang: string]: string } @@ -65,7 +66,8 @@ export const Home: FC = observer(() => { return (
- +
{t('Introduction')}
@@ -85,6 +87,7 @@ export const Home: FC = observer(() => {
+