Skip to content

Instantly share code, notes, and snippets.

@tobinbc
Last active July 28, 2019 12:08
Show Gist options
  • Save tobinbc/5a4d46b7d66ff10305129f261c1a4e58 to your computer and use it in GitHub Desktop.
Save tobinbc/5a4d46b7d66ff10305129f261c1a4e58 to your computer and use it in GitHub Desktop.
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