From b338f22bcaa84e02e59d07c2a34f2ed9aa304708 Mon Sep 17 00:00:00 2001 From: Weves Date: Sat, 2 Sep 2023 14:18:06 -0700 Subject: [PATCH] Fix popup overlap --- web/src/components/admin/connectors/Popup.tsx | 12 ++++++++++-- web/src/components/search/DocumentDisplay.tsx | 6 +++--- web/src/components/search/DocumentFeedbackBlock.tsx | 1 - web/src/components/search/QAFeedback.tsx | 11 ++++++----- web/src/components/search/SearchResultsDisplay.tsx | 11 +++++++++-- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/web/src/components/admin/connectors/Popup.tsx b/web/src/components/admin/connectors/Popup.tsx index 26e7ce004ea..dabf2622c6b 100644 --- a/web/src/components/admin/connectors/Popup.tsx +++ b/web/src/components/admin/connectors/Popup.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useRef, useState } from "react"; export interface PopupSpec { message: string; @@ -17,9 +17,17 @@ export const Popup: React.FC = ({ message, type }) => ( export const usePopup = () => { const [popup, setPopup] = useState(null); + // using NodeJS.Timeout because setTimeout in NodeJS returns a different type than in browsers + const timeoutRef = useRef(null); + const setPopupWithExpiration = (popupSpec: PopupSpec | null) => { + // Clear any previous timeout + if (timeoutRef.current) { + clearTimeout(timeoutRef.current); + } + setPopup(popupSpec); - setTimeout(() => { + timeoutRef.current = setTimeout(() => { setPopup(null); }, 4000); }; diff --git a/web/src/components/search/DocumentDisplay.tsx b/web/src/components/search/DocumentDisplay.tsx index 760e0996f67..d7a52e24685 100644 --- a/web/src/components/search/DocumentDisplay.tsx +++ b/web/src/components/search/DocumentDisplay.tsx @@ -2,18 +2,19 @@ import { DanswerDocument } from "@/lib/search/interfaces"; import { DocumentFeedbackBlock } from "./DocumentFeedbackBlock"; import { getSourceIcon } from "../source"; import { useState } from "react"; -import { usePopup } from "../admin/connectors/Popup"; +import { PopupSpec } from "../admin/connectors/Popup"; interface DocumentDisplayProps { document: DanswerDocument; queryEventId: number | null; + setPopup: (popupSpec: PopupSpec | null) => void; } export const DocumentDisplay = ({ document, queryEventId, + setPopup, }: DocumentDisplayProps) => { - const { popup, setPopup } = usePopup(); const [isHovered, setIsHovered] = useState(false); return ( @@ -25,7 +26,6 @@ export const DocumentDisplay = ({ }} onMouseLeave={() => setIsHovered(false)} > - {popup}
void; } -export const QAFeedbackBlock = ({ queryId }: QAFeedbackBlockProps) => { - const { popup, setPopup } = usePopup(); - +export const QAFeedbackBlock = ({ + queryId, + setPopup, +}: QAFeedbackBlockProps) => { return (
- {popup}
{ const seen = new Set(); @@ -45,6 +46,7 @@ export const SearchResultsDisplay: React.FC = ({ isFetching, defaultOverrides, }) => { + const { popup, setPopup } = usePopup(); const [isAIThoughtsOpen, setIsAIThoughtsOpen] = React.useState( getAIThoughtsIsOpenSavedValue() ); @@ -106,6 +108,7 @@ export const SearchResultsDisplay: React.FC = ({ return ( <> + {popup} {shouldDisplayQA && (
@@ -150,7 +153,10 @@ export const SearchResultsDisplay: React.FC = ({ {searchResponse.queryEventId !== null && (
- +
)}
@@ -169,6 +175,7 @@ export const SearchResultsDisplay: React.FC = ({ key={document.document_id} document={document} queryEventId={queryEventId} + setPopup={setPopup} /> ))}