Files
kiss-translator/src/views/Options/SyncSetting.js

62 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-07-31 15:08:51 +08:00
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
import TextField from "@mui/material/TextField";
import { useI18n } from "../../hooks/I18n";
import { useSync } from "../../hooks/Sync";
import Alert from "@mui/material/Alert";
import Link from "@mui/material/Link";
import { URL_KISS_WORKER } from "../../config";
2023-08-17 13:27:22 +08:00
import { debounce } from "../../libs/utils";
import { useMemo } from "react";
2023-07-31 15:08:51 +08:00
export default function SyncSetting() {
const i18n = useI18n();
const sync = useSync();
2023-08-17 13:27:22 +08:00
const handleChange = useMemo(
() =>
debounce((e) => {
e.preventDefault();
const { name, value } = e.target;
sync.update({
[name]: value,
});
}, 500),
[sync]
);
2023-07-31 15:08:51 +08:00
if (!sync.opt) {
return;
}
const { syncUrl, syncKey } = sync.opt;
return (
<Box>
<Stack spacing={3}>
<Alert severity="warning">{i18n("sync_warn")}</Alert>
<TextField
size="small"
label={i18n("data_sync_url")}
2023-08-17 13:27:22 +08:00
name="syncUrl"
2023-07-31 15:08:51 +08:00
defaultValue={syncUrl}
2023-08-17 13:27:22 +08:00
onChange={handleChange}
2023-07-31 15:08:51 +08:00
helperText={
<Link href={URL_KISS_WORKER}>{i18n("about_sync_api")}</Link>
}
/>
<TextField
size="small"
type="password"
label={i18n("data_sync_key")}
2023-08-17 13:27:22 +08:00
name="syncKey"
2023-07-31 15:08:51 +08:00
defaultValue={syncKey}
2023-08-17 13:27:22 +08:00
onChange={handleChange}
2023-07-31 15:08:51 +08:00
/>
</Stack>
</Box>
);
}