forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 style: improve input file upload (lobehub#3314)
* 💄 style: improve input height * 💄 style: improve input height * fix drag
- Loading branch information
Showing
5 changed files
with
84 additions
and
71 deletions.
There are no files selected for viewing
10 changes: 0 additions & 10 deletions
10
...pp/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/LocalFiles.tsx
This file was deleted.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/LocalFiles.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { memo } from 'react'; | ||
|
||
import DragUpload from '@/components/DragUpload'; | ||
import { EditableFileList } from '@/features/FileList'; | ||
import { useAgentStore } from '@/store/agent'; | ||
import { agentSelectors } from '@/store/agent/slices/chat'; | ||
import { useFileStore } from '@/store/file'; | ||
import { useUserStore } from '@/store/user'; | ||
import { modelProviderSelectors } from '@/store/user/selectors'; | ||
|
||
interface LocalFilesProps { | ||
padding?: number | string; | ||
} | ||
|
||
const LocalFiles = memo<LocalFilesProps>(({ padding }) => { | ||
const model = useAgentStore(agentSelectors.currentAgentModel); | ||
|
||
const enabledFiles = useUserStore(modelProviderSelectors.isModelEnabledFiles(model)); | ||
const canUpload = useUserStore(modelProviderSelectors.isModelEnabledUpload(model)); | ||
|
||
const inputFilesList = useFileStore((s) => s.inputFilesList); | ||
const uploadFile = useFileStore((s) => s.uploadFile); | ||
|
||
const uploadImages = async (fileList: FileList | undefined) => { | ||
if (!fileList || fileList.length === 0) return; | ||
|
||
const pools = Array.from(fileList).map(async (file) => { | ||
// skip none-file items | ||
if (!file.type.startsWith('image') && !enabledFiles) return; | ||
await uploadFile(file); | ||
}); | ||
|
||
await Promise.all(pools); | ||
}; | ||
|
||
return ( | ||
canUpload && ( | ||
<> | ||
<DragUpload enabledFiles={enabledFiles} onUploadFiles={uploadImages} /> | ||
<EditableFileList items={inputFilesList} padding={padding ?? 0} /> | ||
</> | ||
) | ||
); | ||
}); | ||
|
||
export default LocalFiles; |
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