diff --git a/web/src/components/highlight-markdown/index.tsx b/web/src/components/highlight-markdown/index.tsx index 5147a03ea..9b21155e1 100644 --- a/web/src/components/highlight-markdown/index.tsx +++ b/web/src/components/highlight-markdown/index.tsx @@ -1,6 +1,7 @@ import classNames from 'classnames'; import Markdown from 'react-markdown'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; +import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism'; import rehypeKatex from 'rehype-katex'; import rehypeRaw from 'rehype-raw'; import remarkGfm from 'remark-gfm'; @@ -13,8 +14,10 @@ import styles from './index.less'; const HightLightMarkdown = ({ children, + dark = false, }: { children: string | null | undefined; + dark?: boolean; }) => { return ( {String(children).replace(/\n$/, '')} diff --git a/web/src/components/ui/dialog.tsx b/web/src/components/ui/dialog.tsx index 3c1b86a6f..f65644ee0 100644 --- a/web/src/components/ui/dialog.tsx +++ b/web/src/components/ui/dialog.tsx @@ -38,7 +38,7 @@ const DialogContent = React.forwardRef< & { token: string; - form: SharedFrom; + from: SharedFrom; beta: string; isAgent: boolean; }; @@ -31,14 +43,21 @@ type IProps = IModalProps & { function EmbedDialog({ hideModal, token = '', - form, + from, beta = '', isAgent, }: IProps) { const { t } = useTranslate('chat'); - const [visibleAvatar, setVisibleAvatar] = useState(false); - const [locale, setLocale] = useState(''); + const form = useForm>({ + resolver: zodResolver(FormSchema), + defaultValues: { + visibleAvatar: false, + locale: '', + }, + }); + + const values = useWatch({ control: form.control }); const languageOptions = useMemo(() => { return Object.values(LanguageAbbreviation).map((x) => ({ @@ -47,8 +66,9 @@ function EmbedDialog({ })); }, []); - const generateIframeSrc = () => { - let src = `${location.origin}/chat/share?shared_id=${token}&from=${form}&auth=${beta}`; + const generateIframeSrc = useCallback(() => { + const { visibleAvatar, locale } = values; + let src = `${location.origin}/chat/share?shared_id=${token}&from=${from}&auth=${beta}`; if (visibleAvatar) { src += '&visible_avatar=1'; } @@ -56,11 +76,11 @@ function EmbedDialog({ src += `&locale=${locale}`; } return src; - }; + }, [beta, from, token, values]); - const iframeSrc = generateIframeSrc(); - - const text = ` + const text = useMemo(() => { + const iframeSrc = generateIframeSrc(); + return ` ~~~ html