You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

77 lines
1.5 KiB

import React from 'react';
import { Link } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import localForage from 'localforage';
import { sourceLink, infoLine, ToggleDot } from './utils.js';
class Article extends React.Component {
constructor(props) {
super(props);
this.state = {
story: false,
error: false,
};
}
componentDidMount() {
const id = this.props.match.params.id;
localForage.getItem(id)
.then(
(value) => {
this.setState({ story: value });
}
);
fetch('/api/' + id)
.then(res => res.json())
.then(
(result) => {
this.setState({ story: result.story });
localForage.setItem(id, 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 (
<div className='article-container'>
{error && <p>Connection error?</p>}
{story ?
<div className='article'>
<Helmet>
<title>{story.title} - QotNews</title>
</Helmet>
<h1>{story.title}</h1>
<div className='info'>
Source: {sourceLink(story)}
</div>
{infoLine(story)}
{story.text ?
<div className='story-text' dangerouslySetInnerHTML={{ __html: story.text }} />
:
<p>Problem getting article :(</p>
}
</div>
:
<p>loading...</p>
}
<ToggleDot id={id} article={false} />
</div>
);
}
}
export default Article;