Skip to content

Commit

Permalink
avniproject/avni-server#663 | Add debounce to avoid user repeatedly c…
Browse files Browse the repository at this point in the history
…licking on a username to perform assignment / un-assignment
  • Loading branch information
himeshr committed Dec 18, 2023
1 parent af458c5 commit c56218e
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState, useEffect } from "react";
import ReactMultiSelectCheckboxes from "react-multiselect-checkboxes";
import { updateUserAssignmentToSubject } from "./SubjectAssignmentData";
import _ from "lodash";
import _, { debounce } from "lodash";

const SubjectAssignmentMultiSelect = props => {
const [selectedOptions, setSelectedOptions] = useState(
Expand All @@ -20,7 +20,7 @@ const SubjectAssignmentMultiSelect = props => {
]);
}

const onChange = (value, event) => {
const _onChange = (value, event) => {
updateUserAssignmentToSubject(event).then(([error]) => {
if (error) {
alert(error);
Expand All @@ -30,6 +30,8 @@ const SubjectAssignmentMultiSelect = props => {
});
};

const debouncedOnChange = debounce(_onChange, 500);

function getDropdownButtonLabel({ placeholderButtonLabel, value }) {
if (value.length === 0) {
return placeholderButtonLabel;
Expand All @@ -47,7 +49,7 @@ const SubjectAssignmentMultiSelect = props => {
<ReactMultiSelectCheckboxes
options={getSortedDropdownList(props.options)}
value={selectedOptions}
onChange={onChange}
onChange={debouncedOnChange}
setState={setSelectedOptions}
getDropdownButtonLabel={getDropdownButtonLabel}
/>
Expand Down

0 comments on commit c56218e

Please sign in to comment.