mirror of
https://github.com/mue/mue.git
synced 2026-07-09 13:35:35 +02:00
refactor: cleanup various files
This commit is contained in:
@@ -42,53 +42,42 @@ export default class Widgets extends PureComponent {
|
||||
|
||||
componentDidMount() {
|
||||
EventBus.on('refresh', (data) => {
|
||||
if (data === 'widgets') {
|
||||
this.setState({
|
||||
order: JSON.parse(localStorage.getItem('order')),
|
||||
});
|
||||
}
|
||||
|
||||
if (data === 'widgetsWelcome') {
|
||||
this.setState({
|
||||
welcome: localStorage.getItem('showWelcome'),
|
||||
});
|
||||
localStorage.setItem('showWelcome', true);
|
||||
window.onbeforeunload = () => {
|
||||
localStorage.clear();
|
||||
};
|
||||
}
|
||||
|
||||
if (data === 'widgetsWelcomeDone') {
|
||||
this.setState({
|
||||
welcome: localStorage.getItem('showWelcome'),
|
||||
});
|
||||
window.onbeforeunload = null;
|
||||
switch (data) {
|
||||
case 'widgets':
|
||||
return this.setState({
|
||||
order: JSON.parse(localStorage.getItem('order')),
|
||||
});
|
||||
case 'widgetsWelcome':
|
||||
this.setState({
|
||||
welcome: localStorage.getItem('showWelcome'),
|
||||
});
|
||||
localStorage.setItem('showWelcome', true);
|
||||
window.onbeforeunload = () => {
|
||||
localStorage.clear();
|
||||
};
|
||||
break;
|
||||
case 'widgetsWelcomeDone':
|
||||
this.setState({
|
||||
welcome: localStorage.getItem('showWelcome'),
|
||||
});
|
||||
return (window.onbeforeunload = null);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
// don't show when welcome is there
|
||||
if (this.state.welcome !== 'false') {
|
||||
return <div id="widgets" />;
|
||||
}
|
||||
|
||||
// allow for re-ordering widgets
|
||||
// we have a default to prevent errors
|
||||
let elements = [<Greeting />, <Clock />, <QuickLinks />, <Quote />, <Date />, <Message />];
|
||||
|
||||
if (this.state.order) {
|
||||
elements = [];
|
||||
this.state.order.forEach((element) => {
|
||||
elements.push(<Fragment key={element}>{this.widgets[element]}</Fragment>);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
return this.state.welcome !== 'false' ? (
|
||||
<div id="widgets" />
|
||||
) : (
|
||||
<div id="widgets">
|
||||
<Suspense fallback={renderLoader()}>
|
||||
{this.enabled('searchBar') ? <Search /> : null}
|
||||
{elements}
|
||||
{this.state.order.map((element) => (
|
||||
this.widgets[element]
|
||||
))}
|
||||
{this.enabled('weatherEnabled') && this.online ? <Weather /> : null}
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
@@ -14,56 +14,39 @@ import {
|
||||
} from 'react-icons/wi';
|
||||
|
||||
export default function WeatherIcon({ name }) {
|
||||
let icon;
|
||||
|
||||
// name is the openweathermap icon name, see https://openweathermap.org/weather-conditions
|
||||
switch (name) {
|
||||
case '01d':
|
||||
icon = <WiDaySunny />;
|
||||
break;
|
||||
return <WiDaySunny />;
|
||||
case '01n':
|
||||
icon = <WiNightClear />;
|
||||
break;
|
||||
return <WiNightClear />;
|
||||
case '02d':
|
||||
icon = <WiDayCloudy />;
|
||||
break;
|
||||
return <WiDayCloudy />;
|
||||
case '02n':
|
||||
icon = <WiNightCloudy />;
|
||||
break;
|
||||
return <WiNightCloudy />;
|
||||
case '03d':
|
||||
case '03n':
|
||||
icon = <WiCloud />;
|
||||
break;
|
||||
return <WiCloud />;
|
||||
case '04d':
|
||||
case '04n':
|
||||
icon = <WiCloudy />;
|
||||
break;
|
||||
return <WiCloudy />;
|
||||
case '09d':
|
||||
icon = <WiDayShowers />;
|
||||
break;
|
||||
return <WiDayShowers />;
|
||||
case '09n':
|
||||
icon = <WiNightShowers />;
|
||||
break;
|
||||
return <WiNightShowers />;
|
||||
case '10d':
|
||||
case '10n':
|
||||
icon = <WiRain />;
|
||||
break;
|
||||
return <WiRain />;
|
||||
case '11d':
|
||||
case '11n':
|
||||
icon = <WiThunderstorm />;
|
||||
break;
|
||||
return <WiThunderstorm />;
|
||||
case '13d':
|
||||
case '13n':
|
||||
icon = <WiSnow />;
|
||||
break;
|
||||
return <WiSnow />;
|
||||
case '50d':
|
||||
case '50n':
|
||||
icon = <WiFog />;
|
||||
break;
|
||||
return <WiFog />;
|
||||
default:
|
||||
icon = null;
|
||||
break;
|
||||
return null;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import {
|
||||
|
||||
// degrees are imported because of a potential bug, IDK what causes it, but now it is fixed
|
||||
export default function WindDirectionIcon({ degrees }) {
|
||||
let icon;
|
||||
|
||||
// convert the number OpenWeatherMap gives us to the closest direction or something
|
||||
const directions = [
|
||||
'North',
|
||||
@@ -29,33 +27,22 @@ export default function WindDirectionIcon({ degrees }) {
|
||||
|
||||
switch (direction) {
|
||||
case 'North':
|
||||
icon = <WiDirectionUp />;
|
||||
break;
|
||||
return <WiDirectionUp />;
|
||||
case 'North-West':
|
||||
icon = <WiDirectionUpLeft />;
|
||||
break;
|
||||
return <WiDirectionUpLeft />;
|
||||
case 'West':
|
||||
icon = <WiDirectionLeft />;
|
||||
break;
|
||||
return <WiDirectionLeft />;
|
||||
case 'South-West':
|
||||
icon = <WiDirectionDownLeft />;
|
||||
break;
|
||||
return <WiDirectionDownLeft />;
|
||||
case 'South':
|
||||
icon = <WiDirectionDown />;
|
||||
break;
|
||||
return <WiDirectionDown />;
|
||||
case 'South-East':
|
||||
icon = <WiDirectionDownRight />;
|
||||
break;
|
||||
return <WiDirectionDownRight />;
|
||||
case 'East':
|
||||
icon = <WiDirectionRight />;
|
||||
break;
|
||||
return <WiDirectionRight />;
|
||||
case 'North-East':
|
||||
icon = <WiDirectionUpRight />;
|
||||
break;
|
||||
return <WiDirectionUpRight />;
|
||||
default:
|
||||
icon = null;
|
||||
break;
|
||||
return null;
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user