Skip to content

Commit

Permalink
Added debounce to Share file fields (#3388)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
  • Loading branch information
bexsoft committed Jun 17, 2024
1 parent b376cf6 commit c61e1e0
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { api } from "api";
import { errorToHandler } from "api/errors";
import { getMaxShareLinkExpTime } from "screens/Console/ObjectBrowser/objectBrowserThunks";
import { maxShareLinkExpTime } from "screens/Console/ObjectBrowser/objectBrowserSlice";
import debounce from "lodash/debounce";

interface IShareFileProps {
open: boolean;
Expand All @@ -64,15 +65,15 @@ const ShareFile = ({
const [dateValid, setDateValid] = useState<boolean>(true);
const [versionID, setVersionID] = useState<string>("null");

const dateChanged = (newDate: string, isValid: boolean) => {
const debouncedDateChange = debounce((newDate: string, isValid: boolean) => {
setDateValid(isValid);
if (isValid) {
setSelectedDate(newDate);
return;
}
setSelectedDate("");
setShareURL("");
};
}, 300);

useEffect(() => {
dispatch(getMaxShareLinkExpTime());
Expand Down Expand Up @@ -214,7 +215,7 @@ const ShareFile = ({
id="date"
label="Active for"
maxSeconds={maxShareLinkExpTimeVal}
onChange={dateChanged}
onChange={debouncedDateChange}
entity="Link"
/>
</Grid>
Expand Down

0 comments on commit c61e1e0

Please sign in to comment.