Skip to content

Commit

Permalink
fix: Memory error fix on file inputs (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carson-Shaar authored Nov 12, 2024
1 parent 196c752 commit 8659ca6
Showing 1 changed file with 22 additions and 32 deletions.
54 changes: 22 additions & 32 deletions zt_frontend/src/components/ComponentWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
// Clear any existing error
clearError(component.id);
component.value = await createFormData(files);
runCode(true, component.id, component.value);
}
Expand Down Expand Up @@ -81,7 +81,6 @@ import {
import { VDataTable } from "vuetify/components/VDataTable";
import TextComponent from "@/components/TextComponent.vue";
import PlotlyPlot from "@/components/PlotlyComponent.vue";
import { Console } from "console";
export default {
components: {
Expand Down Expand Up @@ -112,34 +111,9 @@ export default {
required: true,
},
},
setup() {
const errors = ref<Record<string, { hasError: boolean; message: string }>>({});
const setError = (componentId: string, message: string) => {
errors.value[componentId] = {
hasError: true,
message: message
};
return {
errors,
setError,
clearError,
};
};
const clearError = (componentId: string) => {
if (errors.value[componentId]) {
errors.value[componentId] = {
hasError: false,
message: ''
};
}
};
data() {
return {
errors,
setError,
clearError
errors: {} as Record<string, { hasError: boolean; message: string }>,
};
},
methods: {
Expand Down Expand Up @@ -208,6 +182,22 @@ export default {
this.$emit("runCode", fromComponent, componentId, componentValue);
},
setError(componentId: string, message: string) {
this.errors[componentId] = {
hasError: true,
message: message,
};
},
clearError(componentId: string) {
if (this.errors[componentId]) {
this.errors[componentId] = {
hasError: false,
message: "",
};
}
},
async fileToBase64(file: File) {
const reader = new FileReader();
reader.readAsDataURL(file);
Expand All @@ -227,10 +217,10 @@ export default {
const fileList: { [key: string]: any } = {};
for (const file of files) {
if (file) {
const fileb64 = await this.fileToBase64(file);
fileList[file.name] = fileb64;
const fileb64 = await this.fileToBase64(file);
fileList[file.name] = fileb64;
}
}
}
return fileList;
},
},
Expand Down

0 comments on commit 8659ca6

Please sign in to comment.