Skip to content

Commit

Permalink
added useDetectionOutside for bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
negar-75 committed Sep 21, 2023
1 parent af9f72c commit edb1de2
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Icon } from '@iconify/react';
import { useState, useMemo } from 'react';
import { useDetectClickOutside } from 'react-detect-click-outside';
import { useDispatch, useSelector } from 'react-redux';
import cx from 'classnames';
import Button from 'renderer/components/Button';

import {
IBookmarks,
addBookmark,
Expand All @@ -21,6 +23,12 @@ interface Props {
const BookmarkButton = ({ currentAddress, pageTitle }: Props) => {
const [openFlyout, setOpenFlyout] = useState<boolean>(false);
const dispatch = useDispatch();
const ref = useDetectClickOutside({
onTriggered: () => {
if (!openFlyout) return;
if (openFlyout) setOpenFlyout(false);
},
});

const initbookmark = {
id: '',
Expand Down Expand Up @@ -48,7 +56,7 @@ const BookmarkButton = ({ currentAddress, pageTitle }: Props) => {
useKeyboardShortcut(SHORTCUT_CHANNEL.BOOKMARK, handleKeyboardShortcut);

return (
<>
<div ref={ref}>
<div>
<Button
className={cx('rounded-full', {
Expand All @@ -71,7 +79,7 @@ const BookmarkButton = ({ currentAddress, pageTitle }: Props) => {
/>
)}
</div>
</>
</div>
);
};

Expand Down

0 comments on commit edb1de2

Please sign in to comment.