Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Fixes file loading (mckaywrigley#1236)
Browse files Browse the repository at this point in the history
* adjust display ui

* modify how files load
  • Loading branch information
mckaywrigley authored and bpalagi committed Jan 28, 2024
1 parent 10df2ba commit 96ba650
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion components/chat/chat-files-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const ChatFilesDisplay: FC<ChatFilesDisplayProps> = ({}) => {
</div>

<div className="overflow-auto">
<div className="flex flex-wrap gap-2 truncate pt-2">
<div className="flex gap-2 overflow-auto pt-2">
{messageImages.map((image, index) => (
<div
key={index}
Expand Down
38 changes: 12 additions & 26 deletions components/chat/chat-ui.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Loading from "@/app/[locale]/loading"
import { useChatHandler } from "@/components/chat/chat-hooks/use-chat-handler"
import { ChatbotUIContext } from "@/context/context"
import { getChatFilesByChatId } from "@/db/chat-files"
import { getChatById } from "@/db/chats"
import { getFileById } from "@/db/files"
import { getMessageFileItemsByMessageId } from "@/db/message-file-items"
import { getMessagesByChatId } from "@/db/messages"
import { getMessageImageFromStorage } from "@/db/storage/message-images"
Expand Down Expand Up @@ -120,33 +120,19 @@ export const ChatUI: FC<ChatUIProps> = ({}) => {
const uniqueFileItems = messageFileItems.flatMap(item => item.file_items)
setChatFileItems(uniqueFileItems)

const uniqueFileIds = [
...new Set(uniqueFileItems.map(item => item.file_id))
]
const chatFiles = await getChatFilesByChatId(params.chatid as string)

if (uniqueFileIds.length > 0) {
const fileFetchPromises = uniqueFileIds.map(async fileId => {
const file = await getFileById(fileId)
return file
})

const files = await Promise.all(fileFetchPromises)
setChatFiles(
files.map(file => ({
id: file.id,
name: file.name,
type: file.type,
file: null
}))
)
setChatFiles(
chatFiles.files.map(file => ({
id: file.id,
name: file.name,
type: file.type,
file: null
}))
)

setUseRetrieval(true)
setShowFilesDisplay(true)
} else {
setUseRetrieval(false)
setShowFilesDisplay(false)
setChatFiles([])
}
setUseRetrieval(true)
setShowFilesDisplay(true)

const fetchedChatMessages = fetchedMessages.map(message => {
return {
Expand Down
2 changes: 1 addition & 1 deletion db/chat-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const getChatFilesByChatId = async (chatId: string) => {
`
id,
name,
files ( id, name, type )
files (*)
`
)
.eq("id", chatId)
Expand Down

0 comments on commit 96ba650

Please sign in to comment.