From 0c4ca9c94d57c2a65c834da047c69465cf6ebd29 Mon Sep 17 00:00:00 2001 From: utin-francis-peter Date: Sun, 23 Jun 2024 23:27:43 +0100 Subject: [PATCH] refactor: selected language gets stored in local state, triggering an effect that updates lang value in local storage and change language --- frontend/src/settings/General.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/src/settings/General.tsx b/frontend/src/settings/General.tsx index 2ceb77a2..bf917d91 100644 --- a/frontend/src/settings/General.tsx +++ b/frontend/src/settings/General.tsx @@ -84,6 +84,11 @@ const General: React.FC = () => { fetchPrompts(); }, []); + React.useEffect(() => { + localStorage.setItem('docsgpt-locale', selectedLanguage?.value as string); + changeLanguage(selectedLanguage?.value); + }, [selectedLanguage, changeLanguage]); + return (
@@ -114,8 +119,6 @@ const General: React.FC = () => { selectedValue={selectedLanguage ?? languageOptions[0]} onSelect={(selectedOption: { label: string; value: string }) => { setSelectedLanguage(selectedOption); - changeLanguage(selectedOption.value); - localStorage.setItem('docsgpt-locale', selectedOption.value); }} size="w-56" rounded="3xl"