Skip to content

Commit

Permalink
feat: add analyze query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
gjgd committed Jun 27, 2020
1 parent 4cdf90b commit 441ed08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/app/src/components/CheckJsonButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import CircularProgress from '@material-ui/core/CircularProgress';
import { green, red } from '@material-ui/core/colors';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import clsx from 'clsx';
import { getQueryParameter } from '../utils';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand Down Expand Up @@ -43,6 +44,7 @@ const CheckJsonButton: React.FunctionComponent<{
value: Object;
setResult: any;
}> = ({ value, setResult }) => {
const analyzeQueryParameter = getQueryParameter('analyze');
const classes = useStyles();
const [loading, setLoading] = React.useState(false);
const [success, setSuccess] = React.useState(false);
Expand All @@ -53,12 +55,7 @@ const CheckJsonButton: React.FunctionComponent<{
[classes.buttonError]: error,
});

React.useEffect(() => {
setSuccess(false);
setError(false);
}, [value]);

const onClick = async () => {
const analyzeObject = async () => {
if (!loading) {
setLoading(true);
const res = await check(value);
Expand All @@ -69,6 +66,18 @@ const CheckJsonButton: React.FunctionComponent<{
}
};

React.useEffect(() => {
if (analyzeQueryParameter === '1') {
analyzeObject();
}
// eslint-disable-next-line
}, [analyzeQueryParameter]);

React.useEffect(() => {
setSuccess(false);
setError(false);
}, [value]);

return (
<div className={classes.root}>
{success}
Expand All @@ -79,7 +88,7 @@ const CheckJsonButton: React.FunctionComponent<{
color="primary"
className={buttonClassname}
disabled={loading}
onClick={onClick}
onClick={analyzeObject}
>
Check
</Button>
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/components/CheckJsonTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ const useStyles = makeStyles((theme) => ({

const CheckJsonTab: React.FunctionComponent<{}> = () => {
const classes = useStyles();
// Json query parameter
const jsonQueryParameter = getQueryParameter('json');
let defaultJson: string;
if (jsonQueryParameter) {
defaultJson = decodeURIComponent(jsonQueryParameter);
} else {
defaultJson = defaultValue;
}

const [jsonValue, setJsonValue] = React.useState(defaultJson);
const [result, setResult] = React.useState<JsonLdCheckResult>();

Expand Down

0 comments on commit 441ed08

Please sign in to comment.