From 627e1cc03aa4c525ab1a1d19ee9162db496c1faf Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Mon, 17 Apr 2023 17:36:34 +0800 Subject: [PATCH] feat: inline LaTeX toggle fixes #237 --- public/locales/da/main.json | 1 + public/locales/en-US/main.json | 1 + public/locales/en/main.json | 1 + public/locales/es/main.json | 1 + public/locales/fr/main.json | 1 + public/locales/it/main.json | 1 + public/locales/ja/main.json | 1 + public/locales/ms/main.json | 1 + public/locales/nb/main.json | 1 + public/locales/sv/main.json | 1 + public/locales/zh-CN/main.json | 1 + public/locales/zh-HK/main.json | 1 + public/locales/zh-TW/main.json | 1 + .../ChatContent/Message/MessageContent.tsx | 3 +- .../SettingsMenu/InlineLatexToggle.tsx | 28 +++++++++++++++++++ src/components/SettingsMenu/SettingsMenu.tsx | 4 ++- src/store/config-slice.ts | 9 ++++++ src/store/store.ts | 1 + 18 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/components/SettingsMenu/InlineLatexToggle.tsx diff --git a/public/locales/da/main.json b/public/locales/da/main.json index 8a28b86..66da40a 100644 --- a/public/locales/da/main.json +++ b/public/locales/da/main.json @@ -25,6 +25,7 @@ "image": "Billede", "autoTitle": "Auto generer titel", "advancedMode": "Avanceret tilstand", + "inlineLatex": "Indlejret LaTeX", "prompt": "Opgave", "promptLibrary": "Opgavebibliotek", "name": "Navn", diff --git a/public/locales/en-US/main.json b/public/locales/en-US/main.json index 4e9d5eb..9b191f8 100644 --- a/public/locales/en-US/main.json +++ b/public/locales/en-US/main.json @@ -25,6 +25,7 @@ "image": "Image", "autoTitle": "Auto generate title", "advancedMode": "Advanced mode", + "inlineLatex": "Inline Latex", "prompt": "Prompt", "promptLibrary": "Prompt Library", "name": "Name", diff --git a/public/locales/en/main.json b/public/locales/en/main.json index 4e9d5eb..9b191f8 100644 --- a/public/locales/en/main.json +++ b/public/locales/en/main.json @@ -25,6 +25,7 @@ "image": "Image", "autoTitle": "Auto generate title", "advancedMode": "Advanced mode", + "inlineLatex": "Inline Latex", "prompt": "Prompt", "promptLibrary": "Prompt Library", "name": "Name", diff --git a/public/locales/es/main.json b/public/locales/es/main.json index 10707fd..d2411a1 100644 --- a/public/locales/es/main.json +++ b/public/locales/es/main.json @@ -25,6 +25,7 @@ "image": "Imagen", "autoTitle": "Generar automáticamente el título de la conversación.", "advancedMode": "Modo avanzado", + "inlineLatex": "Latex en línea", "prompt": "Prompt", "promptLibrary": "Librería de Prompts", "name": "Nombre", diff --git a/public/locales/fr/main.json b/public/locales/fr/main.json index 31cc196..48d36a8 100644 --- a/public/locales/fr/main.json +++ b/public/locales/fr/main.json @@ -25,6 +25,7 @@ "image": "Image", "autoTitle": "Générer le titre automatiquement", "advancedMode": "Mode avancé", + "inlineLatex": "Latex en ligne", "prompt": "Incitation", "promptLibrary": "Bibliothèque de prompt", "name": "Nom", diff --git a/public/locales/it/main.json b/public/locales/it/main.json index b03e425..6147b74 100644 --- a/public/locales/it/main.json +++ b/public/locales/it/main.json @@ -25,6 +25,7 @@ "image": "Immagine", "autoTitle": "Genera automaticamente il titolo", "advancedMode": "Modalità avanzata", + "inlineLatex": "Latex in linea", "prompt": "Prompt", "promptLibrary": "Libreria Prompt", "name": "Nome", diff --git a/public/locales/ja/main.json b/public/locales/ja/main.json index 3bedf46..0fa13b5 100644 --- a/public/locales/ja/main.json +++ b/public/locales/ja/main.json @@ -25,6 +25,7 @@ "image": "画像", "autoTitle": "タイトルを自動生成", "advancedMode": "上級モード", + "inlineLatex": "インライン LaTeX", "prompt": "プロンプト", "promptLibrary": "プロンプトライブラリ", "name": "名前", diff --git a/public/locales/ms/main.json b/public/locales/ms/main.json index ab35e30..2ad660a 100644 --- a/public/locales/ms/main.json +++ b/public/locales/ms/main.json @@ -25,6 +25,7 @@ "image": "Imej", "autoTitle": "Jana tajuk secara automatik", "advancedMode": "Mod lanjutan", + "inlineLatex": "Latex Sebaris", "prompt": "Arahan", "promptLibrary": "Pustaka Arahan", "name": "Nama", diff --git a/public/locales/nb/main.json b/public/locales/nb/main.json index 20245c8..91f6fff 100644 --- a/public/locales/nb/main.json +++ b/public/locales/nb/main.json @@ -25,6 +25,7 @@ "image": "Bilde", "autoTitle": "Auto generer tittel", "advancedMode": "Avansert modus", + "inlineLatex": "Inline Latex", "prompt": "Oppgave", "promptLibrary": "Oppgavebibliotek", "name": "Navn", diff --git a/public/locales/sv/main.json b/public/locales/sv/main.json index a5619d8..e98a7e5 100644 --- a/public/locales/sv/main.json +++ b/public/locales/sv/main.json @@ -25,6 +25,7 @@ "image": "Bild", "autoTitle": "Auto generera titel", "advancedMode": "Avancerat läge", + "inlineLatex": "Inline Latex", "prompt": "Uppmaning", "promptLibrary": "Uppmaningsbibliotek", "name": "Namn", diff --git a/public/locales/zh-CN/main.json b/public/locales/zh-CN/main.json index a8c75a3..e55e8da 100644 --- a/public/locales/zh-CN/main.json +++ b/public/locales/zh-CN/main.json @@ -25,6 +25,7 @@ "image": "图片", "autoTitle": "自动生成标题", "advancedMode": "高级模式", + "inlineLatex": "行内 Latex", "prompt": "提示词", "promptLibrary": "提示词资料库", "name": "名称", diff --git a/public/locales/zh-HK/main.json b/public/locales/zh-HK/main.json index 6e3262f..c547f99 100644 --- a/public/locales/zh-HK/main.json +++ b/public/locales/zh-HK/main.json @@ -25,6 +25,7 @@ "image": "圖片", "autoTitle": "自動生成標題", "advancedMode": "高級模式", + "inlineLatex": "行內 Latex", "prompt": "Prompt", "promptLibrary": "Prompt 資料庫", "name": "名", diff --git a/public/locales/zh-TW/main.json b/public/locales/zh-TW/main.json index 6827bfc..a5a763d 100644 --- a/public/locales/zh-TW/main.json +++ b/public/locales/zh-TW/main.json @@ -25,6 +25,7 @@ "image": "圖片", "autoTitle": "自動生成標題", "advancedMode": "高級模式", + "inlineLatex": "行內 Latex", "prompt": "提示詞", "promptLibrary": "提示詞資料庫", "name": "名稱", diff --git a/src/components/Chat/ChatContent/Message/MessageContent.tsx b/src/components/Chat/ChatContent/Message/MessageContent.tsx index 9eb090e..4844450 100644 --- a/src/components/Chat/ChatContent/Message/MessageContent.tsx +++ b/src/components/Chat/ChatContent/Message/MessageContent.tsx @@ -86,6 +86,7 @@ const ContentView = React.memo( const lastMessageIndex = useStore((state) => state.chats ? state.chats[state.currentChatIndex].messages.length - 1 : 0 ); + const inlineLatex = useStore((state) => state.inlineLatex); const handleDelete = () => { const updatedChats: ChatInterface[] = JSON.parse( @@ -139,7 +140,7 @@ const ContentView = React.memo( { + const { t } = useTranslation(); + + const setInlineLatex = useStore((state) => state.setInlineLatex); + + const [isChecked, setIsChecked] = useState( + useStore.getState().inlineLatex + ); + + useEffect(() => { + setInlineLatex(isChecked); + }, [isChecked]); + + return ( + + ); +}; + +export default InlineLatexToggle; diff --git a/src/components/SettingsMenu/SettingsMenu.tsx b/src/components/SettingsMenu/SettingsMenu.tsx index f3a53c4..97865af 100644 --- a/src/components/SettingsMenu/SettingsMenu.tsx +++ b/src/components/SettingsMenu/SettingsMenu.tsx @@ -9,11 +9,12 @@ import ThemeSwitcher from '@components/Menu/MenuOptions/ThemeSwitcher'; import LanguageSelector from '@components/LanguageSelector'; import AutoTitleToggle from './AutoTitleToggle'; import AdvancedModeToggle from './AdvencedModeToggle'; +import InlineLatexToggle from './InlineLatexToggle'; + import PromptLibraryMenu from '@components/PromptLibraryMenu'; import ChatConfigMenu from '@components/ChatConfigMenu'; import EnterToSubmitToggle from './EnterToSubmitToggle'; - const SettingsMenu = () => { const { t } = useTranslation(); @@ -45,6 +46,7 @@ const SettingsMenu = () => {
+
diff --git a/src/store/config-slice.ts b/src/store/config-slice.ts index d900818..eab7c8b 100644 --- a/src/store/config-slice.ts +++ b/src/store/config-slice.ts @@ -13,6 +13,7 @@ export interface ConfigSlice { defaultSystemMessage: string; hideSideMenu: boolean; enterToSubmit: boolean; + inlineLatex: boolean; setOpenConfig: (openConfig: boolean) => void; setTheme: (theme: Theme) => void; setAutoTitle: (autoTitle: boolean) => void; @@ -22,6 +23,7 @@ export interface ConfigSlice { setHideMenuOptions: (hideMenuOptions: boolean) => void; setHideSideMenu: (hideSideMenu: boolean) => void; setEnterToSubmit: (enterToSubmit: boolean) => void; + setInlineLatex: (inlineLatex: boolean) => void; } export const createConfigSlice: StoreSlice = (set, get) => ({ @@ -34,6 +36,7 @@ export const createConfigSlice: StoreSlice = (set, get) => ({ advancedMode: true, defaultChatConfig: _defaultChatConfig, defaultSystemMessage: _defaultSystemMessage, + inlineLatex: false, setOpenConfig: (openConfig: boolean) => { set((prev: ConfigSlice) => ({ ...prev, @@ -88,4 +91,10 @@ export const createConfigSlice: StoreSlice = (set, get) => ({ enterToSubmit: enterToSubmit, })); }, + setInlineLatex: (inlineLatex: boolean) => { + set((prev: ConfigSlice) => ({ + ...prev, + inlineLatex: inlineLatex, + })); + }, }); diff --git a/src/store/store.ts b/src/store/store.ts index 9098e8e..4ab44ad 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -55,6 +55,7 @@ export const createPartializedState = (state: StoreState) => ({ hideSideMenu: state.hideSideMenu, folders: state.folders, enterToSubmit: state.enterToSubmit, + inlineLatex: state.inlineLatex, }); const useStore = create()(