mirror of
https://github.com/mue/mue.git
synced 2026-07-17 05:54:14 +02:00
feat: hot reload and fixes for weather, quicklinks and quote
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
|
||||
import EventBus from '../../modules/helpers/eventbus';
|
||||
|
||||
import Clock from './time/Clock';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import EventBus from '../../../modules/helpers/eventbus';
|
||||
|
||||
import Tooltip from '@material-ui/core/Tooltip';
|
||||
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
|
||||
|
||||
@@ -17,12 +19,6 @@ export default class QuickLinks extends React.PureComponent {
|
||||
this.language = window.language.widgets.quicklinks;
|
||||
}
|
||||
|
||||
updateLink(type, value) {
|
||||
this.setState({
|
||||
[type]: value
|
||||
});
|
||||
}
|
||||
|
||||
deleteLink(name, event) {
|
||||
event.preventDefault();
|
||||
|
||||
@@ -65,6 +61,23 @@ export default class QuickLinks extends React.PureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
EventBus.on('refresh', (data) => {
|
||||
if (data === 'quicklinks') {
|
||||
const element = document.querySelector('.quicklinks-container');
|
||||
|
||||
if (localStorage.getItem('quicklinksenabled') === 'false') {
|
||||
return element.style.display = 'none';
|
||||
}
|
||||
|
||||
element.style.display = 'block';
|
||||
this.setState({
|
||||
items: JSON.parse(localStorage.getItem('quicklinks'))
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
let target, rel = null;
|
||||
if (localStorage.getItem('quicklinksnewtab') === 'true') {
|
||||
@@ -97,9 +110,9 @@ export default class QuickLinks extends React.PureComponent {
|
||||
<span className='quicklinkscontainer' style={{'visibility': this.state.showAddLink}}>
|
||||
<div className='topbarquicklinks'>
|
||||
<h4>{this.language.new}</h4>
|
||||
<TextareaAutosize rowsMax={1} placeholder={this.language.name} value={this.state.name} onChange={(e) => this.updateLink('name', e.target.value)} />
|
||||
<TextareaAutosize rowsMax={1} placeholder={this.language.name} value={this.state.name} onChange={(e) => this.setState({ name: e.target.value })} />
|
||||
<br/>
|
||||
<TextareaAutosize rowsMax={10} placeholder={this.language.url} value={this.state.url} onChange={(e) => this.updateLink('url', e.target.value)} />
|
||||
<TextareaAutosize rowsMax={10} placeholder={this.language.url} value={this.state.url} onChange={(e) => this.setState({ url: e.target.value })} />
|
||||
<br/>
|
||||
<button className='pinNote' onClick={this.addLink}>{this.language.add}</button>
|
||||
</div>
|
||||
|
||||
@@ -155,8 +155,10 @@ export default class Quote extends React.PureComponent {
|
||||
copy: (localStorage.getItem('copyButton') === 'false') ? null : this.buttons.copy,
|
||||
tweet: (localStorage.getItem('tweetButton') === 'false') ? null : this.buttons.tweet
|
||||
});
|
||||
|
||||
this.getQuote();
|
||||
|
||||
if (!this.state.quote) {
|
||||
this.getQuote();
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
import EventBus from '../../../modules/helpers/eventbus';
|
||||
|
||||
import WeatherIcon from './WeatherIcon';
|
||||
import { WiHumidity, WiWindy } from 'weather-icons-react';
|
||||
|
||||
@@ -13,7 +15,6 @@ export default class Weather extends React.PureComponent {
|
||||
icon: '',
|
||||
temp_text: '',
|
||||
weather: {
|
||||
title: '',
|
||||
temp: '',
|
||||
temp_min: '',
|
||||
temp_max: '',
|
||||
@@ -25,10 +26,30 @@ export default class Weather extends React.PureComponent {
|
||||
}
|
||||
|
||||
async getWeather() {
|
||||
const data = await (await fetch (window.constants.WEATHER_URL + `?city=${this.state.location}`)).json();
|
||||
let data = {
|
||||
weather: [
|
||||
{
|
||||
icon: this.state.icon
|
||||
}
|
||||
],
|
||||
wind: {
|
||||
speed: this.state.weather.windspeed
|
||||
},
|
||||
main: {
|
||||
temp: this.state.weather.original_temp,
|
||||
temp_min: this.state.weather.original_temp_min,
|
||||
temp_max: this.state.weather.original_temp_max,
|
||||
humidity: this.state.weather.humidity,
|
||||
pressure: this.state.weather.pressure
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.state.weather.temp) {
|
||||
data = await (await fetch (window.constants.WEATHER_URL + `?city=${this.state.location}`)).json();
|
||||
}
|
||||
|
||||
let temp = data.main.temp;
|
||||
let temp_min = data.main.temp_max
|
||||
let temp_min = data.main.temp_mix
|
||||
let temp_max = data.main.temp_max;
|
||||
let temp_text = 'K';
|
||||
|
||||
@@ -52,18 +73,33 @@ export default class Weather extends React.PureComponent {
|
||||
icon: data.weather[0].icon,
|
||||
temp_text: temp_text,
|
||||
weather: {
|
||||
title: data.weather[0].main,
|
||||
temp: Math.round(temp),
|
||||
temp_min: Math.round(temp_min),
|
||||
temp_max: Math.round(temp_max),
|
||||
humidity: data.main.humidity,
|
||||
windspeed: data.wind.speed,
|
||||
pressure: data.main.pressure
|
||||
pressure: data.main.pressure,
|
||||
original_temp: data.main.temp,
|
||||
original_temp_min: data.main.temp_min,
|
||||
original_temp_max: data.main.temp_max
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
EventBus.on('refresh', (data) => {
|
||||
if (data === 'weather') {
|
||||
const element = document.querySelector('.weather');
|
||||
|
||||
if (localStorage.getItem('weatherEnabled') === 'false') {
|
||||
return element.style.display = 'none';
|
||||
}
|
||||
|
||||
element.style.display = 'block';
|
||||
this.getWeather();
|
||||
}
|
||||
});
|
||||
|
||||
this.getWeather();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user