mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update data initial requests (#538)
This commit is contained in:
@ -2,49 +2,43 @@ import { CssVarsProvider } from "@mui/joy/styles";
|
||||
import { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { RouterProvider } from "react-router-dom";
|
||||
import { globalService, locationService } from "./services";
|
||||
import { locationService } from "./services";
|
||||
import { useAppSelector } from "./store";
|
||||
import router from "./router";
|
||||
import * as api from "./helpers/api";
|
||||
import * as storage from "./helpers/storage";
|
||||
|
||||
function App() {
|
||||
const { i18n } = useTranslation();
|
||||
const global = useAppSelector((state) => state.global);
|
||||
const { locale, systemStatus } = useAppSelector((state) => state.global);
|
||||
|
||||
useEffect(() => {
|
||||
locationService.updateStateWithLocation();
|
||||
window.onpopstate = () => {
|
||||
locationService.updateStateWithLocation();
|
||||
};
|
||||
|
||||
globalService.initialState();
|
||||
}, []);
|
||||
|
||||
// Inject additional style and script codes.
|
||||
useEffect(() => {
|
||||
api.getSystemStatus().then(({ data }) => {
|
||||
const { data: status } = data;
|
||||
if (status.additionalStyle) {
|
||||
const styleEl = document.createElement("style");
|
||||
styleEl.innerHTML = status.additionalStyle;
|
||||
styleEl.setAttribute("type", "text/css");
|
||||
document.head.appendChild(styleEl);
|
||||
}
|
||||
if (status.additionalScript) {
|
||||
const scriptEl = document.createElement("script");
|
||||
scriptEl.innerHTML = status.additionalScript;
|
||||
document.head.appendChild(scriptEl);
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
if (systemStatus.additionalStyle) {
|
||||
const styleEl = document.createElement("style");
|
||||
styleEl.innerHTML = systemStatus.additionalStyle;
|
||||
styleEl.setAttribute("type", "text/css");
|
||||
document.head.appendChild(styleEl);
|
||||
}
|
||||
if (systemStatus.additionalScript) {
|
||||
const scriptEl = document.createElement("script");
|
||||
scriptEl.innerHTML = systemStatus.additionalScript;
|
||||
document.head.appendChild(scriptEl);
|
||||
}
|
||||
}, [systemStatus]);
|
||||
|
||||
useEffect(() => {
|
||||
i18n.changeLanguage(global.locale);
|
||||
i18n.changeLanguage(locale);
|
||||
storage.set({
|
||||
locale: global.locale,
|
||||
locale: locale,
|
||||
});
|
||||
}, [global.locale]);
|
||||
}, [locale]);
|
||||
|
||||
return (
|
||||
<CssVarsProvider>
|
||||
|
Reference in New Issue
Block a user