Skip to content

Commit

Permalink
fix open icon modal (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
itwillwork authored Dec 3, 2024
1 parent 6b4eb41 commit 0f75e04
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/Icons/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ export const Icons: React.FC<IconsProps> = ({currentIcon, onChangeCurrentIcon})
}
}, [isMobile]);

const closeTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();

React.useEffect(() => {
if (currentIcon && currentIcon !== iconForDialog?.name) {
const iconToShow = allIcons.find((icon) => icon.name === currentIcon);

if (iconToShow) {
setIsOpenIconDialog(true);
clearTimeout(closeTimeoutRef.current);
setIconForDialog(iconToShow);
}
}
Expand All @@ -54,6 +57,7 @@ export const Icons: React.FC<IconsProps> = ({currentIcon, onChangeCurrentIcon})
const handleSelectIcon = React.useCallback(
(item: IconItem) => {
setIsOpenIconDialog(true);
clearTimeout(closeTimeoutRef.current);
setIconForDialog(item);
onChangeCurrentIcon?.(item?.name);
},
Expand All @@ -62,7 +66,7 @@ export const Icons: React.FC<IconsProps> = ({currentIcon, onChangeCurrentIcon})

const handleCloseDialog = React.useCallback(() => {
setIsOpenIconDialog(false);
setTimeout(() => {
closeTimeoutRef.current = setTimeout(() => {
setIconForDialog(undefined);
onChangeCurrentIcon?.(undefined);
}, 500);
Expand Down

0 comments on commit 0f75e04

Please sign in to comment.