From 2c5c7f4b05f01d9c55281f56ca76058a979113ad Mon Sep 17 00:00:00 2001 From: Sebastian Nowak Date: Sun, 8 Dec 2024 18:07:24 +0100 Subject: [PATCH 01/15] 221: Add basic error boundries --- frontend/package-lock.json | 12 ++++++++++++ frontend/package.json | 3 ++- .../src/components/fallbacks/MainFallback.tsx | 9 +++++++++ .../fallbacks/RateLimitStatusFallback.tsx | 16 ++++++++++++++++ frontend/src/components/navbar/Navbar.tsx | 12 +++++++----- frontend/src/main.tsx | 10 +++++++--- 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 frontend/src/components/fallbacks/MainFallback.tsx create mode 100644 frontend/src/components/fallbacks/RateLimitStatusFallback.tsx diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 45835017..66343f98 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -28,6 +28,7 @@ "prettier": "^3.3.3", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-error-boundary": "^4.1.2", "react-icons": "^5.3.0", "react-router-dom": "^6.26.2", "recharts": "^2.13.3", @@ -5460,6 +5461,17 @@ "react": "^18.3.1" } }, + "node_modules/react-error-boundary": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-4.1.2.tgz", + "integrity": "sha512-GQDxZ5Jd+Aq/qUxbCm1UtzmL/s++V7zKgE8yMktJiCQXCCFZnMZh9ng+6/Ne6PjNSXH0L9CjeOEREfRnq6Duag==", + "dependencies": { + "@babel/runtime": "^7.12.5" + }, + "peerDependencies": { + "react": ">=16.13.1" + } + }, "node_modules/react-icons": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.3.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index b4de7d5c..9c58e8c4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -31,11 +31,12 @@ "framer-motion": "^11.9.0", "jotai": "^2.10.0", "js-cookie": "^3.0.5", - "mantine-form-zod-resolver": "^1.1.0", "jwt-decode": "^4.0.0", + "mantine-form-zod-resolver": "^1.1.0", "prettier": "^3.3.3", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-error-boundary": "^4.1.2", "react-icons": "^5.3.0", "react-router-dom": "^6.26.2", "recharts": "^2.13.3", diff --git a/frontend/src/components/fallbacks/MainFallback.tsx b/frontend/src/components/fallbacks/MainFallback.tsx new file mode 100644 index 00000000..baa57482 --- /dev/null +++ b/frontend/src/components/fallbacks/MainFallback.tsx @@ -0,0 +1,9 @@ +import React from 'react'; + +export const MainFallback = () => { + return ( +
+

MainFallback

+
+ ); +}; diff --git a/frontend/src/components/fallbacks/RateLimitStatusFallback.tsx b/frontend/src/components/fallbacks/RateLimitStatusFallback.tsx new file mode 100644 index 00000000..5932b9a0 --- /dev/null +++ b/frontend/src/components/fallbacks/RateLimitStatusFallback.tsx @@ -0,0 +1,16 @@ +import { HoverCard } from '@mantine/core'; +import { IconBrandReddit } from '@tabler/icons-react'; +import React from 'react'; + +export const RateLimitStatusFallback = () => { + return ( + + + + + + Error occurred while fetching rate limit status + + + ); +}; diff --git a/frontend/src/components/navbar/Navbar.tsx b/frontend/src/components/navbar/Navbar.tsx index 49f90af4..8d6b9e70 100644 --- a/frontend/src/components/navbar/Navbar.tsx +++ b/frontend/src/components/navbar/Navbar.tsx @@ -3,6 +3,8 @@ import ThemeSwitch from './ThemeSwitch'; import { Anchor, Card, Flex, Group } from '@mantine/core'; import StatusIndicator from './StatusIndicator'; import RateLimitStatus from './RateLimitStatus.tsx'; +import { ErrorBoundary } from 'react-error-boundary'; +import { RateLimitStatusFallback } from '../fallbacks/RateLimitStatusFallback.tsx'; const LeftNavItems = () => { return ( @@ -17,7 +19,9 @@ const LeftNavItems = () => { const RightNavItems = () => { return ( - + }> + + @@ -30,11 +34,9 @@ const RightNavItems = () => { */ const Navbar = () => { return ( - +