Simplify class invite dropdown code

This commit is contained in:
Tanner Collin 2022-07-11 07:53:16 +00:00
parent d77cde5042
commit c811ad2be6

View File

@ -470,21 +470,17 @@ export function ICalButtons(props) {
]; ];
// get default option from local storage or default to first item in options list // get default option from local storage or default to first item in options list
const pref = 'calendarPreference'; const calendarValue = localStorage.getItem('calendarPreference') || 'Email';
let defaultSelection = options[0]; const defaultOption = options.find(x => x.value === calendarValue);
let savedPreference = localStorage.getItem(pref);
if (savedPreference != null) {
defaultSelection = options.filter(x => x.value === savedPreference)[0];
}
const [selectedOption, setOption] = useState(defaultSelection); const [selectedOption, setOption] = useState(defaultOption);
const onClick = (e, data) => { const onChange = (e, data) => {
let newOption = options.filter(x => x.value === data.value)[0]; const newOption = options.find(x => x.value === data.value);
setOption(newOption); setOption(newOption);
// set the option as users preference // set the option as users preference
localStorage.setItem(pref, newOption.value); localStorage.setItem('calendarPreference', newOption.value);
}; };
return ( return (
@ -502,7 +498,7 @@ export function ICalButtons(props) {
<Dropdown <Dropdown
className='button icon' className='button icon'
floating floating
onChange={onClick} onChange={onChange}
options={options} options={options}
trigger={<></>} trigger={<></>}
/> />