Skip to content

Commit

Permalink
Add file preview functionality in Uploader components
Browse files Browse the repository at this point in the history
  • Loading branch information
swuecho committed Jul 17, 2024
1 parent 8f60c70 commit 8b6d550
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 9 additions & 4 deletions web/src/views/chat/components/Uploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div>
<NUpload multiline :action="actionURL" :headers="headers" :data="data" :default-file-list="fileListData"
:show-download-button="true" @finish="handleFinish" @before-upload="beforeUpload"
@remove="handleRemove" @download="handleDownload" @update:file-list="handleFileListUpdate">
@preview="handlePreview" @remove="handleRemove" @download="handleDownload"
@update:file-list="handleFileListUpdate">

<NButton v-if="showUploaderButton" id="attach_file_button" data-testid="attach_file_button"
type="primary"> {{ $t('chat.uploader_button') }}
Expand Down Expand Up @@ -98,7 +99,6 @@ function handleFinish({ file, event }: { file: UploadFileInfo, event?: ProgressE
}
// @ts-ignore
function handleRemove({ file }: { file: UploadFileInfo }) {
console.log('remove', file)
if (file.url) {
Expand All @@ -113,8 +113,13 @@ function fileUrl(file: UploadFileInfo): string {
const url = `/download/${file_id}`
return url
}
// @ts-ignore
async function handleDownload(file) {
function handlePreview(file: UploadFileInfo, detail: { event: MouseEvent }) {
detail.event.preventDefault()
handleDownload(file)
}
async function handleDownload(file: UploadFileInfo) {
console.log('download', file)
// get last part of file.url
const url = fileUrl(file)
Expand Down
12 changes: 6 additions & 6 deletions web/src/views/chat/components/UploaderReadOnly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function fileUrl(file: UploadFileInfo): string {
return url
}
// @ts-ignore
function handleRemove({ file }: { file: UploadFileInfo }) {
console.log('remove', file)
if (file.url) {
Expand All @@ -110,6 +109,12 @@ function handleRemove({ file }: { file: UploadFileInfo }) {
console.log(file.url)
}
async function handlePreview(file: UploadFileInfo, detail: { event: MouseEvent }) {
detail.event.preventDefault()
await handleDownload(file)
}
// @ts-ignore
async function handleDownload(file) {
console.log('download', file)
Expand Down Expand Up @@ -140,9 +145,4 @@ async function handleDownload(file) {
return false //!!! cancel original download
}
async function handlePreview(file: UploadFileInfo) {
console.log('preview', file)
await handleDownload(file)
return false
}
</script>

0 comments on commit 8b6d550

Please sign in to comment.