import Box from "@mui/material/Box"; import Stack from "@mui/material/Stack"; import InputLabel from "@mui/material/InputLabel"; import TextField from "@mui/material/TextField"; import MenuItem from "@mui/material/MenuItem"; import FormControl from "@mui/material/FormControl"; import Select from "@mui/material/Select"; import { useSetting, useSettingUpdate } from "../../hooks/Setting"; import { limitNumber } from "../../libs/utils"; import { useI18n } from "../../hooks/I18n"; import { UI_LANGS } from "../../config"; import { apiSyncAll } from "../../apis/data"; import { useCallback } from "react"; export default function Settings() { const i18n = useI18n(); const setting = useSetting(); const updateSetting = useSettingUpdate(); const handleSyncBlur = useCallback(async () => { try { await apiSyncAll(); } catch (err) { console.log("sync data", err); } }, []); if (!setting) { return; } const { uiLang, googleUrl, fetchLimit, openaiUrl, openaiKey, openaiModel, openaiPrompt, clearCache, syncUrl, syncKey, } = setting; return ( {i18n("ui_lang")} { updateSetting({ fetchLimit: limitNumber(e.target.value, 1, 10), }); }} /> {i18n("clear_cache")} { updateSetting({ googleUrl: e.target.value, }); }} /> { updateSetting({ openaiUrl: e.target.value, }); }} /> { updateSetting({ openaiKey: e.target.value, }); }} /> { updateSetting({ openaiModel: e.target.value, }); }} /> { updateSetting({ openaiPrompt: e.target.value, }); }} multiline minRows={2} maxRows={10} /> { updateSetting({ syncUrl: e.target.value, }); }} onBlur={handleSyncBlur} /> { updateSetting({ syncKey: e.target.value, }); }} onBlur={handleSyncBlur} /> ); }