Last active
July 28, 2019 12:08
-
-
Save tobinbc/5a4d46b7d66ff10305129f261c1a4e58 to your computer and use it in GitHub Desktop.
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
import { CircularProgress } from '@material-ui/core'; | |
import CardContent from '@material-ui/core/CardContent'; | |
import React, { FunctionComponent, useEffect, useState } from 'react'; | |
import { Redirect, RouteComponentProps } from 'react-router-dom'; | |
const getStorage = () => new Promise(resolve => chrome.storage.local.get(resolve)); | |
type Props = RouteComponentProps; | |
const Holding: FunctionComponent<Props> = (props: Props) => { | |
const [redirect, setRedirect] = useState(''); | |
useEffect(() => { | |
getNextRoute(); | |
}, []); | |
const getNextRoute = async () => { | |
try { | |
let storage: any = await getStorage(); | |
switch (true) { | |
case storage.ok === undefined: | |
setRedirect('/signup'); | |
case storage.ok === true: | |
setRedirect('/record'); | |
} | |
} catch (e) { | |
setRedirect(`/error/${e.message}`); | |
} | |
}; | |
return redirect === '' ? ( | |
<CardContent> | |
<CircularProgress style={{ margin: '0 auto' }} /> | |
</CardContent> | |
) : ( | |
<Redirect to={redirect} /> | |
); | |
}; | |
export { Holding }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment