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
+111 -14

No files matched your search

+24 -7
View File
@@ -101,6 +101,8 @@ import { CircularProgress } from "@mui/material";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { useCentralStore } from "./utils/store/central.js";
import { useSnackbar } from "notistack";
import { ErrorBoundary } from "react-error-boundary";
import { ErrorNotice } from "./components/notices/errorNotice/errorNotice.jsx";
const anim = {
initial: {
@@ -457,6 +459,7 @@ function App() {
<SideMenu />
<AppBar />
<AudioPlayer key={audioPlayerVisible} />
<ErrorBoundary FallbackComponent={ErrorNotice}>
<Routes location={location}>
{/* <Route
// key={location.key}
@@ -465,7 +468,9 @@ function App() {
<Route
path="/"
exact
element={<Navigate to={initialRoute} />}
element={
<Navigate to={initialRoute} />
}
// element={<></>}
/>
<Route
@@ -479,12 +484,15 @@ function App() {
maxWidth="md"
>
<DialogTitle id="alert-dialog-text">
Unable to reach server
Unable to reach
server
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-desc">
Unable to connect to
the jellyfin server.
Unable to
connect to the
jellyfin
server.
</DialogContentText>
</DialogContent>
<DialogActions>
@@ -503,7 +511,8 @@ function App() {
handleRelaunch
}
>
Restart JellyPlayer
Restart
JellyPlayer
</Button>
</DialogActions>
</Dialog>
@@ -515,7 +524,10 @@ function App() {
element={<LoginRoute />}
/>
<Route path="/home" element={<Home />} />
<Route
path="/home"
element={<Home />}
/>
<Route
path="/setup/server"
element={<ServerSetup />}
@@ -550,6 +562,7 @@ function App() {
exact
path="/musicalbum/:id"
element={<MusicAlbumTitlePage />}
errorElement={<div>Error</div>}
/>
<Route
exact
@@ -592,13 +605,17 @@ function App() {
path="/settings"
element={<Settings />}
/>
<Route path="/about" element={<About />} />
<Route
path="/about"
element={<About />}
/>
<Route
path="/player"
element={<VideoPlayer />}
/>
{/* </Route> */}
</Routes>
</ErrorBoundary>
</div>
<ReactQueryDevtools buttonPosition="bottom-left" />
</ThemeProvider>
+1
View File
@@ -75,6 +75,7 @@ const LikeButton = ({
opacity: mutation.isPending ? 1 : 0,
transition: "opacity 200ms",
}}
thickness={2}
/>
<IconButton
onClick={(e) => {
@@ -67,6 +67,7 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
opacity: mutation.isPending ? 1 : 0,
transition: "opacity 200ms",
}}
thickness={2}
/>
<IconButton
onClick={(e) => {
+1
View File
@@ -17,6 +17,7 @@ class ErrorBoundary extends React.Component {
// in ErrorBoundary (created by App)
// in div (created by App)
// in App
this.setState;
console.error(`Err in ${info} - ${error}`);
}
+1 -1
View File
@@ -327,7 +327,7 @@ const Hero = ({
}}
/>
)}
{!!videoTracks[0].VideoRangeType && (
{!!videoTracks[0]?.VideoRangeType && (
<Chip
variant="filled"
label={
@@ -1,10 +1,12 @@
/** @format */
import React from "react";
import Box from "@mui/material/Box";
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 (
<Box
sx={{
@@ -14,11 +16,51 @@ export const ErrorNotice = () => {
justifyContent: "center",
alignItems: "center",
flexFlow: "column",
opacity: 0.2,
// opacity: 0.2,
}}
>
<MdiEmoticonDead sx={{ fontSize: 200 }} />
<Typography variant="h3">Something went wrong</Typography>
<div
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>
);
};
+35
View File
@@ -168,3 +168,38 @@ h1 {
.MuiListItemIcon-root {
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);
}
}