import React from 'react';
import * as Constants from '../../modules/constants';
export default class Update extends React.PureComponent {
constructor(...args) {
super(...args);
this.state = {
title: this.props.language.title,
date: null,
content: this.props.language.title,
html: this.props.language.loading,
image: null
};
}
async getUpdate() {
if (localStorage.getItem('offlineMode') === 'true') {
return this.setState({
title: this.props.language.offline.title,
html: this.props.language.offline.description
});
}
const data = await (await fetch(Constants.API_URL + '/getUpdate')).json();
if (data.statusCode === 500 || data.title === null) {
const supportText = `
${this.props.language.contact_support}: https://muetab.com/contact
`; return this.setState({ title: this.props.language.error.title, html: this.props.language.error.description + supportText }); } this.setState({ title: data.title, date: data.published, image: data.image || null, author: data.author, html: data.content }); } componentDidMount() { this.getUpdate(); } render() { return