Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 committed Mar 20, 2024
1 parent 1324be5 commit 1ca99ba
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions client/src/app/components/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,16 @@ export const Autocomplete: React.FC<IAutocompleteProps> = ({

const filteredOptions = useMemo(() => {
const lowerInputValue = inputValue.toLowerCase();
return options.filter((option) => {
const optionNameLower = toString(option.name).toLowerCase();
const isNotSelected = !selections.some(
(selection) => selection.id === option.id
);
const matchesInputValue = optionNameLower.includes(lowerInputValue);
return isNotSelected && matchesInputValue;
});
return options.filter(
({ id, name }) =>
selections.findIndex((s) => s.id === id) === -1 && // Corrected check for not selected
toString(name).toLowerCase().includes(lowerInputValue)
);
}, [options, selections, inputValue]);

/** callback for removing a selection */
const deleteSelectionByItemId = (idToDelete: number) => {
const updatedSelections = selections.filter(({ id }) => id !== idToDelete);
onChange(updatedSelections);
onChange(selections.filter(({ id }) => id !== idToDelete));
};

/** lookup the option matching the itemId and add as a selection */
Expand Down Expand Up @@ -190,14 +186,9 @@ export const Autocomplete: React.FC<IAutocompleteProps> = ({
if (!event || !itemId) {
return;
}

const newSelection = options.find((option) => option.id === itemId);
if (newSelection) {
const updatedSelections = [...selections, newSelection].filter(Boolean);
onChange(updatedSelections);
setInputValue("");
setMenuIsOpen(false);
}
event.stopPropagation();
focusTextInput(true);
addSelectionByItemId(itemId);
};

/** close the menu when a click occurs outside of the menu or text input group */
Expand Down

0 comments on commit 1ca99ba

Please sign in to comment.