Skip to content

Commit

Permalink
fix: Fixed reload button if then app crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
artalat committed Dec 31, 2023
1 parent 95753e3 commit cef7a7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/OfflineComponents/BlueBaseApp/BlueBaseApp.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import { BlueBase, BlueBaseProgress, BootOptions } from '../../BlueBase';
import { ErrorObserver } from '../../components';
Expand Down Expand Up @@ -61,7 +61,7 @@ export const BlueBaseApp = (props: BlueBaseAppProps) => {

const { onError } = useExceptionHandlingOnProduction(BB);

async function boot(reset?: boolean) {
const boot = useCallback(async (reset?: boolean) => {
if (!booting) {
setBooting(true);
}
Expand All @@ -79,7 +79,7 @@ export const BlueBaseApp = (props: BlueBaseAppProps) => {
});
setBootCount(bootCount + 1);
setBooting(false);
}
}, [booting, bootCount, setBooting, setProgress, setBootCount, BB, props]);

BB.reboot = async (reset: boolean = false) => {
boot(reset);
Expand All @@ -100,7 +100,7 @@ export const BlueBaseApp = (props: BlueBaseAppProps) => {
}

if (progress.error) {
return <ErrorComponent BB={BB} progress={progress} bootCount={bootCount} />;
return <ErrorComponent BB={BB} progress={progress} bootCount={bootCount} retry={boot} />;
}

return (
Expand All @@ -111,6 +111,7 @@ export const BlueBaseApp = (props: BlueBaseAppProps) => {
progress={progress}
bootCount={bootCount}
onError={onError}
retry={boot}
>
<ThemeProvider>
<IntlProvider>
Expand Down
6 changes: 3 additions & 3 deletions src/OfflineComponents/BlueBaseAppError/BlueBaseAppError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export interface BlueBaseAppErrorProps {
error?: Error;
progress?: BlueBaseProgress;
bootCount: number;
retry?: () => void;
}

export const BlueBaseAppError = ({ progress, error: err, BB }: BlueBaseAppErrorProps) => {
export const BlueBaseAppError = ({ progress, error: err, retry }: BlueBaseAppErrorProps) => {
const error = err || (progress && progress.error);
let development = process.env.NODE_ENV !== 'production';

Expand All @@ -28,7 +29,6 @@ export const BlueBaseAppError = ({ progress, error: err, BB }: BlueBaseAppErrorP
}

const message = development === true && error ? error.message : MISSING_ERROR;
const reload = () => BB.reboot();

return (
<WaitObserver delay={100}>
Expand Down Expand Up @@ -64,7 +64,7 @@ export const BlueBaseAppError = ({ progress, error: err, BB }: BlueBaseAppErrorP
{message}
</Text>
<View style={{}}>
<TouchableOpacity onPress={reload} testID="error-button">
<TouchableOpacity onPress={retry} testID="error-button">
<Text
style={{
backgroundColor: 'rgba(76, 175, 80, .1)',
Expand Down

0 comments on commit cef7a7b

Please sign in to comment.