-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(feed brain): add pending message * feat: add 'filesUploading' translation * feat(chatPage): update tests
- Loading branch information
1 parent
f701056
commit e3701e3
Showing
10 changed files
with
92 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 55 additions & 21 deletions
76
frontend/app/chat/[chatId]/components/ActionsBar/ActionsBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,71 @@ | ||
import { useParams } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { AiOutlineLoading3Quarters } from "react-icons/ai"; | ||
|
||
import { useChatApi } from "@/lib/api/chat/useChatApi"; | ||
|
||
import { ChatInput, KnowledgeToFeed } from "./components"; | ||
import { useActionBar } from "./hooks/useActionBar"; | ||
import { useKnowledgeUploader } from "./hooks/useKnowledgeUploader"; | ||
import { checkIfHasPendingRequest } from "./utils/checkIfHasPendingRequest"; | ||
|
||
export const ActionsBar = (): JSX.Element => { | ||
const { shouldDisplayUploadCard, setShouldDisplayUploadCard } = | ||
useActionBar(); | ||
const { addContent, contents, feedBrain, removeContent } = | ||
useKnowledgeUploader(); | ||
const { getHistory } = useChatApi(); | ||
const { t } = useTranslation(["chat"]); | ||
const [hasPendingRequests, setHasPendingRequests] = useState(false); | ||
const params = useParams(); | ||
|
||
return ( | ||
<div | ||
className={ | ||
shouldDisplayUploadCard ? "h-full flex flex-col flex-auto" : "" | ||
useEffect(() => { | ||
const updateNotificationsStatus = async () => { | ||
const chatId = params?.chatId as string | undefined; | ||
if (chatId !== undefined) { | ||
const history = await getHistory(chatId); | ||
setHasPendingRequests(checkIfHasPendingRequest(history)); | ||
} | ||
> | ||
{shouldDisplayUploadCard && ( | ||
<div className="flex flex-1 overflow-y-scroll shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-6"> | ||
<KnowledgeToFeed | ||
onClose={() => setShouldDisplayUploadCard(false)} | ||
contents={contents} | ||
addContent={addContent} | ||
removeContent={removeContent} | ||
/> | ||
}; | ||
void updateNotificationsStatus(); | ||
}, [getHistory, params?.chatId]); | ||
|
||
return ( | ||
<> | ||
{hasPendingRequests && ( | ||
<div className="flex mt-1 flex-row w-full shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-2 pl-6"> | ||
<div className="flex flex-1 items-center"> | ||
<span className="text-1xl">{t("filesUploading")}</span> | ||
</div> | ||
<AiOutlineLoading3Quarters className="animate-spin text-3xl" /> | ||
</div> | ||
)} | ||
<div className="flex mt-1 flex-col w-full shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-6"> | ||
<ChatInput | ||
shouldDisplayUploadCard={shouldDisplayUploadCard} | ||
setShouldDisplayUploadCard={setShouldDisplayUploadCard} | ||
feedBrain={() => void feedBrain()} | ||
hasContentToFeedBrain={contents.length > 0} | ||
/> | ||
|
||
<div | ||
className={ | ||
shouldDisplayUploadCard ? "h-full flex flex-col flex-auto" : "" | ||
} | ||
> | ||
{shouldDisplayUploadCard && ( | ||
<div className="flex flex-1 overflow-y-scroll shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-6"> | ||
<KnowledgeToFeed | ||
onClose={() => setShouldDisplayUploadCard(false)} | ||
contents={contents} | ||
addContent={addContent} | ||
removeContent={removeContent} | ||
/> | ||
</div> | ||
)} | ||
<div className="flex mt-1 flex-col w-full shadow-md dark:shadow-primary/25 hover:shadow-xl transition-shadow rounded-xl bg-white dark:bg-black border border-black/10 dark:border-white/25 p-6"> | ||
<ChatInput | ||
shouldDisplayUploadCard={shouldDisplayUploadCard} | ||
setShouldDisplayUploadCard={setShouldDisplayUploadCard} | ||
feedBrain={() => void feedBrain()} | ||
hasContentToFeedBrain={contents.length > 0} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
frontend/app/chat/[chatId]/components/ActionsBar/utils/checkIfHasPendingRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ChatItem } from "../../../types"; | ||
|
||
export const checkIfHasPendingRequest = (chatItems: ChatItem[]): boolean => { | ||
return chatItems.some( | ||
(item) => | ||
item.item_type === "NOTIFICATION" && item.body.status === "Pending" | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters