From afe5ab207fd619b0a16f39ee7a88fde1cfa88669 Mon Sep 17 00:00:00 2001 From: OGBONNA SUNDAY <62995161+OgDev-01@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:58:25 +0100 Subject: [PATCH] fix: popover display issue of safari (#1962) --- .../contributor-highlight-card.tsx | 30 ++++++++-- .../HighlightInput/highlight-input-form.tsx | 59 +++++++++++++------ 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/components/molecules/ContributorHighlight/contributor-highlight-card.tsx b/components/molecules/ContributorHighlight/contributor-highlight-card.tsx index 64c20d3be2..5997971517 100644 --- a/components/molecules/ContributorHighlight/contributor-highlight-card.tsx +++ b/components/molecules/ContributorHighlight/contributor-highlight-card.tsx @@ -124,6 +124,8 @@ const ContributorHighlightCard = ({ const { follow, unFollow, isError } = useFollowUser( dropdownOpen && loggedInUser && loggedInUser?.user_metadata.user_name !== user ? user : "" ); + const [popoverOpen, setPopoverOpen] = useState(false); + const popoverContentRef = React.useRef(null); const [date, setDate] = useState(shipped_date ? new Date(shipped_date) : undefined); @@ -167,6 +169,20 @@ const ContributorHighlightCard = ({ return !matches ? false : true; }; + const handleClickOutsidePopoverContent = (e: MouseEvent) => { + if (popoverContentRef.current && !popoverContentRef.current.contains(e.target as Node)) { + setPopoverOpen(false); + } + }; + + useEffect(() => { + // This closes the popover when user clicks outside of it's content + document.addEventListener("mousedown", handleClickOutsidePopoverContent); + return () => { + document.removeEventListener("mousedown", handleClickOutsidePopoverContent); + }; + }, [popoverOpen]); + const getEmojiReactors = (reaction_users: string[]) => { if (!Array.isArray(reaction_users)) return ""; @@ -659,20 +675,26 @@ const ContributorHighlightCard = ({ >
- + - - + { + setDate(date); + setPopoverOpen(false); + }} className="border rounded-md" /> diff --git a/components/molecules/HighlightInput/highlight-input-form.tsx b/components/molecules/HighlightInput/highlight-input-form.tsx index 8ce75e0692..11410ee5ed 100644 --- a/components/molecules/HighlightInput/highlight-input-form.tsx +++ b/components/molecules/HighlightInput/highlight-input-form.tsx @@ -109,6 +109,8 @@ const HighlightInputForm = ({ refreshCallback }: HighlightInputFormProps): JSX.E const [errorMsg, setError] = useState(""); const [highlightSuggestions, setHighlightSuggestions] = useState([]); const [loadingSuggestions, setLoadingSuggestions] = useState(false); + const [createPopoverOpen, setCreatePopoverOpen] = useState(false); + const popoverContentRef = useRef(null); const generateSummary = useRef(false); const fetchAllUserHighlights = async (page: number): Promise => { @@ -150,6 +152,12 @@ const HighlightInputForm = ({ refreshCallback }: HighlightInputFormProps): JSX.E setBodyText(value); }; + const handleClickOutsidePopoverContent = (e: MouseEvent) => { + if (popoverContentRef.current && !popoverContentRef.current.contains(e.target as Node)) { + setCreatePopoverOpen(false); + } + }; + useEffect(() => { // disable scroll when form is open if (isFormOpenMobile) { @@ -159,6 +167,14 @@ const HighlightInputForm = ({ refreshCallback }: HighlightInputFormProps): JSX.E } }, [isFormOpenMobile]); + useEffect(() => { + // This closes the popover when user clicks outside of it's content + document.addEventListener("mousedown", handleClickOutsidePopoverContent); + return () => { + document.removeEventListener("mousedown", handleClickOutsidePopoverContent); + }; + }, []); + // get the user's latest pull requests and issues that don't yet have highlights associated with them // and suggest them to the user when they are creating a highlight. useEffect(() => { @@ -555,20 +571,29 @@ const HighlightInputForm = ({ refreshCallback }: HighlightInputFormProps): JSX.E
- + - - + { + setDate(date); + setCreatePopoverOpen(false); + }} className="border rounded-md" /> @@ -656,24 +681,20 @@ const HighlightInputForm = ({ refreshCallback }: HighlightInputFormProps): JSX.E
{suggestion.type === "pull_request" && ( )} {suggestion.type === "issue" && ( )}

- +