fix sync webfix

This commit is contained in:
Gabe Yuan
2023-09-10 15:04:41 +08:00
parent 399c6b6fed
commit 1ef9974c05

View File

@@ -1,6 +1,6 @@
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import { useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { useI18n } from "../../hooks/I18n"; import { useI18n } from "../../hooks/I18n";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Accordion from "@mui/material/Accordion"; import Accordion from "@mui/material/Accordion";
@@ -75,11 +75,17 @@ export default function Webfix() {
const alert = useAlert(); const alert = useAlert();
const { setting, updateSetting } = useSetting(); const { setting, updateSetting } = useSetting();
const loadSites = useCallback(async () => {
const sites = await loadOrFetchWebfix(process.env.REACT_APP_WEBFIXURL);
setSites(sites);
}, []);
const handleSyncTest = async (e) => { const handleSyncTest = async (e) => {
e.preventDefault(); e.preventDefault();
try { try {
setLoading(true); setLoading(true);
await syncWebfix(process.env.REACT_APP_WEBFIXURL); await syncWebfix(process.env.REACT_APP_WEBFIXURL);
await loadSites();
alert.success(i18n("sync_success")); alert.success(i18n("sync_success"));
} catch (err) { } catch (err) {
console.log("[sync webfix]", err); console.log("[sync webfix]", err);
@@ -93,15 +99,14 @@ export default function Webfix() {
(async () => { (async () => {
try { try {
setLoading(true); setLoading(true);
const sites = await loadOrFetchWebfix(process.env.REACT_APP_WEBFIXURL); await loadSites();
setSites(sites);
} catch (err) { } catch (err) {
console.log("[load webfix]", err.message); console.log("[load webfix]", err.message);
} finally { } finally {
setLoading(false); setLoading(false);
} }
})(); })();
}, []); }, [loadSites]);
return ( return (
<Box> <Box>