From 3b75bc1118cf1ee1dccb6a0235f892d4584afbab Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 22 Apr 2024 14:25:46 +0100 Subject: [PATCH 1/4] error boundary on gif picker --- src/components/dialogs/GifSelect.tsx | 38 +++++++++++++++++++++++++++- src/view/com/util/ErrorBoundary.tsx | 12 ++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/components/dialogs/GifSelect.tsx b/src/components/dialogs/GifSelect.tsx index baff31168b..926849dafc 100644 --- a/src/components/dialogs/GifSelect.tsx +++ b/src/components/dialogs/GifSelect.tsx @@ -13,6 +13,8 @@ import { useSetExternalEmbedPref, } from '#/state/preferences' import {Gif, useGifphySearch, useGiphyTrending} from '#/state/queries/giphy' +import {ErrorScreen} from '#/view/com/util/error/ErrorScreen' +import {ErrorBoundary} from '#/view/com/util/ErrorBoundary' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import * as Dialog from '#/components/Dialog' import * as TextField from '#/components/forms/TextField' @@ -54,13 +56,18 @@ export function GifSelectDialog({ break } + const renderErrorBoundary = useCallback( + (error: any) => , + [], + ) + return ( - {content} + {content} ) } @@ -357,3 +364,32 @@ function GiphyConsentPrompt({control}: {control: Dialog.DialogControlProps}) { ) } + +function DialogError({details}: {details?: string}) { + const {_} = useLingui() + const control = Dialog.useDialogContext() + + return ( + + + + + ) +} diff --git a/src/view/com/util/ErrorBoundary.tsx b/src/view/com/util/ErrorBoundary.tsx index 22fdd606e4..dccd2bbc9b 100644 --- a/src/view/com/util/ErrorBoundary.tsx +++ b/src/view/com/util/ErrorBoundary.tsx @@ -1,12 +1,14 @@ import React, {Component, ErrorInfo, ReactNode} from 'react' -import {ErrorScreen} from './error/ErrorScreen' -import {CenteredView} from './Views' import {msg} from '@lingui/macro' -import {logger} from '#/logger' import {useLingui} from '@lingui/react' +import {logger} from '#/logger' +import {ErrorScreen} from './error/ErrorScreen' +import {CenteredView} from './Views' + interface Props { children?: ReactNode + renderError?: (error: any) => ReactNode } interface State { @@ -30,6 +32,10 @@ export class ErrorBoundary extends Component { public render() { if (this.state.hasError) { + if (this.props.renderError) { + return this.props.renderError(this.state.error) + } + return ( From 5b815ff93092251db0d0efbabe8d6e46a2877809 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 22 Apr 2024 14:27:38 +0100 Subject: [PATCH 2/4] add dialog.close for web users --- src/components/dialogs/GifSelect.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/dialogs/GifSelect.tsx b/src/components/dialogs/GifSelect.tsx index 926849dafc..bdb4979832 100644 --- a/src/components/dialogs/GifSelect.tsx +++ b/src/components/dialogs/GifSelect.tsx @@ -373,6 +373,7 @@ function DialogError({details}: {details?: string}) { + Date: Mon, 22 Apr 2024 14:38:21 +0100 Subject: [PATCH 3/4] fix size of dialog on web --- src/components/dialogs/GifSelect.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/dialogs/GifSelect.tsx b/src/components/dialogs/GifSelect.tsx index bdb4979832..0d398259a0 100644 --- a/src/components/dialogs/GifSelect.tsx +++ b/src/components/dialogs/GifSelect.tsx @@ -370,9 +370,7 @@ function DialogError({details}: {details?: string}) { const control = Dialog.useDialogContext() return ( - + Date: Mon, 22 Apr 2024 21:51:54 +0100 Subject: [PATCH 4/4] Safer coercion --- src/components/dialogs/GifSelect.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/dialogs/GifSelect.tsx b/src/components/dialogs/GifSelect.tsx index 0d398259a0..ad4fbeadea 100644 --- a/src/components/dialogs/GifSelect.tsx +++ b/src/components/dialogs/GifSelect.tsx @@ -57,7 +57,7 @@ export function GifSelectDialog({ } const renderErrorBoundary = useCallback( - (error: any) => , + (error: any) => , [], )