mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-11 05:36:03 +02:00
Fix popup overlap
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
|
|
||||||
export interface PopupSpec {
|
export interface PopupSpec {
|
||||||
message: string;
|
message: string;
|
||||||
@@ -17,9 +17,17 @@ export const Popup: React.FC<PopupSpec> = ({ message, type }) => (
|
|||||||
|
|
||||||
export const usePopup = () => {
|
export const usePopup = () => {
|
||||||
const [popup, setPopup] = useState<PopupSpec | null>(null);
|
const [popup, setPopup] = useState<PopupSpec | null>(null);
|
||||||
|
// using NodeJS.Timeout because setTimeout in NodeJS returns a different type than in browsers
|
||||||
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
const setPopupWithExpiration = (popupSpec: PopupSpec | null) => {
|
const setPopupWithExpiration = (popupSpec: PopupSpec | null) => {
|
||||||
|
// Clear any previous timeout
|
||||||
|
if (timeoutRef.current) {
|
||||||
|
clearTimeout(timeoutRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
setPopup(popupSpec);
|
setPopup(popupSpec);
|
||||||
setTimeout(() => {
|
timeoutRef.current = setTimeout(() => {
|
||||||
setPopup(null);
|
setPopup(null);
|
||||||
}, 4000);
|
}, 4000);
|
||||||
};
|
};
|
||||||
|
@@ -2,18 +2,19 @@ import { DanswerDocument } from "@/lib/search/interfaces";
|
|||||||
import { DocumentFeedbackBlock } from "./DocumentFeedbackBlock";
|
import { DocumentFeedbackBlock } from "./DocumentFeedbackBlock";
|
||||||
import { getSourceIcon } from "../source";
|
import { getSourceIcon } from "../source";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { usePopup } from "../admin/connectors/Popup";
|
import { PopupSpec } from "../admin/connectors/Popup";
|
||||||
|
|
||||||
interface DocumentDisplayProps {
|
interface DocumentDisplayProps {
|
||||||
document: DanswerDocument;
|
document: DanswerDocument;
|
||||||
queryEventId: number | null;
|
queryEventId: number | null;
|
||||||
|
setPopup: (popupSpec: PopupSpec | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DocumentDisplay = ({
|
export const DocumentDisplay = ({
|
||||||
document,
|
document,
|
||||||
queryEventId,
|
queryEventId,
|
||||||
|
setPopup,
|
||||||
}: DocumentDisplayProps) => {
|
}: DocumentDisplayProps) => {
|
||||||
const { popup, setPopup } = usePopup();
|
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -25,7 +26,6 @@ export const DocumentDisplay = ({
|
|||||||
}}
|
}}
|
||||||
onMouseLeave={() => setIsHovered(false)}
|
onMouseLeave={() => setIsHovered(false)}
|
||||||
>
|
>
|
||||||
{popup}
|
|
||||||
<div className="flex relative">
|
<div className="flex relative">
|
||||||
<div className="absolute -left-10 top-2/4 -translate-y-2/4 w-10 flex">
|
<div className="absolute -left-10 top-2/4 -translate-y-2/4 w-10 flex">
|
||||||
<div
|
<div
|
||||||
|
@@ -70,7 +70,6 @@ const DocumentFeedback = ({
|
|||||||
queryId,
|
queryId,
|
||||||
feedbackType
|
feedbackType
|
||||||
);
|
);
|
||||||
console.log(errorMsg);
|
|
||||||
if (!errorMsg) {
|
if (!errorMsg) {
|
||||||
setPopup({
|
setPopup({
|
||||||
message: "Thanks for your feedback!",
|
message: "Thanks for your feedback!",
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { PopupSpec, usePopup } from "../admin/connectors/Popup";
|
import { PopupSpec } from "../admin/connectors/Popup";
|
||||||
import { ThumbsDownIcon, ThumbsUpIcon } from "../icons/icons";
|
import { ThumbsDownIcon, ThumbsUpIcon } from "../icons/icons";
|
||||||
|
|
||||||
type Feedback = "like" | "dislike";
|
type Feedback = "like" | "dislike";
|
||||||
@@ -71,14 +71,15 @@ const QAFeedback = ({
|
|||||||
|
|
||||||
interface QAFeedbackBlockProps {
|
interface QAFeedbackBlockProps {
|
||||||
queryId: number;
|
queryId: number;
|
||||||
|
setPopup: (popupSpec: PopupSpec | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const QAFeedbackBlock = ({ queryId }: QAFeedbackBlockProps) => {
|
export const QAFeedbackBlock = ({
|
||||||
const { popup, setPopup } = usePopup();
|
queryId,
|
||||||
|
setPopup,
|
||||||
|
}: QAFeedbackBlockProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
{popup}
|
|
||||||
<QAFeedback queryId={queryId} setPopup={setPopup} feedbackType="like" />
|
<QAFeedback queryId={queryId} setPopup={setPopup} feedbackType="like" />
|
||||||
<div className="ml-2">
|
<div className="ml-2">
|
||||||
<QAFeedback
|
<QAFeedback
|
||||||
|
@@ -18,7 +18,8 @@ import {
|
|||||||
getAIThoughtsIsOpenSavedValue,
|
getAIThoughtsIsOpenSavedValue,
|
||||||
setAIThoughtsIsOpenSavedValue,
|
setAIThoughtsIsOpenSavedValue,
|
||||||
} from "@/lib/search/aiThoughtUtils";
|
} from "@/lib/search/aiThoughtUtils";
|
||||||
import { Grid, ThreeDots } from "react-loader-spinner";
|
import { ThreeDots } from "react-loader-spinner";
|
||||||
|
import { usePopup } from "../admin/connectors/Popup";
|
||||||
|
|
||||||
const removeDuplicateDocs = (documents: DanswerDocument[]) => {
|
const removeDuplicateDocs = (documents: DanswerDocument[]) => {
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
@@ -45,6 +46,7 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
|
|||||||
isFetching,
|
isFetching,
|
||||||
defaultOverrides,
|
defaultOverrides,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { popup, setPopup } = usePopup();
|
||||||
const [isAIThoughtsOpen, setIsAIThoughtsOpen] = React.useState<boolean>(
|
const [isAIThoughtsOpen, setIsAIThoughtsOpen] = React.useState<boolean>(
|
||||||
getAIThoughtsIsOpenSavedValue()
|
getAIThoughtsIsOpenSavedValue()
|
||||||
);
|
);
|
||||||
@@ -106,6 +108,7 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{popup}
|
||||||
{shouldDisplayQA && (
|
{shouldDisplayQA && (
|
||||||
<div className="min-h-[16rem] p-4 border-2 rounded-md border-gray-700 relative">
|
<div className="min-h-[16rem] p-4 border-2 rounded-md border-gray-700 relative">
|
||||||
<div>
|
<div>
|
||||||
@@ -150,7 +153,10 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
|
|||||||
|
|
||||||
{searchResponse.queryEventId !== null && (
|
{searchResponse.queryEventId !== null && (
|
||||||
<div className="absolute right-3 bottom-3">
|
<div className="absolute right-3 bottom-3">
|
||||||
<QAFeedbackBlock queryId={searchResponse.queryEventId} />
|
<QAFeedbackBlock
|
||||||
|
queryId={searchResponse.queryEventId}
|
||||||
|
setPopup={setPopup}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -169,6 +175,7 @@ export const SearchResultsDisplay: React.FC<SearchResultsDisplayProps> = ({
|
|||||||
key={document.document_id}
|
key={document.document_id}
|
||||||
document={document}
|
document={document}
|
||||||
queryEventId={queryEventId}
|
queryEventId={queryEventId}
|
||||||
|
setPopup={setPopup}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user