2021-09-10 15:38:53 +00:00
|
|
|
import variables from 'modules/variables';
|
2021-08-27 22:08:32 +00:00
|
|
|
import { PureComponent, createRef } from 'react';
|
2021-10-12 21:18:47 +00:00
|
|
|
import { InputLabel, MenuItem, FormControl, Select } from '@mui/material';
|
2020-10-27 14:59:45 +00:00
|
|
|
|
2021-08-28 14:34:12 +00:00
|
|
|
import EventBus from 'modules/helpers/eventbus';
|
2021-04-12 19:35:17 +00:00
|
|
|
|
2021-08-14 19:10:48 +00:00
|
|
|
export default class Dropdown extends PureComponent {
|
2021-03-23 13:10:34 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2021-03-21 14:39:12 +00:00
|
|
|
this.state = {
|
2021-10-12 21:18:47 +00:00
|
|
|
value: localStorage.getItem(this.props.name) || this.props.children[0].props.value,
|
2022-04-11 21:57:07 +00:00
|
|
|
title: '',
|
2021-03-21 14:39:12 +00:00
|
|
|
};
|
2021-08-27 22:08:32 +00:00
|
|
|
this.dropdown = createRef();
|
2020-10-27 14:59:45 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 13:10:34 +00:00
|
|
|
onChange = (e) => {
|
|
|
|
const { value } = e.target;
|
|
|
|
|
2022-08-26 09:45:32 +00:00
|
|
|
if (value === variables.getMessage('modals.main.loading')) {
|
2021-04-17 10:17:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-28 22:04:04 +00:00
|
|
|
variables.stats.postEvent('setting', `${this.props.name} from ${this.state.value} to ${value}`);
|
2021-06-21 16:42:14 +00:00
|
|
|
|
2021-03-21 14:39:12 +00:00
|
|
|
this.setState({
|
2022-04-11 21:57:07 +00:00
|
|
|
value,
|
2021-03-21 14:39:12 +00:00
|
|
|
});
|
2022-04-11 21:57:07 +00:00
|
|
|
|
2021-09-18 19:51:00 +00:00
|
|
|
if (!this.props.noSetting) {
|
|
|
|
localStorage.setItem(this.props.name, value);
|
2022-11-06 11:59:59 +00:00
|
|
|
localStorage.setItem(this.props.name2, this.props.value2);
|
2021-09-18 19:51:00 +00:00
|
|
|
}
|
2022-04-11 21:57:07 +00:00
|
|
|
|
2021-03-19 20:18:57 +00:00
|
|
|
if (this.props.onChange) {
|
2021-03-21 14:39:12 +00:00
|
|
|
this.props.onChange(value);
|
2021-03-19 20:18:57 +00:00
|
|
|
}
|
2021-04-12 19:35:17 +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 19:35:17 +00:00
|
|
|
EventBus.dispatch('refresh', this.props.category);
|
2022-04-11 21:57:07 +00:00
|
|
|
};
|
2021-03-19 20:18:57 +00:00
|
|
|
|
2020-10-27 14:59:45 +00:00
|
|
|
render() {
|
2021-10-12 21:18:47 +00:00
|
|
|
const id = 'dropdown' + this.props.name;
|
|
|
|
const label = this.props.label || '';
|
|
|
|
|
2020-10-27 14:59:45 +00:00
|
|
|
return (
|
2021-11-18 14:49:20 +00:00
|
|
|
<FormControl fullWidth className={id}>
|
2021-10-12 21:18:47 +00:00
|
|
|
<InputLabel id={id}>{label}</InputLabel>
|
2022-04-11 21:57:07 +00:00
|
|
|
<Select
|
|
|
|
labelId={id}
|
|
|
|
id={this.props.name}
|
|
|
|
value={this.state.value}
|
|
|
|
label={label}
|
|
|
|
onChange={this.onChange}
|
|
|
|
ref={this.dropdown}
|
|
|
|
key={id}
|
|
|
|
>
|
|
|
|
{this.props.manual
|
|
|
|
? this.props.children
|
|
|
|
: this.props.children.map((e, index) => {
|
|
|
|
return e ? (
|
|
|
|
<MenuItem key={index} value={e.props ? e.props.value : ''}>
|
|
|
|
{e.props ? e.props.children : ''}
|
|
|
|
</MenuItem>
|
|
|
|
) : null;
|
|
|
|
})}
|
2021-10-12 21:18:47 +00:00
|
|
|
</Select>
|
|
|
|
</FormControl>
|
2020-10-27 14:59:45 +00:00
|
|
|
);
|
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|