fix(dev): proxy api during react development
This commit is contained in:
parent
b1d196e4ca
commit
b8e39348e8
11 changed files with 196 additions and 8 deletions
36
src/App.tsx
36
src/App.tsx
|
|
@ -49,10 +49,46 @@ export function AppStateView({
|
|||
);
|
||||
}
|
||||
|
||||
export function resolveDocumentMetadata(dashboard: DashboardRuntimeState): {
|
||||
description: string;
|
||||
title: string;
|
||||
} {
|
||||
if (dashboard.state === "ready") {
|
||||
const uiDashboard = dashboardDocumentToUiDashboard(dashboard.document);
|
||||
return {
|
||||
title: uiDashboard.title,
|
||||
description:
|
||||
uiDashboard.subtitle ||
|
||||
dashboard.document.metadata.description ||
|
||||
uiDashboard.title,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
title: dashboard.title,
|
||||
description: dashboard.subtitle || dashboard.message,
|
||||
};
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [dashboard, setDashboard] =
|
||||
useState<DashboardRuntimeState>(loadingDashboardState);
|
||||
|
||||
useEffect(() => {
|
||||
const metadata = resolveDocumentMetadata(dashboard);
|
||||
document.title = metadata.title;
|
||||
|
||||
let description = document.querySelector<HTMLMetaElement>(
|
||||
'meta[name="description"]',
|
||||
);
|
||||
if (!description) {
|
||||
description = document.createElement("meta");
|
||||
description.name = "description";
|
||||
document.head.append(description);
|
||||
}
|
||||
description.content = metadata.description;
|
||||
}, [dashboard]);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
let refreshTimer: number | undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue