@@ -12,13 +12,16 @@ import {
1212 type FC ,
1313 type ReactNode ,
1414 type SVGAttributes ,
15+ type ReactElement ,
1516} from "react" ;
1617import { useTranslation } from "react-i18next" ;
18+ import { logger } from "matrix-js-sdk/src/logger" ;
1719
1820import { RageshakeButton } from "./settings/RageshakeButton" ;
1921import styles from "./ErrorView.module.css" ;
2022import { useUrlParams } from "./UrlParams" ;
2123import { LinkButton } from "./button" ;
24+ import { ElementWidgetActions , type WidgetHelpers } from "./widget.ts" ;
2225
2326interface Props {
2427 Icon : ComponentType < SVGAttributes < SVGElement > > ;
@@ -35,6 +38,7 @@ interface Props {
3538 */
3639 fatal ?: boolean ;
3740 children : ReactNode ;
41+ widget : WidgetHelpers | null ;
3842}
3943
4044export const ErrorView : FC < Props > = ( {
@@ -43,6 +47,7 @@ export const ErrorView: FC<Props> = ({
4347 rageshake,
4448 fatal,
4549 children,
50+ widget,
4651} ) => {
4752 const { t } = useTranslation ( ) ;
4853 const { confineToRoom } = useUrlParams ( ) ;
@@ -51,6 +56,46 @@ export const ErrorView: FC<Props> = ({
5156 window . location . href = "/" ;
5257 } , [ ] ) ;
5358
59+ const CloseWidgetButton : FC < { widget : WidgetHelpers } > = ( {
60+ widget,
61+ } ) : ReactElement => {
62+ // in widget mode we don't want to show the return home button but a close button
63+ const closeWidget = ( ) : void => {
64+ widget . api . transport
65+ . send ( ElementWidgetActions . Close , { } )
66+ . catch ( ( e ) => {
67+ // What to do here?
68+ logger . error ( "Failed to send close action" , e ) ;
69+ } )
70+ . finally ( ( ) => {
71+ widget . api . transport . stop ( ) ;
72+ } ) ;
73+ } ;
74+ return (
75+ < Button kind = "primary" onClick = { closeWidget } >
76+ { t ( "action.close" ) }
77+ </ Button >
78+ ) ;
79+ } ;
80+
81+ // Whether the error is considered fatal or pathname is `/` then reload the all app.
82+ // If not then navigate to home page.
83+ const ReturnToHomeButton = ( ) : ReactElement => {
84+ if ( fatal || location . pathname === "/" ) {
85+ return (
86+ < Button kind = "tertiary" className = { styles . homeLink } onClick = { onReload } >
87+ { t ( "return_home_button" ) }
88+ </ Button >
89+ ) ;
90+ } else {
91+ return (
92+ < LinkButton kind = "tertiary" className = { styles . homeLink } to = "/" >
93+ { t ( "return_home_button" ) }
94+ </ LinkButton >
95+ ) ;
96+ }
97+ } ;
98+
5499 return (
55100 < div className = { styles . error } >
56101 < BigIcon className = { styles . icon } >
@@ -63,20 +108,11 @@ export const ErrorView: FC<Props> = ({
63108 { rageshake && (
64109 < RageshakeButton description = { `***Error View***: ${ title } ` } />
65110 ) }
66- { ! confineToRoom &&
67- ( fatal || location . pathname === "/" ? (
68- < Button
69- kind = "tertiary"
70- className = { styles . homeLink }
71- onClick = { onReload }
72- >
73- { t ( "return_home_button" ) }
74- </ Button >
75- ) : (
76- < LinkButton kind = "tertiary" className = { styles . homeLink } to = "/" >
77- { t ( "return_home_button" ) }
78- </ LinkButton >
79- ) ) }
111+ { widget ? (
112+ < CloseWidgetButton widget = { widget } />
113+ ) : (
114+ ! confineToRoom && < ReturnToHomeButton />
115+ ) }
80116 </ div >
81117 ) ;
82118} ;
0 commit comments