forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#49341 from rezkiy37/fix/49340-improve-re…
…fresh Improve refresh and reload when error occured
- Loading branch information
Showing
5 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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,10 @@ | ||
import {useErrorBoundary} from 'react-error-boundary'; | ||
import type UsePageRefresh from './type'; | ||
|
||
const usePageRefresh: UsePageRefresh = () => { | ||
const {resetBoundary} = useErrorBoundary(); | ||
|
||
return resetBoundary; | ||
}; | ||
|
||
export default usePageRefresh; |
This file contains 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,24 @@ | ||
import differenceInMilliseconds from 'date-fns/differenceInMilliseconds'; | ||
import {useErrorBoundary} from 'react-error-boundary'; | ||
import CONST from '@src/CONST'; | ||
import type UsePageRefresh from './type'; | ||
|
||
const usePageRefresh: UsePageRefresh = () => { | ||
const {resetBoundary} = useErrorBoundary(); | ||
|
||
return () => { | ||
const lastRefreshTimestamp = JSON.parse(sessionStorage.getItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP) ?? 'null') as string; | ||
|
||
if (lastRefreshTimestamp === null || differenceInMilliseconds(Date.now(), Number(lastRefreshTimestamp)) > CONST.ERROR_WINDOW_RELOAD_TIMEOUT) { | ||
resetBoundary(); | ||
sessionStorage.setItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP, Date.now().toString()); | ||
|
||
return; | ||
} | ||
|
||
window.location.reload(); | ||
sessionStorage.removeItem(CONST.SESSION_STORAGE_KEYS.LAST_REFRESH_TIMESTAMP); | ||
}; | ||
}; | ||
|
||
export default usePageRefresh; |
This file contains 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,3 @@ | ||
type UsePageRefresh = () => () => void; | ||
|
||
export default UsePageRefresh; |
This file contains 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