Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: update UI uploading files and images #4562

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,24 @@
)

const refAttachmentMenus = useClickOutside(() =>
setShowAttachmentMenus(false)

Check warning on line 79 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

79 line is not covered with tests
)
const [showRightPanel, setShowRightPanel] = useAtom(showRightPanelAtom)

useEffect(() => {
if (textareaRef.current) {
textareaRef.current.focus()

Check warning on line 85 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

85 line is not covered with tests
}
}, [activeThreadId])

useEffect(() => {
if (!selectedModel && !activeSettingInputBox) {
setActiveSettingInputBox(true)

Check warning on line 91 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

91 line is not covered with tests
}
}, [activeSettingInputBox, selectedModel, setActiveSettingInputBox])

const onStopInferenceClick = async () => {
stopInference()

Check warning on line 96 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

96 line is not covered with tests
}

const isModelSupportRagAndTools = isLocalEngine(
Expand All @@ -107,11 +107,11 @@
* @param event - The change event object.
*/
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0]
if (!file) return
upload.addFile(file)
upload.upload().then((data) => {
setFileUpload({

Check warning on line 114 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

110-114 lines are not covered with tests
file: file,
type: 'pdf',
id: data?.successful?.[0]?.response?.body?.id,
Expand All @@ -121,31 +121,31 @@
}

const handleImageChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0]
if (!file) return
setFileUpload({ file: file, type: 'image' })

Check warning on line 126 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

124-126 lines are not covered with tests
}

const renderPreview = (fileUpload: any) => {
if (fileUpload) {
if (fileUpload.type === 'image') {

Check warning on line 131 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

131 line is not covered with tests
return <ImageUploadPreview file={fileUpload.file} />
} else {
return <FileUploadPreview />

Check warning on line 134 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

134 line is not covered with tests
}
}
}

return (
<div className="relative p-4 pb-2">
{renderPreview(fileUpload)}
<div className="relative flex w-full flex-col">
{renderPreview(fileUpload)}
<RichTextEditor
className={twMerge(
'relative mb-1 max-h-[400px] resize-none rounded-lg border border-[hsla(var(--app-border))] p-3 pr-20',
'focus-within:outline-none focus-visible:outline-0 focus-visible:ring-1 focus-visible:ring-[hsla(var(--primary-bg))] focus-visible:ring-offset-0',
'overflow-y-auto',
fileUpload && 'rounded-t-none',
fileUpload && 'rounded-t-none border-t-0',
experimentalFeature && 'pl-10',
activeSettingInputBox && 'pb-14 pr-16'
)}
Expand All @@ -157,7 +157,7 @@
<TextArea
className="sr-only"
data-testid="txt-input-chat"
onChange={(e) => setCurrentPrompt(e.target.value)}

Check warning on line 160 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

160 line is not covered with tests
/>
{experimentalFeature && (
<Tooltip
Expand All @@ -166,7 +166,7 @@
theme="icon"
className="absolute left-3 top-2.5"
onClick={(e) => {
if (

Check warning on line 169 in web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

169 line is not covered with tests
!!fileUpload ||
(activeAssistant?.tools &&
!activeAssistant?.tools[0]?.enabled &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const FileUploadPreview = () => {
return (
<div className="flex flex-col rounded-t-lg border border-b-0 border-[hsla(var(--app-border))] p-4">
{!!fileUpload && (
<div className="bg-secondary relative inline-flex w-60 space-x-3 rounded-lg p-4">
<div className="relative inline-flex w-60 space-x-3 rounded-lg bg-[hsla(var(--secondary-bg))] p-4">
<Icon type={fileUpload?.type} />

<div className="w-full">
Expand All @@ -35,10 +35,10 @@ const FileUploadPreview = () => {
</div>

<div
className="absolute -right-2 -top-2 cursor-pointer rounded-full p-0.5"
className="absolute -right-2 -top-2 cursor-pointer rounded-full bg-[hsla(var(--destructive-bg))] p-0.5 text-[hsla(var(--destructive-fg))]"
onClick={onDeleteClick}
>
<XIcon size={14} className="text-background" />
<XIcon size={14} className="text-white" />
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ const ImageUploadPreview: React.FC<Props> = ({ file }) => {

return (
<div className="flex flex-col rounded-t-lg border border-b-0 border-[hsla(var(--app-border))] p-4">
<div className="bg-secondary relative w-60 rounded-lg p-4">
<div className="relative w-40 overflow-hidden rounded-lg border border-[hsla(var(--app-border))]">
<img src={base64} alt={file.name} className="object-cover" />
<h6 className="mt-2 line-clamp-1 font-medium">
{file.name.replaceAll(/[-._]/g, ' ')}
</h6>
<div
className="absolute -right-2 -top-2 cursor-pointer rounded-full p-0.5"
className="absolute right-2 top-2 cursor-pointer rounded-full bg-[hsla(var(--destructive-bg))] p-0.5 text-[hsla(var(--destructive-fg))]"
onClick={onDeleteClick}
>
<XIcon size={14} className="text-background" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const DocMessage = ({
const { onViewFile } = usePath()

return (
<div className="group/file bg-secondary relative mb-2 inline-flex w-60 cursor-pointer gap-x-3 overflow-hidden rounded-lg p-4">
<div className="group/file relative mb-2 inline-flex w-60 cursor-pointer gap-x-3 overflow-hidden rounded-lg bg-[hsla(var(--secondary-bg))] p-4">
<div
className="absolute left-0 top-0 z-20 hidden h-full w-full bg-black/20 opacity-50 group-hover/file:inline-block"
onClick={() => onViewFile(`${id}.pdf`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const RelativeImage = ({
className={onClick ? 'cursor-pointer' : 'cursor-default'}
>
<img
className="aspect-auto h-[300px]"
className="aspect-auto"
alt={src}
src={src.includes('files/') ? `file://${path}/${src}` : src}
/>
Expand Down
Loading