Skip to content

Commit b44bfbe

Browse files
committed
Reduced code duplication of ErrorBoundary, wrapped PageLayout with ErrorBoundary.
1 parent 08eb005 commit b44bfbe

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/PageRouter.tsx

+5-25
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,11 @@ export const PageRouter = () => {
1717
const { activePage } = useDevice();
1818
return (
1919
<ErrorBoundary FallbackComponent={ErrorPage}>
20-
{activePage === "messages" && (
21-
<ErrorBoundary FallbackComponent={ErrorPage}>
22-
<MessagesPage />
23-
</ErrorBoundary>
24-
)}
25-
{activePage === "map" && (
26-
<ErrorBoundary FallbackComponent={ErrorPage}>
27-
<MapPage />
28-
</ErrorBoundary>
29-
)}
30-
{activePage === "config" && (
31-
<ErrorBoundary FallbackComponent={ErrorPage}>
32-
<ConfigPage />
33-
</ErrorBoundary>
34-
)}
35-
{activePage === "channels" && (
36-
<ErrorBoundary FallbackComponent={ErrorPage}>
37-
<ChannelsPage />
38-
</ErrorBoundary>
39-
)}
40-
{activePage === "nodes" && (
41-
<ErrorBoundary FallbackComponent={ErrorPage}>
42-
<NodesPage />
43-
</ErrorBoundary>
44-
)}
20+
{activePage === "messages" && <MessagesPage />}
21+
{activePage === "map" && <MapPage />}
22+
{activePage === "config" && <ConfigPage />}
23+
{activePage === "channels" && <ChannelsPage />}
24+
{activePage === "nodes" && <NodesPage />}
4525
</ErrorBoundary>
4626
);
4727
};

src/components/PageLayout.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { cn } from "@app/core/utils/cn.ts";
22
import { AlignLeftIcon, type LucideIcon } from "lucide-react";
3+
import { ErrorBoundary } from "react-error-boundary";
4+
import { ErrorPage } from "./UI/ErrorPage";
35
import Footer from "./UI/Footer";
46
import { Spinner } from "./UI/Spinner";
57

@@ -23,7 +25,7 @@ export const PageLayout = ({
2325
children,
2426
}: PageLayoutProps) => {
2527
return (
26-
<>
28+
<ErrorBoundary FallbackComponent={ErrorPage}>
2729
<div className="relative flex h-full w-full flex-col">
2830
<div className="flex h-14 shrink-0 border-b-[0.5px] border-slate-300 dark:border-slate-700 md:h-16 md:px-4">
2931
<button
@@ -68,6 +70,6 @@ export const PageLayout = ({
6870
<Footer />
6971
</div>
7072
</div>
71-
</>
73+
</ErrorBoundary>
7274
);
7375
};

0 commit comments

Comments
 (0)