2021-09-10 15:38:53 +00:00
|
|
|
import variables from 'modules/variables';
|
2021-08-14 19:10:48 +00:00
|
|
|
import { PureComponent } from 'react';
|
2022-04-11 21:57:07 +00:00
|
|
|
import {
|
|
|
|
Radio as RadioUI,
|
|
|
|
RadioGroup,
|
|
|
|
FormControlLabel,
|
|
|
|
FormControl,
|
|
|
|
FormLabel,
|
|
|
|
} from '@mui/material';
|
2021-03-20 15:52:27 +00:00
|
|
|
|
2021-08-28 14:34:12 +00:00
|
|
|
import EventBus from 'modules/helpers/eventbus';
|
2021-04-12 17:55:02 +00:00
|
|
|
|
2021-08-14 19:10:48 +00:00
|
|
|
export default class Radio extends PureComponent {
|
2021-03-23 13:10:34 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2021-03-20 15:52:27 +00:00
|
|
|
this.state = {
|
2022-04-11 21:57:07 +00:00
|
|
|
value: localStorage.getItem(this.props.name),
|
2021-03-20 15:52:27 +00:00
|
|
|
};
|
|
|
|
}
|
2022-04-11 21:57:07 +00:00
|
|
|
|
2021-03-23 13:10:34 +00:00
|
|
|
handleChange = (e) => {
|
|
|
|
const { value } = e.target;
|
|
|
|
|
2021-04-17 10:17:46 +00:00
|
|
|
if (value === 'loading') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-17 15:31:42 +00:00
|
|
|
if (this.props.name === 'language') {
|
2021-08-22 14:00:05 +00:00
|
|
|
// old tab name
|
2022-04-11 21:57:07 +00:00
|
|
|
if (
|
|
|
|
localStorage.getItem('tabName') ===
|
|
|
|
variables.language.getMessage(variables.languagecode, 'tabname')
|
|
|
|
) {
|
|
|
|
localStorage.setItem(
|
|
|
|
'tabName',
|
|
|
|
require(`translations/${value.replace('-', '_')}.json`).tabname,
|
|
|
|
);
|
2021-08-22 14:00:05 +00:00
|
|
|
}
|
2021-08-17 15:31:42 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 15:52:27 +00:00
|
|
|
localStorage.setItem(this.props.name, value);
|
2022-04-11 21:57:07 +00:00
|
|
|
|
2021-03-20 15:52:27 +00:00
|
|
|
this.setState({
|
2022-04-11 21:57:07 +00:00
|
|
|
value,
|
2021-03-20 15:52:27 +00:00
|
|
|
});
|
2021-04-12 17:55:02 +00:00
|
|
|
|
2021-11-04 13:58:53 +00:00
|
|
|
if (this.props.onChange) {
|
|
|
|
this.props.onChange(value);
|
|
|
|
}
|
|
|
|
|
2021-09-28 22:04:04 +00:00
|
|
|
variables.stats.postEvent('setting', `${this.props.name} from ${this.state.value} to ${value}`);
|
2022-04-11 21:57:07 +00:00
|
|
|
|
2021-04-14 20:20:43 +00:00
|
|
|
if (this.props.element) {
|
|
|
|
if (!document.querySelector(this.props.element)) {
|
2022-04-08 13:48:36 +00:00
|
|
|
document.querySelector('.reminder-info').style.display = 'flex';
|
2021-04-14 20:20:43 +00:00
|
|
|
return localStorage.setItem('showReminder', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 17:55:02 +00:00
|
|
|
EventBus.dispatch('refresh', this.props.category);
|
2022-04-11 21:57:07 +00:00
|
|
|
};
|
|
|
|
|
2021-03-20 15:52:27 +00:00
|
|
|
render() {
|
|
|
|
return (
|
2022-04-11 21:57:07 +00:00
|
|
|
<FormControl component="fieldset">
|
|
|
|
<FormLabel
|
|
|
|
className={this.props.smallTitle ? 'radio-title-small' : 'radio-title'}
|
|
|
|
component="legend"
|
|
|
|
>
|
|
|
|
{this.props.title}
|
|
|
|
</FormLabel>
|
|
|
|
<RadioGroup
|
|
|
|
aria-label={this.props.name}
|
|
|
|
name={this.props.name}
|
|
|
|
onChange={this.handleChange}
|
|
|
|
value={this.state.value}
|
|
|
|
>
|
2021-04-08 18:52:17 +00:00
|
|
|
{this.props.options.map((option) => (
|
2022-04-11 21:57:07 +00:00
|
|
|
<FormControlLabel
|
|
|
|
value={option.value}
|
|
|
|
control={<RadioUI />}
|
|
|
|
label={option.name}
|
|
|
|
key={option.name}
|
|
|
|
/>
|
2021-04-02 12:24:18 +00:00
|
|
|
))}
|
2021-03-20 15:52:27 +00:00
|
|
|
</RadioGroup>
|
|
|
|
</FormControl>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|