Update ErrorNotice and add route level errorBoundary

This commit is contained in:
Prayag Prajapati committed 2023-12-12 20:29:16 +05:30
1 parent 5799031a34
commit c5922d67c4
7 files changed
+242 -145

No files matched your search

+155 -138
View File
@@ -101,6 +101,8 @@ import { CircularProgress } from "@mui/material";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { useCentralStore } from "./utils/store/central.js"; import { useCentralStore } from "./utils/store/central.js";
import { useSnackbar } from "notistack"; import { useSnackbar } from "notistack";
import { ErrorBoundary } from "react-error-boundary";
import { ErrorNotice } from "./components/notices/errorNotice/errorNotice.jsx";
const anim = { const anim = {
initial: { initial: {
@@ -457,148 +459,163 @@ function App() {
<SideMenu /> <SideMenu />
<AppBar /> <AppBar />
<AudioPlayer key={audioPlayerVisible} /> <AudioPlayer key={audioPlayerVisible} />
<Routes location={location}> <ErrorBoundary FallbackComponent={ErrorNotice}>
{/* <Route <Routes location={location}>
{/* <Route
// key={location.key} // key={location.key}
element={<AnimationWrapper />} element={<AnimationWrapper />}
> */} > */}
<Route <Route
path="/" path="/"
exact exact
element={<Navigate to={initialRoute} />} element={
// element={<></>} <Navigate to={initialRoute} />
/> }
<Route // element={<></>}
path="/error" />
element={ <Route
<Dialog path="/error"
open element={
onClose={handleRelaunch} <Dialog
aria-labelledby="alert-dialog-text" open
aria-describedby="alert-dialog-desc" onClose={handleRelaunch}
maxWidth="md" aria-labelledby="alert-dialog-text"
> aria-describedby="alert-dialog-desc"
<DialogTitle id="alert-dialog-text"> maxWidth="md"
Unable to reach server >
</DialogTitle> <DialogTitle id="alert-dialog-text">
<DialogContent> Unable to reach
<DialogContentText id="alert-dialog-desc"> server
Unable to connect to </DialogTitle>
the jellyfin server. <DialogContent>
</DialogContentText> <DialogContentText id="alert-dialog-desc">
</DialogContent> Unable to
<DialogActions> connect to the
<Button jellyfin
onClick={() => server.
navigate( </DialogContentText>
"/servers/list", </DialogContent>
) <DialogActions>
} <Button
> onClick={() =>
Change Server navigate(
</Button> "/servers/list",
<Button )
variant="outlined" }
onClick={ >
handleRelaunch Change Server
} </Button>
> <Button
Restart JellyPlayer variant="outlined"
</Button> onClick={
</DialogActions> handleRelaunch
</Dialog> }
} >
/> Restart
<Route JellyPlayer
path="/login/index" </Button>
exact </DialogActions>
element={<LoginRoute />} </Dialog>
/> }
/>
<Route
path="/login/index"
exact
element={<LoginRoute />}
/>
<Route path="/home" element={<Home />} /> <Route
<Route path="/home"
path="/setup/server" element={<Home />}
element={<ServerSetup />} />
/> <Route
<Route path="/setup/server"
path="/servers/list" element={<ServerSetup />}
element={<ServerList />} />
/> <Route
<Route path="/servers/list"
path="/login/withImg/:userName/:userId/" element={<ServerList />}
element={<LoginWithImage />} />
/> <Route
<Route path="/login/withImg/:userName/:userId/"
path="/login/users" element={<LoginWithImage />}
element={<UserLogin />} />
/> <Route
<Route path="/login/users"
path="/login/manual" element={<UserLogin />}
element={<UserLoginManual />} />
/> <Route
<Route path="/login/manual"
exact element={<UserLoginManual />}
path="/library/:id" />
element={<LibraryView />} <Route
/> exact
<Route path="/library/:id"
exact element={<LibraryView />}
path="/item/:id" />
element={<ItemDetail />} <Route
/> exact
<Route path="/item/:id"
exact element={<ItemDetail />}
path="/musicalbum/:id" />
element={<MusicAlbumTitlePage />} <Route
/> exact
<Route path="/musicalbum/:id"
exact element={<MusicAlbumTitlePage />}
path="/artist/:id" errorElement={<div>Error</div>}
element={<ArtistTitlePage />} />
/> <Route
<Route exact
exact path="/artist/:id"
path="/boxset/:id" element={<ArtistTitlePage />}
element={<BoxSetTitlePage />} />
/> <Route
<Route exact
exact path="/boxset/:id"
path="/episode/:id" element={<BoxSetTitlePage />}
element={<EpisodeTitlePage />} />
/> <Route
<Route exact
exact path="/episode/:id"
path="/person/:id" element={<EpisodeTitlePage />}
element={<PersonTitlePage />} />
/> <Route
<Route exact
exact path="/person/:id"
path="/playlist/:id" element={<PersonTitlePage />}
element={<PlaylistTitlePage />} />
/> <Route
<Route exact
path="/series/:id" path="/playlist/:id"
element={<SeriesTitlePage />} element={<PlaylistTitlePage />}
/> />
<Route <Route
path="/search" path="/series/:id"
element={<SearchPage />} element={<SeriesTitlePage />}
/> />
<Route <Route
path="/favorite" path="/search"
element={<FavoritePage />} element={<SearchPage />}
/> />
<Route <Route
path="/settings" path="/favorite"
element={<Settings />} element={<FavoritePage />}
/> />
<Route path="/about" element={<About />} /> <Route
<Route path="/settings"
path="/player" element={<Settings />}
element={<VideoPlayer />} />
/> <Route
{/* </Route> */} path="/about"
</Routes> element={<About />}
/>
<Route
path="/player"
element={<VideoPlayer />}
/>
{/* </Route> */}
</Routes>
</ErrorBoundary>
</div> </div>
<ReactQueryDevtools buttonPosition="bottom-left" /> <ReactQueryDevtools buttonPosition="bottom-left" />
</ThemeProvider> </ThemeProvider>
+1
View File
@@ -75,6 +75,7 @@ const LikeButton = ({
opacity: mutation.isPending ? 1 : 0, opacity: mutation.isPending ? 1 : 0,
transition: "opacity 200ms", transition: "opacity 200ms",
}} }}
thickness={2}
/> />
<IconButton <IconButton
onClick={(e) => { onClick={(e) => {
@@ -67,6 +67,7 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
opacity: mutation.isPending ? 1 : 0, opacity: mutation.isPending ? 1 : 0,
transition: "opacity 200ms", transition: "opacity 200ms",
}} }}
thickness={2}
/> />
<IconButton <IconButton
onClick={(e) => { onClick={(e) => {
+1
View File
@@ -17,6 +17,7 @@ class ErrorBoundary extends React.Component {
// in ErrorBoundary (created by App) // in ErrorBoundary (created by App)
// in div (created by App) // in div (created by App)
// in App // in App
this.setState;
console.error(`Err in ${info} - ${error}`); console.error(`Err in ${info} - ${error}`);
} }
+1 -1
View File
@@ -327,7 +327,7 @@ const Hero = ({
}} }}
/> />
)} )}
{!!videoTracks[0].VideoRangeType && ( {!!videoTracks[0]?.VideoRangeType && (
<Chip <Chip
variant="filled" variant="filled"
label={ label={
@@ -1,10 +1,12 @@
/** @format */ /** @format */
import React from "react";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import { MdiEmoticonDead } from "../../icons/mdiEmoticonDead"; import Button from "@mui/material/Button";
import { red } from "@mui/material/colors";
export const ErrorNotice = () => { export const ErrorNotice = ({ error, resetErrorBoundary }) => {
console.error(error);
return ( return (
<Box <Box
sx={{ sx={{
@@ -14,11 +16,51 @@ export const ErrorNotice = () => {
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
flexFlow: "column", flexFlow: "column",
opacity: 0.2, // opacity: 0.2,
}} }}
> >
<MdiEmoticonDead sx={{ fontSize: 200 }} /> <div
<Typography variant="h3">Something went wrong</Typography> className="material-symbols-rounded animate-icon"
style={{
fontSize: "10em",
color: red[800],
}}
>
error
</div>
<Typography
variant="h3"
fontFamily="JetBrains Mono Variable"
fontWeight={100}
>
Something went wrong
</Typography>
<Typography
fontFamily="JetBrains Mono Variable"
fontWeight={100}
variant="h5"
style={{
padding: "0.5em",
background: "rgb(0 0 0 / 1)",
borderRadius: "8px",
border: "2px dashed rgb(255 255 255 / 0.5)",
maxWidth: "40em",
marginTop: "1em",
// opacity: 0.6,
}}
>
{error.message}
</Typography>
<Button
size="large"
variant="contained"
onClick={resetErrorBoundary ? resetErrorBoundary : () => {}}
style={{
marginTop: "1em",
}}
>
Retry
</Button>
</Box> </Box>
); );
}; };
+35
View File
@@ -168,3 +168,38 @@ h1 {
.MuiListItemIcon-root { .MuiListItemIcon-root {
font-size: 24px; font-size: 24px;
} }
.animate-icon {
position: relative;
&::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(1);
width: 100%;
height: 100%;
border-radius: 100%;
opacity: 0;
filter: blur(10px);
animation: iconAnimation cubic-bezier(0.175, 0.885, 0.32, 1.275) 3s
infinite;
background: rgb(255 0 0 / 0.1);
}
}
@keyframes iconAnimation {
0% {
opacity: 0;
transform: translate(-50%, -50%) scale(1);
}
60% {
opacity: 1;
transform: translate(-50%, -50%) scale(4);
}
100% {
opacity: 0;
transform: translate(-50%, -50%) scale(4);
}
}