mirror of
https://github.com/mue/mue.git
synced 2026-07-16 21:44:22 +02:00
refactor and fix some things
This commit is contained in:
@@ -6,54 +6,37 @@ export default class Update extends React.PureComponent {
|
||||
super(...args);
|
||||
this.state = {
|
||||
title: this.props.language.title,
|
||||
date: '???',
|
||||
date: null,
|
||||
content: this.props.language.title,
|
||||
author: 'Mue',
|
||||
html: this.props.language.loading
|
||||
html: this.props.language.loading,
|
||||
image: null
|
||||
};
|
||||
}
|
||||
|
||||
async getUpdate() {
|
||||
const supportText = `<br/><p>${this.props.language.contact_support}: <a target='_blank' class='modalLink' href='https://muetab.com/contact'>https://muetab.com/contact</a></p>`;
|
||||
|
||||
const removeStuff = () => { // quick code to make update modal a bit better, will replace later
|
||||
document.getElementById('author').innerText = '';
|
||||
const img = document.getElementsByTagName('img')[0];
|
||||
img.parentNode.removeChild(img);
|
||||
}
|
||||
|
||||
if (localStorage.getItem('offlineMode') === 'true') {
|
||||
removeStuff();
|
||||
return this.setState({
|
||||
title: this.props.language.offline.title,
|
||||
html: this.props.language.offline.description
|
||||
});
|
||||
}
|
||||
|
||||
try { // Get update log from the API
|
||||
const data = await (await fetch(Constants.API_URL + '/getUpdate')).json();
|
||||
if (data.statusCode === 500) {
|
||||
removeStuff();
|
||||
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,
|
||||
author: data.author,
|
||||
html: data.content + `<br/><p>${this.props.language.read_blog}: <a target='_blank' class='modalLink' href='${data.url}'>${data.url}</a></p>`
|
||||
});
|
||||
} catch (e) { // If it fails, we send an error
|
||||
removeStuff();
|
||||
this.setState({
|
||||
const data = await (await fetch(Constants.API_URL + '/getUpdate')).json();
|
||||
if (data.statusCode === 500 || data.title === null) {
|
||||
const supportText = `<br/><p>${this.props.language.contact_support}: <a target='_blank' class='modalLink' href='https://muetab.com/contact'>https://muetab.com/contact</a></p>`;
|
||||
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() {
|
||||
@@ -64,8 +47,8 @@ export default class Update extends React.PureComponent {
|
||||
return <div className='updateContent'>
|
||||
<span className='closeModal' onClick={this.props.modalClose}>×</span>
|
||||
<h1 style={{ 'marginBottom': '-10px' }}>{this.state.title}</h1>
|
||||
<h5 style={{ 'lineHeight':'0px' }} id='author'> By {this.state.author} • {this.state.date}</h5>
|
||||
<img draggable='false' src={this.state.image} alt='Update'></img>
|
||||
<h5 style={{ 'lineHeight': '0px' }}>{this.state.date}</h5>
|
||||
{this.state.image ? <img draggable='false' src={this.state.image} alt='Update'></img> : null}
|
||||
<p dangerouslySetInnerHTML={{ __html: this.state.html }}></p>
|
||||
</div>;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import React from 'react';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
import Checkbox from '../Checkbox';
|
||||
import Dropdown from '../Dropdown';
|
||||
import Section from '../Section';
|
||||
import FileUpload from '../FileUpload';
|
||||
|
||||
import { ColorPicker } from 'react-color-gradient-picker';
|
||||
import hexToRgb from '../../../../modules/helpers/background/hexToRgb';
|
||||
import rgbToHex from '../../../../modules/helpers/background/rgbToHex';
|
||||
|
||||
import { toast } from 'react-toastify';
|
||||
import { Beforeunload } from 'react-beforeunload';
|
||||
|
||||
import 'react-color-gradient-picker/dist/index.css';
|
||||
|
||||
Reference in New Issue
Block a user