From cd311e0fa1dbec50ebe7cc870cdaaf387601da43 Mon Sep 17 00:00:00 2001 From: David Ralph Date: Thu, 25 Aug 2022 17:07:35 +0100 Subject: [PATCH] refactor: cleanup various files --- .DS_Store | Bin 10244 -> 0 bytes .gitignore | 1 + src/components/widgets/Widgets.jsx | 65 ++++++++---------- .../widgets/weather/WeatherIcon.jsx | 43 ++++-------- .../widgets/weather/WindDirectionIcon.jsx | 31 +++------ 5 files changed, 50 insertions(+), 90 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index bac96f5d044e1073917ab9aa104532042fd8dfe1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHM&uMKc%6jCr66$uEdr@kMO_n8B*eu8=Kv}Q;i^5*D)ldth4qf*9|=;3 zPMdo-TsE7fN7$O@!@K7|`+YE9YcrjTyHG2j?*3^)cH1CD_Y zg#rA}=H@NL()Er3$ADvC!T|3NJ}#COEl06bTL(II1c1z8ST)=i`3BP0vZCcEmY6{k zu_|P&D)bRU#OfILHLjxND3-B034Qnw+Op6m6rrqReP6*zRAT9R$ADuX%>bX>b5x=Y z3TR-S-^Cw?j+%2FS*s#*9WQSw9Bb*dY7Dip zjqQF{V}EaS!=OJXm!FB5+1!D-yqEVDydP?ta=SLD4~G5KdhaHG`bNsIF}|-iz75*j z>&3&DWHhJ;QM;!Uf>s-l@4pM8mfT*I!>H9)y0v)1D|m(V;?bR*<#XlJ{@InUc2D~| z=a+H6a`xQrZoxZp^2-Z1*6)O!NZwaolhE5I9gIIu`UlCFtZWpTPm}XzF1F~maV{(l zJ93(dER2Hl8ymha0IKxiJ`MewmrcTwG&sH6^s313l5;&Y>x^7J)brc1O&*QiEoHd-9R zs%B&!R;>(un}BWU5<1awN!L|tR23Q+S(-_9b}pS2gV zRo5H?jseGjW56-s7v(+N*YTg}u`)|;n6GF#iltJ=xKfAwpMDJJo9CprInTTE ZzdQd|C-1kjPxfY=WTUK;_Io=2zX4!i*kAwv diff --git a/.gitignore b/.gitignore index c28b1f13..dfcf9fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ yarn-error.log stats.json yarn.lock keys.json +.DS_Store *.zip diff --git a/src/components/widgets/Widgets.jsx b/src/components/widgets/Widgets.jsx index d74e093f..ec8ac3f8 100644 --- a/src/components/widgets/Widgets.jsx +++ b/src/components/widgets/Widgets.jsx @@ -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
; - } - - // allow for re-ordering widgets - // we have a default to prevent errors - let elements = [, , , , , ]; - - if (this.state.order) { - elements = []; - this.state.order.forEach((element) => { - elements.push({this.widgets[element]}); - }); - } - - return ( + return this.state.welcome !== 'false' ? ( +
+ ) : (
{this.enabled('searchBar') ? : null} - {elements} + {this.state.order.map((element) => ( + this.widgets[element] + ))} {this.enabled('weatherEnabled') && this.online ? : null}
diff --git a/src/components/widgets/weather/WeatherIcon.jsx b/src/components/widgets/weather/WeatherIcon.jsx index 84c32087..f4708928 100644 --- a/src/components/widgets/weather/WeatherIcon.jsx +++ b/src/components/widgets/weather/WeatherIcon.jsx @@ -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 = ; - break; + return ; case '01n': - icon = ; - break; + return ; case '02d': - icon = ; - break; + return ; case '02n': - icon = ; - break; + return ; case '03d': case '03n': - icon = ; - break; + return ; case '04d': case '04n': - icon = ; - break; + return ; case '09d': - icon = ; - break; + return ; case '09n': - icon = ; - break; + return ; case '10d': case '10n': - icon = ; - break; + return ; case '11d': case '11n': - icon = ; - break; + return ; case '13d': case '13n': - icon = ; - break; + return ; case '50d': case '50n': - icon = ; - break; + return ; default: - icon = null; - break; + return null; } - - return icon; } diff --git a/src/components/widgets/weather/WindDirectionIcon.jsx b/src/components/widgets/weather/WindDirectionIcon.jsx index 941a4a3b..0002cd82 100644 --- a/src/components/widgets/weather/WindDirectionIcon.jsx +++ b/src/components/widgets/weather/WindDirectionIcon.jsx @@ -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 = ; - break; + return ; case 'North-West': - icon = ; - break; + return ; case 'West': - icon = ; - break; + return ; case 'South-West': - icon = ; - break; + return ; case 'South': - icon = ; - break; + return ; case 'South-East': - icon = ; - break; + return ; case 'East': - icon = ; - break; + return ; case 'North-East': - icon = ; - break; + return ; default: - icon = null; - break; + return null; } - - return icon; }