-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: deal with misc todo comments in frontend #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { atom, getDefaultStore } from 'jotai'; | ||
|
|
||
| export interface ErrorBannerMessage { | ||
| readonly id: number; | ||
| readonly message: string; | ||
| } | ||
|
|
||
| export const errorBannerMessagesAtom = atom<ErrorBannerMessage[]>([]); | ||
|
|
||
| let nextId = 0; | ||
|
|
||
| /** | ||
| * Queues a dismissible global error banner (`ErrorBanner`, mounted in `Providers`). Called from outside React | ||
| * (`queryClient.ts`'s `QueryCache.onError`), hence writing through jotai's default store rather than a hook. | ||
| */ | ||
| export function pushErrorBanner(message: string): void { | ||
| const id = nextId++; | ||
| getDefaultStore().set(errorBannerMessagesAtom, (prev) => [...prev, { id, message }]); | ||
| } | ||
|
|
||
| export function dismissErrorBanner(id: number): void { | ||
| getDefaultStore().set(errorBannerMessagesAtom, (prev) => prev.filter((banner) => banner.id !== id)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| 'use client'; | ||
|
|
||
| import { useAtomValue } from 'jotai'; | ||
| import { useEffect } from 'react'; | ||
| import { FaExclamationTriangle, FaTimes } from 'react-icons/fa'; | ||
| import { dismissErrorBanner, errorBannerMessagesAtom } from '@/api/errorBanner'; | ||
|
|
||
| const AUTO_DISMISS_MS = 8_000; | ||
|
|
||
| function Banner({ id, message }: { readonly id: number; readonly message: string }) { | ||
| useEffect(() => { | ||
| const timeout = setTimeout(() => dismissErrorBanner(id), AUTO_DISMISS_MS); | ||
| return () => clearTimeout(timeout); | ||
| }, [id]); | ||
|
|
||
| return ( | ||
| <div className="flex items-center gap-3 rounded-lg border-[1px] border-misc-danger bg-card p-3 shadow-lg dark:bg-card-dark"> | ||
| <FaExclamationTriangle className="h-4 w-4 shrink-0 text-misc-danger" /> | ||
| <p className="text-sm text-primary dark:text-primary-dark">{message}</p> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| <button | ||
| aria-label="Dismiss" | ||
| className="ml-auto text-secondary hover:text-primary dark:text-secondary-dark dark:hover:text-primary-dark" | ||
| onClick={() => dismissErrorBanner(id)} | ||
| type="button" | ||
| > | ||
| <FaTimes className="h-3.5 w-3.5" /> | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Surfaces background query failures (a refetch that failed while stale data is still on screen — see | ||
| * `queryClient.ts`'s `onError`). First-load errors are handled locally by `UserErrorHandler` instead, so this | ||
| * only needs to catch the "user is already looking at data and something broke quietly" case. | ||
| */ | ||
| export function ErrorBanner() { | ||
| const banners = useAtomValue(errorBannerMessagesAtom); | ||
|
|
||
| if (banners.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="fixed bottom-4 right-4 z-50 flex w-full max-w-sm flex-col gap-2"> | ||
| {banners.map((banner) => ( | ||
| <Banner id={banner.id} key={banner.id} message={banner.message} /> | ||
| ))} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,25 @@ | ||
| import { FaExclamationTriangle } from 'react-icons/fa'; | ||
| import { LoginButton } from './LoginButton'; | ||
| import { APIError } from '@/api/error'; | ||
|
|
||
| // TODO? | ||
| /** | ||
| * Handles the first-load error state for `useMe()` consumers (`NavGateProvider`, `UserDesktop`, `UserMobile`) — | ||
| * no cached user data exists yet, so there's nothing to keep showing underneath. Background refetch failures | ||
| * (data already on screen) go through the global `ErrorBanner` instead (see `queryClient.ts`'s `onError`). | ||
| */ | ||
| export function UserErrorHandler({ error }: { readonly error: Error }) { | ||
| if (error instanceof APIError && error.statusCode === 401) { | ||
| return <LoginButton />; | ||
| } | ||
|
|
||
| console.error(error); | ||
| return <>Error</>; | ||
| return ( | ||
| <div className="flex w-full flex-col items-center gap-2 rounded-lg border-[1px] border-misc-danger bg-card p-8 text-center dark:bg-card-dark"> | ||
| <FaExclamationTriangle className="h-8 w-8 text-misc-danger" /> | ||
| <p className="text-lg font-medium text-primary dark:text-primary-dark">Something went wrong</p> | ||
| <p className="text-sm text-secondary dark:text-secondary-dark"> | ||
| {error instanceof APIError ? error.message : 'Please try refreshing the page.'} | ||
| </p> | ||
| </div> | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.