|
|
@ -48,7 +48,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( |
|
|
|
const storedFilesData = ref<{ title: string; file: File }[]>([]) |
|
|
|
const storedFilesData = ref<{ title: string; file: File }[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
/** keep user selected File object */ |
|
|
|
/** keep user selected File object */ |
|
|
|
const storedFiles = ref<File[]>([]) |
|
|
|
const storedFiles = ref<{ title: string; file: File }[]>([]) |
|
|
|
|
|
|
|
|
|
|
|
const attachments = ref<File[]>([]) |
|
|
|
const attachments = ref<File[]>([]) |
|
|
|
|
|
|
|
|
|
|
@ -60,7 +60,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( |
|
|
|
|
|
|
|
|
|
|
|
const { api, isLoading } = useApi() |
|
|
|
const { api, isLoading } = useApi() |
|
|
|
|
|
|
|
|
|
|
|
const { files, open } = useFileDialog() |
|
|
|
const { files, open, reset } = useFileDialog() |
|
|
|
|
|
|
|
|
|
|
|
/** remove a file from our stored attachments (either locally stored or saved ones) */ |
|
|
|
/** remove a file from our stored attachments (either locally stored or saved ones) */ |
|
|
|
function removeFile(i: number) { |
|
|
|
function removeFile(i: number) { |
|
|
@ -81,22 +81,27 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( |
|
|
|
if (!selectedFiles.length || isPublicGrid) return |
|
|
|
if (!selectedFiles.length || isPublicGrid) return |
|
|
|
|
|
|
|
|
|
|
|
if (isPublic.value) { |
|
|
|
if (isPublic.value) { |
|
|
|
storedFiles.value.push(...selectedFiles) |
|
|
|
storedFiles.value.push( |
|
|
|
storedFilesData.value.push( |
|
|
|
|
|
|
|
...(await Promise.all<AttachmentProps>( |
|
|
|
...(await Promise.all<AttachmentProps>( |
|
|
|
Array.from(selectedFiles).map( |
|
|
|
Array.from(selectedFiles).map( |
|
|
|
(file) => |
|
|
|
(file) => |
|
|
|
new Promise<AttachmentProps>((resolve) => { |
|
|
|
new Promise<AttachmentProps>((resolve) => { |
|
|
|
const res: AttachmentProps = { file, title: file.name } |
|
|
|
const res: any = { ...file, file, title: file.name } |
|
|
|
if (isImage(file.name, (file as any).mimetype)) { |
|
|
|
|
|
|
|
|
|
|
|
console.log(res) |
|
|
|
|
|
|
|
if (isImage(file.name, (<any>file).mimetype ?? file.type)) { |
|
|
|
const reader = new FileReader() |
|
|
|
const reader = new FileReader() |
|
|
|
reader.onload = (e: any) => { |
|
|
|
|
|
|
|
|
|
|
|
reader.onload = (e) => { |
|
|
|
res.data = e.target?.result |
|
|
|
res.data = e.target?.result |
|
|
|
|
|
|
|
|
|
|
|
resolve(res) |
|
|
|
resolve(res) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reader.onerror = () => { |
|
|
|
reader.onerror = () => { |
|
|
|
resolve(res) |
|
|
|
resolve(res) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reader.readAsDataURL(file) |
|
|
|
reader.readAsDataURL(file) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
resolve(res) |
|
|
|
resolve(res) |
|
|
@ -106,7 +111,9 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( |
|
|
|
)), |
|
|
|
)), |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return updateModelValue(storedFilesData.value.map((storedFile) => storedFile.file)) |
|
|
|
reset() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return updateModelValue(storedFiles.value.map((next) => next.file)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const newAttachments = [] |
|
|
|
const newAttachments = [] |
|
|
@ -129,6 +136,8 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset() |
|
|
|
|
|
|
|
|
|
|
|
updateModelValue([...attachments.value, ...newAttachments]) |
|
|
|
updateModelValue([...attachments.value, ...newAttachments]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,7 +170,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** our currently visible items, either the locally stored or the ones from db, depending on isPublicForm status */ |
|
|
|
/** our currently visible items, either the locally stored or the ones from db, depending on isPublicForm status */ |
|
|
|
const visibleItems = computed<any[]>(() => [...attachments.value, ...storedFiles.value]) |
|
|
|
const visibleItems = computed<any[]>(() => (isPublic.value ? storedFiles.value : attachments.value)) |
|
|
|
|
|
|
|
|
|
|
|
watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles)) |
|
|
|
watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles)) |
|
|
|
|
|
|
|
|
|
|
|