imeeting/frontend/src/App.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from "react";
import AppRoutes from "./routes";
import { getOpenPlatformConfig } from "./api";
import type { SysPlatformConfig } from "./types";
export default function App() {
const [config, setConfig] = useState<SysPlatformConfig | null>(null);
useEffect(() => {
const fetchConfig = async () => {
try {
const data = await getOpenPlatformConfig();
setConfig(data);
if (data.projectName) {
document.title = data.projectName;
}
if (data.iconUrl) {
let link: HTMLLinkElement | null = document.querySelector("link[rel~='icon']");
if (!link) {
link = document.createElement('link');
link.rel = 'icon';
document.getElementsByTagName('head')[0].appendChild(link);
}
link.href = data.iconUrl;
}
// Save to sessionStorage for other components
sessionStorage.setItem("platformConfig", JSON.stringify(data));
} catch (e) {
console.error("Failed to load platform config", e);
}
};
fetchConfig();
}, []);
return <AppRoutes />;
}