data sync

This commit is contained in:
Gabe Yuan
2023-07-31 03:10:09 +08:00
parent 497084fe8a
commit 2aef159d9d
12 changed files with 14333 additions and 9971 deletions

View File

@@ -9,12 +9,22 @@ 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;
}
@@ -28,6 +38,8 @@ export default function Settings() {
openaiModel,
openaiPrompt,
clearCache,
syncUrl,
syncKey,
} = setting;
return (
@@ -102,6 +114,7 @@ export default function Settings() {
<TextField
size="small"
type="password"
label={i18n("openai_key")}
defaultValue={openaiKey}
onChange={(e) => {
@@ -135,6 +148,31 @@ export default function Settings() {
minRows={2}
maxRows={10}
/>
<TextField
size="small"
label={i18n("data_sync_url")}
defaultValue={syncUrl}
onChange={(e) => {
updateSetting({
syncUrl: e.target.value,
});
}}
onBlur={handleSyncBlur}
/>
<TextField
size="small"
type="password"
label={i18n("data_sync_key")}
defaultValue={syncKey}
onChange={(e) => {
updateSetting({
syncKey: e.target.value,
});
}}
onBlur={handleSyncBlur}
/>
</Stack>
</Box>
);