Skip to content

Commit

Permalink
fix: decrypted post failed cannot render
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Dec 20, 2019
1 parent c809188 commit fb1f47a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/InjectedComponents/AddToKeyStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface AddToKeyStoreProps {
provePost: string
postBy: ProfileIdentifier
completeComponentProps?: Partial<SuccessProps>
completeComponent?: React.ComponentType
completeComponent?: React.ComponentType<{ data: boolean }>
waitingComponentProps?: Partial<WaitingProps>
waitingComponent?: React.ComponentType
failedComponentProps?: Partial<FailedProps>
Expand Down
2 changes: 1 addition & 1 deletion src/components/InjectedComponents/DecryptedPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const DecryptPostFailed = React.memo(function DecryptPostFailed({ error,
return (
<AdditionalContent
title={geti18nString('service_decryption_failed')}
renderText={error && error.message}
renderText={error?.message}
{...props.AdditionalContentProps}
/>
)
Expand Down
15 changes: 5 additions & 10 deletions src/utils/components/AsyncComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type PromiseState<T> =
export default function AsyncComponent<Return>(props: {
promise: () => Promise<Return>
dependencies: ReadonlyArray<unknown>
completeComponent: React.ComponentType<{ data: Return }> | React.ReactNode
completeComponent: React.ComponentType<{ data: Return }>
awaitingComponent: React.SuspenseProps['fallback']
failedComponent: React.ComponentType<{ error: Error }> | React.ReactNode
failedComponent: React.ComponentType<{ error: Error }> | null
}) {
const [state, setState] = React.useState<PromiseState<Return>>({ status: 'not-started' })
// eslint-disable-next-line
Expand All @@ -30,16 +30,15 @@ export default function AsyncComponent<Return>(props: {
return {
default: () => {
const CompleteComponent = props.completeComponent
if (isComponent(CompleteComponent)) return <CompleteComponent data={data} />
else return (CompleteComponent as React.ReactElement) || null
return <CompleteComponent data={data} />
},
}
} catch (e) {
return {
default: () => {
const FailedComponent = props.failedComponent
if (isComponent(FailedComponent)) return <FailedComponent error={e} />
else return (FailedComponent as React.ReactElement) || null
if (FailedComponent === null) return null
return <FailedComponent error={e} />
},
}
}
Expand All @@ -54,10 +53,6 @@ export default function AsyncComponent<Return>(props: {
)
}

function isComponent<T>(f?: React.ComponentType<T> | NonNullable<React.ReactNode> | null): f is React.ComponentType<T> {
return typeof f === 'function'
}

/** React hook for not-cancelable async calculation */
export function useAsync<T>(fn: () => PromiseLike<T>, dep: ReadonlyArray<unknown>): PromiseLike<T> {
let res: Parameters<ConstructorParameters<typeof Promise>[0]>[0] = () => {},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/jss/renderInShadowRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const generateClassName = createGenerateClassName()
export class RenderInShadowRootWrapper extends React.PureComponent {
state: { error?: Error } = { error: undefined }
render() {
if (this.state.error) return this.state.error.message
if (this.state.error) return <pre style={{ whiteSpace: 'break-spaces' }}>{this.state.error.message}</pre>
return <Maskbook children={this.props.children} />
}
componentDidCatch(error: Error) {
Expand Down

0 comments on commit fb1f47a

Please sign in to comment.