Skip to content

Commit

Permalink
Implement file fetching logic when a value is present
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacornelius committed Oct 25, 2024
1 parent a7bc0f0 commit 0345f49
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/renderer/file-upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export default {
this.removeDefaultClasses();
},
mounted() {
if (this.value) {
this.fetchFiles();
}
this.$root.$on('set-upload-data-name',
(recordList, index, id) => this.listenRecordList(recordList, index, id));
Expand Down Expand Up @@ -621,6 +625,28 @@ export default {
: null;
}
},
async fetchFiles() {
const fileIds = Array.isArray(this.value) ? this.value : [this.value];
const fetchPromises = fileIds.map(async (file) => {
const id = file?.file ?? file;
const endpoint = `files/${id}`;
try {
const response = await ProcessMaker.apiClient.get(endpoint);
if (response?.data) {
const fileExists = this.files.some(existingFile => existingFile.id === response.data.id);
// Check if the file already exists in the list before adding it.
if (!fileExists) {
this.files.push(response.data);
}
}
} catch (error) {
console.error(`Failed to fetch file ${id}`, error);
}
});
return await Promise.all(fetchPromises);
},
},
};
</script>
Expand Down

0 comments on commit 0345f49

Please sign in to comment.