-
Notifications
You must be signed in to change notification settings - Fork 85
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 #85 from medyo/develop
Version 1.12.1
- Loading branch information
Showing
10 changed files
with
140 additions
and
100 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
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,32 @@ | ||
import React, { useContext } from 'react' | ||
import { ErrorBoundary } from 'react-error-boundary' | ||
import { trackException } from '../utils/Analytics' | ||
import { AiFillBug } from 'react-icons/ai' | ||
import { WiRefresh } from 'react-icons/wi' | ||
import { APP } from '../Constants' | ||
import '../pages/Page.css' | ||
|
||
export default function AppErrorBoundary({ children }) { | ||
function ErrorFallback({ error, resetErrorBoundary }) { | ||
return ( | ||
<div className="Page appError"> | ||
<AiFillBug size={64} /> | ||
<p>Sorry there was a problem loading this page.</p> | ||
<p>{error}</p> | ||
<button onClick={resetErrorBoundary}> | ||
<WiRefresh size={32} className={'buttonIcon'} /> Try again | ||
</button> | ||
</div> | ||
) | ||
} | ||
|
||
const errorHandler = (error, info) => { | ||
trackException(error, true) | ||
} | ||
|
||
return ( | ||
<ErrorBoundary FallbackComponent={ErrorFallback} onError={errorHandler}> | ||
{children} | ||
</ErrorBoundary> | ||
) | ||
} |
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,21 @@ | ||
import React, { useState } from 'react' | ||
import BeatLoader from 'react-spinners/BeatLoader' | ||
|
||
export const AppLoadingHOC = (WrappedComponent) => { | ||
function HOC(props) { | ||
const [isLoading, setIsLoading] = useState(true) | ||
const setLoadingState = (isComponentLoading) => setIsLoading(isComponentLoading) | ||
|
||
return ( | ||
<> | ||
{isLoading && ( | ||
<div className="appLoading"> | ||
<BeatLoader color={'#A9B2BD'} loading={true} size={15} /> | ||
</div> | ||
)} | ||
<WrappedComponent {...props} setLoading={setLoadingState} isLoading={isLoading} /> | ||
</> | ||
) | ||
} | ||
return HOC | ||
} |
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 |
---|---|---|
@@ -1,24 +1,39 @@ | ||
import useRemoteConfiguration from './useRemoteConfiguration'; | ||
import { ConfigurationProvider } from './ConfigurationContext'; | ||
import { LOCAL_CONFIGURATION } from '../Constants'; | ||
import BeatLoader from "react-spinners/BeatLoader"; | ||
import AppWrapper from './AppWrapper' | ||
import React, { useEffect, useState } from 'react' | ||
import remoteConfigurationApi from '../services/remoteConfiguration' | ||
import { ConfigurationProvider } from './ConfigurationContext' | ||
import { AppLoadingHOC } from './AppLoadingHOC' | ||
import useAsyncError from '../hooks/useAsyncError' | ||
|
||
export default function ConfigurationWrapper({ children }) { | ||
const [configuration, loadingConfiguration, errorConfiguration] = useRemoteConfiguration() | ||
if (loadingConfiguration) { | ||
return ( | ||
<div className="appLoading"> | ||
<BeatLoader color={'#A9B2BD'} loading={true} size={15} /> | ||
</div> | ||
) | ||
} | ||
export const ConfigurationWrapper = (props) => { | ||
const { setLoading, isLoading } = props | ||
const [configurationData, setConfigurationData] = useState(null) | ||
const throwError = useAsyncError() | ||
|
||
const getConfiguration = () => (errorConfiguration ? LOCAL_CONFIGURATION : configuration) | ||
useEffect(() => { | ||
setLoading(true) | ||
const setup = async () => { | ||
// try { | ||
const data = await remoteConfigurationApi.getRemoteConfiguration() | ||
if (!data) { | ||
throwError( | ||
'Could not fetch configuration data, Make sure you are connected to the internet' | ||
) | ||
} else { | ||
setConfigurationData(data) | ||
} | ||
setLoading(false) | ||
} | ||
|
||
setup() | ||
}, []) | ||
|
||
return ( | ||
<ConfigurationProvider value={getConfiguration()}> | ||
<AppWrapper>{children}</AppWrapper> | ||
</ConfigurationProvider> | ||
<> | ||
{configurationData && ( | ||
<ConfigurationProvider value={configurationData}>{props.children}</ConfigurationProvider> | ||
)} | ||
</> | ||
) | ||
} | ||
} | ||
|
||
export default AppLoadingHOC(ConfigurationWrapper) |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import React, { useCallback, useState } from 'react' | ||
|
||
const useAsyncError = () => { | ||
const [_, setError] = useState() | ||
return useCallback( | ||
(e) => { | ||
setError(() => { | ||
throw e | ||
}) | ||
}, | ||
[setError] | ||
) | ||
} | ||
export default useAsyncError |
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