Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit f5f5184

Browse files
committed
fix: closes #29
1 parent 9178273 commit f5f5184

File tree

8 files changed

+76
-8
lines changed

8 files changed

+76
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "timetabl-app",
3-
"version": "1.0.6-beta",
3+
"version": "1.0.7-beta",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/components/App/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ import Nav from "../Nav";
22
import { Outlet } from "react-router-dom";
33
import { Flex } from "@chakra-ui/react";
44
import { Box } from "@chakra-ui/react";
5+
import { ErrorBoundary } from "../ErrorBoundary";
56

67
export default () => {
78
return (
89
<Flex direction={"column"} width={"100vw"} maxW="full" height={"100vh"}>
910
<Nav />
1011
<Box mt={"100px"} />
1112
<Flex direction={"column"} w="full" h="full" maxH={"calc(100% - 100px)"}>
12-
<Outlet />
13+
<ErrorBoundary>
14+
<Outlet />
15+
</ErrorBoundary>
1316
</Flex>
1417
</Flex>
1518
);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
Flex,
3+
Alert,
4+
AlertIcon,
5+
AlertTitle,
6+
AlertDescription,
7+
} from "@chakra-ui/react";
8+
import { Component, ErrorInfo, ReactNode } from "react";
9+
10+
interface Props {
11+
children: ReactNode;
12+
}
13+
14+
interface State {
15+
hasError: boolean;
16+
}
17+
18+
export class ErrorBoundary extends Component<Props, State> {
19+
public state: State = {
20+
hasError: false,
21+
};
22+
23+
public static getDerivedStateFromError(): State {
24+
// Update state so the next render will show the fallback UI.
25+
return { hasError: true };
26+
}
27+
28+
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
29+
console.error("Uncaught error:", error, errorInfo);
30+
}
31+
32+
public render() {
33+
if (this.state.hasError) {
34+
return (
35+
<Flex>
36+
<Alert status="error" rounded={5} m={6}>
37+
<AlertIcon />
38+
<AlertTitle>An error occured.</AlertTitle>
39+
<AlertDescription>
40+
Check your console for more information.
41+
</AlertDescription>
42+
</Alert>
43+
</Flex>
44+
);
45+
}
46+
47+
return this.props.children;
48+
}
49+
}
50+
51+
export default ErrorBoundary;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ErrorBoundary } from "./ErrorBoundary";

src/main.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { inject } from "@vercel/analytics";
1919
import { log } from "./utils/log";
2020
import { UnauthorizedError } from "./errors/UnauthorisedError";
2121
import NetworkError from "./errors/NetworkError";
22+
import { ErrorBoundary } from "./components/ErrorBoundary";
2223

2324
// Redirect to new domain if using old domain
2425
if (window.location.host === "timetabl.vercel.app") {
@@ -100,9 +101,11 @@ ReactDOM.createRoot(document.getElementById("root")).render(
100101
]}
101102
>
102103
<ColorModeScript initialColorMode={themeGen().config.initialColorMode} />
103-
<BrowserRouter>
104-
<Routes />
105-
</BrowserRouter>
104+
<ErrorBoundary>
105+
<BrowserRouter>
106+
<Routes />
107+
</BrowserRouter>
108+
</ErrorBoundary>
106109
<ToastContainer />
107110
<ReactQueryDevtools initialIsOpen={false} />
108111
</Compose>

src/routes/Landing/Hero/Hero.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { motion } from "framer-motion";
99
import { SignIn } from "phosphor-react";
1010
import { lazy, Suspense, useState } from "react";
11+
import { ErrorBoundary } from "../../../components/ErrorBoundary";
1112
import { useAuth } from "../../../hooks/useAuth";
1213

1314
const HeroExperience = lazy(() => import("./HeroExperience"));
@@ -89,9 +90,12 @@ export const Hero = () => {
8990
position={"relative"}
9091
w={"full"}
9192
h="60vh"
93+
display={{ base: "none", md: "block" }}
9294
>
9395
<Suspense fallback={null}>
94-
<HeroExperience />
96+
<ErrorBoundary>
97+
<HeroExperience />
98+
</ErrorBoundary>
9599
</Suspense>
96100
</Flex>
97101
</Stack>

src/routes/Main/Main.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Outlet, useLocation, useNavigate } from "react-router-dom";
33
import { Flex, useBreakpointValue } from "@chakra-ui/react";
44
import { useAuth } from "../../hooks/useAuth";
55
import Sidebar from "../../components/Sidebar";
6+
import { ErrorBoundary } from "../../components/ErrorBoundary";
67

78
export default () => {
89
const { loggedIn, shouldRedirect } = useAuth();
@@ -37,7 +38,9 @@ export default () => {
3738
ml={{ base: 0, md: "144px" }}
3839
overflowY={"auto"}
3940
>
40-
<Outlet />
41+
<ErrorBoundary>
42+
<Outlet />
43+
</ErrorBoundary>
4144
</Flex>
4245
</Flex>
4346
);

src/routes/Main/Settings/Settings.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { Code, Gear, Info } from "phosphor-react";
99
import { Outlet, Link, useLocation } from "react-router-dom";
1010
import "@fontsource/poppins";
11+
import { ErrorBoundary } from "../../../components/ErrorBoundary";
1112

1213
const MenuEntry = ({
1314
active,
@@ -84,7 +85,9 @@ export default () => {
8485
mb={20}
8586
overflowY="auto"
8687
>
87-
<Outlet />
88+
<ErrorBoundary>
89+
<Outlet />
90+
</ErrorBoundary>
8891
</Flex>
8992
</Flex>
9093
);

0 commit comments

Comments
 (0)