import React from 'react'; import { Link } from 'react-router-dom'; import { Helmet } from 'react-helmet'; import { sourceLink, infoLine, ToggleDot } from './utils.js'; class Article extends React.Component { constructor(props) { super(props); const id = this.props.match.params.id; this.state = { story: JSON.parse(localStorage.getItem(id)) || false, error: false, }; } componentDidMount() { const id = this.props.match.params.id; fetch('/api/' + id) .then(res => res.json()) .then( (result) => { this.setState({ story: result.story }); localStorage.setItem(id, JSON.stringify(result.story)); }, (error) => { this.setState({ error: true }); } ); } render() { const id = this.props.match.params.id; const story = this.state.story; const error = this.state.error; return (
{error &&

Connection error?

} {story ?
{story.title} - QotNews

{story.title}

Source: {sourceLink(story)}
{infoLine(story)} {story.text ?
:

Problem getting article :(

}
:

loading...

}
); } } export default Article;