Skip to content

Commit

Permalink
Merge branch 'main' into initial-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
barroco authored Sep 12, 2023
2 parents c03f533 + ed05039 commit f8226d7
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 372 deletions.
97 changes: 0 additions & 97 deletions reports/src/App.css

This file was deleted.

14 changes: 9 additions & 5 deletions reports/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { RouterProvider, createHashRouter } from "react-router-dom";
import { useReport } from "./capability/useReport";
import "./App.css";
import { CustomThemeProvider } from "./ThemeContext";

function App() {
// FIXME use the report from the config
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const configuration = JSON.parse(document.getElementById("interuss_report_json")?.innerHTML || "{}");
const configuration = JSON.parse(
document.getElementById("interuss_report_json")?.innerHTML || "{}"
);
console.log("Configuration:", configuration);

const { loading, error, report, nav } = useReport(configuration);
Expand All @@ -16,7 +16,11 @@ function App() {
return !error ? <div>Report not found</div> : <div>{error}</div>;
}
const router = createHashRouter(nav);
return <RouterProvider router={router} />;
return (
<CustomThemeProvider>
<RouterProvider router={router} />
</CustomThemeProvider>
);
}

export default App;
87 changes: 87 additions & 0 deletions reports/src/ThemeContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
CssBaseline,
GlobalStyles,
Interpolation,
PaletteMode,
Theme,
ThemeProvider,
createTheme,
useMediaQuery,
} from "@mui/material";
import {
PropsWithChildren,
createContext,
useContext,
useEffect,
useMemo,
useState,
} from "react";

type ThemeContextProps = {
toggleColorMode: () => void;
colorMode: PaletteMode;
};
export const ThemeContext = createContext<ThemeContextProps>({
toggleColorMode: () => {},
colorMode: "light",
});

export const useTheme = () => useContext(ThemeContext);

export const CustomThemeProvider = ({
children,
}: PropsWithChildren<unknown>) => {
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");

const [mode, setMode] = useState<PaletteMode>("light");

useEffect(
() => setMode(prefersDarkMode ? "dark" : "light"),
[prefersDarkMode]
);

const theme = useMemo(
() =>
createTheme({
palette: {
mode,
},
components: {
MuiChip: {
styleOverrides: {
root: {
borderRadius: 8,
},
},
},
},
}),
[mode]
);

const globalStyles: Interpolation<Theme> = (theme) => {
return {
body: {
backgroundColor:
theme.palette.mode === "light"
? theme.palette.grey[100]
: theme.palette.grey[900],
},
};
};

const toggleColorMode = () =>
setMode((prevMode: PaletteMode) =>
prevMode === "light" ? "dark" : "light"
);

return (
<ThemeContext.Provider value={{ toggleColorMode, colorMode: mode }}>
<ThemeProvider theme={theme}>
<CssBaseline />
<GlobalStyles styles={globalStyles} />
{children}
</ThemeProvider>
</ThemeContext.Provider>
);
};
Loading

0 comments on commit f8226d7

Please sign in to comment.