From c811ad2be67d2b5d450363c9e1306a47ac3e3ef4 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 11 Jul 2022 07:53:16 +0000 Subject: [PATCH] Simplify class invite dropdown code --- webclient/src/Classes.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/webclient/src/Classes.js b/webclient/src/Classes.js index 655ffa5..a4ef8cf 100644 --- a/webclient/src/Classes.js +++ b/webclient/src/Classes.js @@ -470,21 +470,17 @@ export function ICalButtons(props) { ]; // get default option from local storage or default to first item in options list - const pref = 'calendarPreference'; - let defaultSelection = options[0]; - let savedPreference = localStorage.getItem(pref); - if (savedPreference != null) { - defaultSelection = options.filter(x => x.value === savedPreference)[0]; - } + const calendarValue = localStorage.getItem('calendarPreference') || 'Email'; + const defaultOption = options.find(x => x.value === calendarValue); - const [selectedOption, setOption] = useState(defaultSelection); + const [selectedOption, setOption] = useState(defaultOption); - const onClick = (e, data) => { - let newOption = options.filter(x => x.value === data.value)[0]; + const onChange = (e, data) => { + const newOption = options.find(x => x.value === data.value); setOption(newOption); // set the option as users preference - localStorage.setItem(pref, newOption.value); + localStorage.setItem('calendarPreference', newOption.value); }; return ( @@ -502,7 +498,7 @@ export function ICalButtons(props) { } />