Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #1220: Better error/loading handling when posts can't be loaded #1251

Merged
merged 6 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions src/frontend/src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'highlight.js/styles/github.css';
import { makeStyles } from '@material-ui/core/styles';
import { Box, Grid, Typography, ListSubheader } from '@material-ui/core';
import './telescope-post-content.css';
import Spinner from '../Spinner/Spinner.jsx';
import ErrorRoundedIcon from '@material-ui/icons/ErrorRounded';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"@material-ui/icons/ErrorRounded import should occur before import of ../AdminButtonseslintimport/order"

It's a quick fix, linter will handle this for you.

import AdminButtons from '../AdminButtons';

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -67,6 +69,13 @@ const useStyles = makeStyles((theme) => ({
textDecorationLine: 'underline',
},
},
spinner: {
padding: '20px',
},
error: {
lineHeight: '1.00',
fontSize: '1em',
},
}));

function formatPublishedDate(dateString) {
Expand All @@ -86,11 +95,44 @@ const Post = ({ postUrl }) => {

if (error) {
console.error(`Error loading post at ${postUrl}`, error);
return null;
return (
<Box className={classes.root} boxShadow={2}>
<ListSubheader className={classes.header}>
<AdminButtons />
<Typography variant="h1" className={classes.title}>
<Grid container className={classes.error}>
<Grid item>
<ErrorRoundedIcon className={classes.error} />
</Grid>{' '}
- Post Failed to Load
</Grid>
</Typography>
</ListSubheader>
</Box>
);
}

if (!post) {
return <div>Loading...</div>;
return (
<Box className={classes.root} boxShadow={2}>
<ListSubheader className={classes.header}>
<AdminButtons />
<Typography variant="h1" className={classes.title}>
Loading Blog...
</Typography>
</ListSubheader>

<Grid container justify="center">
<Grid item className={classes.spinner}>
<Spinner animation="border" variant="light">
<span className="sr-only" textAlign="center">
Loading...
</span>
</Spinner>
</Grid>
</Grid>
</Box>
);
}

return (
Expand Down
33 changes: 31 additions & 2 deletions src/frontend/src/components/Posts/Posts.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { useSWRInfinite } from 'swr';

import { Container } from '@material-ui/core';
import { Container, Grid } from '@material-ui/core';
import { makeStyles } from '@material-ui/core/styles';
import SentimentDissatisfiedRoundedIcon from '@material-ui/icons/SentimentDissatisfiedRounded';
import Timeline from './Timeline.jsx';
import useSiteMetaData from '../../hooks/use-site-metadata';

Expand All @@ -11,6 +12,19 @@ const useStyles = makeStyles(() => ({
padding: 0,
maxWidth: '785px',
},
error: {
position: 'center',
color: '#B5B5B5',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cindyledev, @agarcia-caicedo or someone else who knows our theme code: are there theme values we should be using for these colours instead?

fontFamily: 'Roboto',
fontSize: '5rem',
paddingBottom: '30px',
},
errorIcon: {
position: 'center',
color: '#B5B5B5',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here re: colours/theme.

fontSize: '10rem',
paddingBottom: 0,
},
}));

const REFRESH_INTERVAL = 5 * 60 * 1000; /* refresh data every 5 minutes */
Expand All @@ -29,7 +43,22 @@ const Posts = () => {
// TODO: need proper error handling
if (error) {
console.error('Error loading post data', error);
return null;
return (
<Container className={classes.root}>
<Grid
container
className={classes.error}
justify="center"
alignItems="center"
direction="column"
>
<Grid item>
<SentimentDissatisfiedRoundedIcon className={classes.errorIcon} />
</Grid>
<Grid item>Blog Timeline Failed to Load!</Grid>
</Grid>
</Container>
);
}

return (
Expand Down