From 62d62eeceef5348f0564ba22cd15b028a1fb3e4b Mon Sep 17 00:00:00 2001 From: Cristopfer Luis Viana da Silva Date: Thu, 8 Feb 2024 09:48:49 -0300 Subject: [PATCH] feat: Add Fahrenheit config to storage feat: Add Expanded cards config to storage --- src/app.jsx | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/app.jsx b/src/app.jsx index ae5ebe5..a215dd4 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -33,11 +33,13 @@ export class Application extends React.Component { componentDidMount() { const storageHidedCards = localStorage.getItem('hidedCards'); const hidedCards = storageHidedCards != null && storageHidedCards !== '' ? storageHidedCards.split(',') : []; + const fahrenheitChecked = Boolean(localStorage.getItem('fahrenheitChecked')) || false + const isExpanded = JSON.parse(localStorage.getItem('isExpanded')) || {} const intervalId = setInterval(() => { if (!this.state.isShowBtnInstall && !this.state.isError) this.loadSensors(); }, 1000); - this.setState({ intervalId, hidedCards }); + this.setState({ intervalId, hidedCards, fahrenheitChecked, isExpanded }); } componentWillUnmount() { @@ -129,21 +131,22 @@ export class Application extends React.Component { this.setState({ alert: { msg, variant } }); }; - handleChange = (checked, event) => { + handleChangeFahrenheit = (event, checked) => { this.setState({ fahrenheitChecked: checked }); + localStorage.setItem('fahrenheitChecked', checked); if (checked) { - // this.setAlert(_('lm-sensors has a bug that converts all data to fahrenheit, including voltage, fans and etc.'), 'info'); this.setState({ fahrenheitTemp: ['-f'] }); } else { - this.setState({ fahrenheitTemp: [], alert: null }); + this.setState({ fahrenheitTemp: [] }); } }; - handleChangeCards = (checked, event) => { + handleChangeCards = (event, checked) => { const isExpanded = this.state.isExpanded; Object.keys(isExpanded).forEach((element) => { isExpanded[element] = checked; }); + localStorage.setItem('isExpanded', JSON.stringify(isExpanded)); this.setState({ isExpanded, expandAllCards: checked }); }; @@ -169,7 +172,7 @@ export class Application extends React.Component { } }) .fail((e) => { - this.getLmSensorsInstallCmd(index + 1); + this.getLmSensorsInstallCmd(index + 1); }); }; @@ -189,7 +192,7 @@ export class Application extends React.Component { }); }) .fail((err) => { - this.setState({ isShowLoading: false, isShowBtnInstall: false }); + this.setState({ isShowLoading: false, isShowBtnInstall: true }); this.setAlert(err.message, 'warning'); }); }; @@ -242,7 +245,7 @@ export class Application extends React.Component { @@ -253,12 +256,11 @@ export class Application extends React.Component { id="allcards-checkbox" name="allcards-checkbox" /> - <> - {isShowLoading ? : <>} - {alert != null ? {alert.msg} : <>} - {isShowBtnInstall ? : <>} - {hidedCards.length > 0 ? : <>} - + {isShowLoading ? : <>} + {alert != null ? {alert.msg} : <>} + {isShowBtnInstall ? : <>} + {hidedCards.length > 0 ? : <>} + {sensors !== null ? Object.entries(sensors).map((key, keyIndex) => { if (hidedCards.includes(key[0])) {