Skip to content

Commit

Permalink
Upgrade from Material UI v5 to v6 (#1049)
Browse files Browse the repository at this point in the history
* chore: npm update to mui 6

* perf: prevent dark-mode SSR flickering using CSS variables

* refactor: remove color choice, make it automatically

* refactor: npx @mui/codemod@latest v6.0.0/system-props

* fix: RandomButton
  • Loading branch information
jy95 authored Nov 28, 2024
1 parent 3f1f0f8 commit de94719
Show file tree
Hide file tree
Showing 11 changed files with 437 additions and 743 deletions.
1,028 changes: 399 additions & 629 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"dependencies": {
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@mui/icons-material": "^5.16.6",
"@mui/material": "^5.16.7",
"@mui/icons-material": "^6.1.9",
"@mui/material": "^6.1.9",
"@mui/x-charts": "^8.0.0-alpha.1",
"@mui/x-data-grid": "^7.22.3",
"@mui/x-data-grid": "^8.0.0-alpha.1",
"@reduxjs/toolkit": "^2.3.0",
"@types/node": "^22.10.0",
"@types/react": "npm:types-react@rc",
Expand Down
13 changes: 7 additions & 6 deletions src/app/[locale]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export default function Error({

return (
<Box
display="flex"
flexDirection="column"
alignItems="center"
justifyContent="center"
height="80vh"
>
sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
height: "80vh"
}}>
<Typography variant="h4" gutterBottom>{t('title')}</Typography>
<Button variant="contained" color="primary" onClick={reset}>{t('retry')}</Button>
</Box>
Expand Down
15 changes: 8 additions & 7 deletions src/app/[locale]/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ export default function NotFoundPage() {

return (
<Box
display="flex"
flexDirection="column"
alignItems="center"
justifyContent="center"
height="80vh"
>
sx={{
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
height: "80vh"
}}>
<Typography variant="h4" gutterBottom>{t('title')}</Typography>
<Link href="/">
<Button variant="contained" color="primary">
{t('goGome')}
</Button>
</Link>
</Box>
)
);
}
12 changes: 10 additions & 2 deletions src/app/[locale]/planning/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,23 @@ export default function PlanningViewer() {
{
value: "RECORDED",
label: (
<Box display="flex" alignItems="center">
<Box
sx={{
display: "flex",
alignItems: "center"
}}>
<CheckCircleIcon />
</Box>
)
},
{
value: 'PENDING',
label: (
<Box display="flex" alignItems="center">
<Box
sx={{
display: "flex",
alignItems: "center"
}}>
<HourglassEmptyIcon />
</Box>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/GamesView/RandomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function RandomButton() {

return (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', marginTop: '10px' }}>
<Fab variant="extended" onClick={fetchRandomGame}>
<Fab color="primary" variant="extended" onClick={fetchRandomGame}>
<CasinoIcon sx={{ mr: 1 }} />
{ t("randomButtonLabel") }
</Fab>
Expand Down
20 changes: 0 additions & 20 deletions src/components/Menu/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ import {useTranslations} from 'next-intl';
import {CssBaseline, IconButton, Toolbar} from "@mui/material";
import MuiAppBar from '@mui/material/AppBar';
import MenuIcon from '@mui/icons-material/Menu';
import Switch from '@mui/material/Switch';
import { styled } from '@mui/material/styles';

// Icons for switch
import Brightness5Icon from '@mui/icons-material/Brightness5'; // sun
import Brightness4Icon from '@mui/icons-material/Brightness4'; // moon

// Icons for languages
import SvgIcon from '@mui/material/SvgIcon';
import Tooltip from '@mui/material/Tooltip';
Expand All @@ -27,7 +22,6 @@ import languages_with_icons from "./HeaderLanguages";

// Redux
import { drawerOpen } from "@/redux/features/miscellaneousSlice";
import { themeColor } from "@/redux/features/themeColorSlice";

// styled AppBar
const drawerWidth = 240;
Expand Down Expand Up @@ -58,17 +52,11 @@ function Header() {
const pathname = usePathname()
const dispatch = useAppDispatch();
const isdrawerOpen = useAppSelector((state) => state.miscellaneous.drawerOpen);
const currentColor = useAppSelector((state) => state.themeColor.currentColor);

const handleDrawerOpen = () => {
dispatch(drawerOpen(true));
};

const handleDarkMode = (event : any) => {
const color = (event.target.checked) ? "dark" : "light";
dispatch(themeColor({color, mode: "manual"}));
}

return (
<>
<CssBaseline />
Expand All @@ -90,14 +78,6 @@ function Header() {
>
<MenuIcon/>
</IconButton>
<Switch
checked={currentColor === "dark"}
onChange={handleDarkMode}
checkedIcon={<Brightness4Icon color="action" />}
icon={<Brightness5Icon style={{ color: '#ffeb3b' }}/>}
inputProps={{ 'aria-label': 'Mode' }}
color="default"
/>
<div style={{flexGrow: 1}}/>
<div>
{
Expand Down
6 changes: 5 additions & 1 deletion src/components/filters/platformsFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ type Props = {
function RenderEntry(props: Props) {
const {idx} = props;
return (
<Box display="flex" alignItems="center">
<Box
sx={{
display: "flex",
alignItems: "center"
}}>
<RenderPlatformIcon identifier={idx} />
</Box>
);
Expand Down
31 changes: 4 additions & 27 deletions src/providers/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,12 @@

import { createTheme, ThemeProvider as MUIThemeProvider } from '@mui/material/styles';

import { useAppDispatch, useAppSelector } from '@/redux/hooks';
import { selectCurrentColor, selectCurrentSystemColor, themeColor } from '@/redux/features/themeColorSlice';
import { useMediaQuery } from '@mui/material';
import { useEffect, useMemo } from 'react';
import { useMemo } from 'react';
import { useAsyncMemo } from '@/hooks/useAsyncMemo';


export function ThemeProvider({ children, lng }: { children: React.ReactNode, lng : string }) {

// for theme Color
const dispatch = useAppDispatch();
const currentColor = useAppSelector((state) => selectCurrentColor(state));
const currentSystemColor = useAppSelector((state) => selectCurrentSystemColor(state));
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
const systemColor = prefersDarkMode ? "dark" : "light";

// Two case handled here :
// 1) When user comes to the site and have different color that default
// 2) When user changes on the fly its preferred system color
useEffect(() => {
if (currentSystemColor !== systemColor) {
dispatch(themeColor({color: systemColor, mode: "auto"}));
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[currentSystemColor, currentColor]
);

// Prepare theme for possible darkmode
const muiLanguage = useAsyncMemo(async () => {
switch(lng) {
Expand All @@ -45,11 +23,10 @@ export function ThemeProvider({ children, lng }: { children: React.ReactNode, ln
const theme = useMemo(
() =>
createTheme({
palette: {
mode: currentColor,
},
colorSchemes: { dark: true },
cssVariables: true
}, muiLanguage),
[muiLanguage, currentColor],
[muiLanguage],
);

return (
Expand Down
2 changes: 0 additions & 2 deletions src/redux/Store.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { configureStore } from "@reduxjs/toolkit";

import games from "./features/gamesSlice";
import themeColor from "./features/themeColorSlice";
import miscellaneous from "./features/miscellaneousSlice";
import { gamesAPI } from "./services/gamesAPI";
import { planningAPI } from "./services/planningAPI";
Expand All @@ -18,7 +17,6 @@ const store = configureStore({
reducer: {
// common reducers
games,
themeColor,
miscellaneous,
// API calls
[gamesAPI.reducerPath]: gamesAPI.reducer,
Expand Down
45 changes: 0 additions & 45 deletions src/redux/features/themeColorSlice.tsx

This file was deleted.

0 comments on commit de94719

Please sign in to comment.