import React from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import userService from '../api/services/userService'; import Dropdown from '../components/Dropdown'; import { useDarkTheme } from '../hooks'; import { selectChunks, selectPrompt, selectTokenLimit, setChunks, setModalStateDeleteConv, setPrompt, setTokenLimit, } from '../preferences/preferenceSlice'; import Prompts from './Prompts'; export default function General() { const { t, i18n: { changeLanguage, language }, } = useTranslation(); const themes = ['Light', 'Dark']; const languageOptions = [ { label: 'English', value: 'en', }, { label: 'Spanish', value: 'es', }, { label: 'Japanese', value: 'jp', }, { label: 'Mandarin', value: 'zh', }, ]; const chunks = ['0', '2', '4', '6', '8', '10']; const token_limits = new Map([ [0, t('settings.general.none')], [100, t('settings.general.low')], [1000, t('settings.general.medium')], [2000, t('settings.general.default')], [4000, t('settings.general.high')], [1e9, t('settings.general.unlimited')], ]); const [prompts, setPrompts] = React.useState< { name: string; id: string; type: string }[] >([]); const selectedChunks = useSelector(selectChunks); const selectedTokenLimit = useSelector(selectTokenLimit); const [isDarkTheme, toggleTheme] = useDarkTheme(); const [selectedTheme, setSelectedTheme] = React.useState( isDarkTheme ? 'Dark' : 'Light', ); const dispatch = useDispatch(); const locale = localStorage.getItem('docsgpt-locale'); const [selectedLanguage, setSelectedLanguage] = React.useState( locale ? languageOptions.find((option) => option.value === locale) : languageOptions[0], ); const selectedPrompt = useSelector(selectPrompt); React.useEffect(() => { const handleFetchPrompts = async () => { try { const response = await userService.getPrompts(); if (!response.ok) { throw new Error('Failed to fetch prompts'); } const promptsData = await response.json(); setPrompts(promptsData); } catch (error) { console.error(error); } }; handleFetchPrompts(); }, []); React.useEffect(() => { localStorage.setItem('docsgpt-locale', selectedLanguage?.value as string); changeLanguage(selectedLanguage?.value); }, [selectedLanguage, changeLanguage]); return (
{t('settings.general.selectTheme')}
{t('settings.general.selectLanguage')}
{t('settings.general.chunks')}
{t('settings.general.convHistory')}
{t('settings.general.deleteAllLabel')}