Merge pull request #17 from ocristopfer/feat_save_options_configurated_optins_on_storage

feat: Add Fahrenheit config to storage
This commit is contained in:
Cristopfer Luis 2024-02-08 09:50:20 -03:00 committed by GitHub
commit 6d762b41ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -33,11 +33,13 @@ export class Application extends React.Component {
componentDidMount() { componentDidMount() {
const storageHidedCards = localStorage.getItem('hidedCards'); const storageHidedCards = localStorage.getItem('hidedCards');
const hidedCards = storageHidedCards != null && storageHidedCards !== '' ? storageHidedCards.split(',') : []; const hidedCards = storageHidedCards != null && storageHidedCards !== '' ? storageHidedCards.split(',') : [];
const fahrenheitChecked = Boolean(localStorage.getItem('fahrenheitChecked')) || false
const isExpanded = JSON.parse(localStorage.getItem('isExpanded')) || {}
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
if (!this.state.isShowBtnInstall && !this.state.isError) if (!this.state.isShowBtnInstall && !this.state.isError)
this.loadSensors(); this.loadSensors();
}, 1000); }, 1000);
this.setState({ intervalId, hidedCards }); this.setState({ intervalId, hidedCards, fahrenheitChecked, isExpanded });
} }
componentWillUnmount() { componentWillUnmount() {
@ -129,21 +131,22 @@ export class Application extends React.Component {
this.setState({ alert: { msg, variant } }); this.setState({ alert: { msg, variant } });
}; };
handleChange = (checked, event) => { handleChangeFahrenheit = (event, checked) => {
this.setState({ fahrenheitChecked: checked }); this.setState({ fahrenheitChecked: checked });
localStorage.setItem('fahrenheitChecked', checked);
if (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'] }); this.setState({ fahrenheitTemp: ['-f'] });
} else { } else {
this.setState({ fahrenheitTemp: [], alert: null }); this.setState({ fahrenheitTemp: [] });
} }
}; };
handleChangeCards = (checked, event) => { handleChangeCards = (event, checked) => {
const isExpanded = this.state.isExpanded; const isExpanded = this.state.isExpanded;
Object.keys(isExpanded).forEach((element) => { Object.keys(isExpanded).forEach((element) => {
isExpanded[element] = checked; isExpanded[element] = checked;
}); });
localStorage.setItem('isExpanded', JSON.stringify(isExpanded));
this.setState({ isExpanded, expandAllCards: checked }); this.setState({ isExpanded, expandAllCards: checked });
}; };
@ -189,7 +192,7 @@ export class Application extends React.Component {
}); });
}) })
.fail((err) => { .fail((err) => {
this.setState({ isShowLoading: false, isShowBtnInstall: false }); this.setState({ isShowLoading: false, isShowBtnInstall: true });
this.setAlert(err.message, 'warning'); this.setAlert(err.message, 'warning');
}); });
}; };
@ -242,7 +245,7 @@ export class Application extends React.Component {
<Checkbox <Checkbox
label={_("Show temperature in Fahrenheit")} label={_("Show temperature in Fahrenheit")}
isChecked={fahrenheitChecked} isChecked={fahrenheitChecked}
onChange={this.handleChange} onChange={this.handleChangeFahrenheit}
id="fahrenheit-checkbox" id="fahrenheit-checkbox"
name="fahrenheit-checkbox" name="fahrenheit-checkbox"
/> />
@ -253,12 +256,11 @@ export class Application extends React.Component {
id="allcards-checkbox" id="allcards-checkbox"
name="allcards-checkbox" name="allcards-checkbox"
/> />
<>
{isShowLoading ? <Spinner isSVG /> : <></>} {isShowLoading ? <Spinner isSVG /> : <></>}
{alert != null ? <Alert variant={alert.variant}>{alert.msg}</Alert> : <></>} {alert != null ? <Alert variant={alert.variant}>{alert.msg}</Alert> : <></>}
{isShowBtnInstall ? <Button onClick={this.handleInstallSensors}>{_('Install')}</Button> : <></>} {isShowBtnInstall ? <Button onClick={this.handleInstallSensors}>{_('Install')}</Button> : <></>}
{hidedCards.length > 0 ? <Button onClick={() => this.handleShowHidedCards()}>{_('Show hided cards')}</Button> : <></>} {hidedCards.length > 0 ? <Button onClick={() => this.handleShowHidedCards()}>{_('Show hided cards')}</Button> : <></>}
</>
{sensors !== null {sensors !== null
? Object.entries(sensors).map((key, keyIndex) => { ? Object.entries(sensors).map((key, keyIndex) => {
if (hidedCards.includes(key[0])) { if (hidedCards.includes(key[0])) {