Skip to content

Commit

Permalink
fixup! Add front-end for image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Apr 25, 2024
1 parent 4b21934 commit 46dac2e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion arches/app/src/components/ControlledListManager/ItemEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "@/components/ControlledListManager/const.ts";
import { bestLabel } from "@/components/ControlledListManager/utils.ts";
import type { FileUploadBeforeSendEvent } from "primevue/fileupload";
import type { FileUploadBeforeSendEvent, FileUploadUploadEvent } from "primevue/fileupload";
import type { ControlledListItem, Label, NewLabel } from "@/types/ControlledListManager";
const { displayedRow: item } = inject(displayedRowKey);
Expand Down Expand Up @@ -55,6 +55,14 @@ const addHeader = (event: FileUploadBeforeSendEvent) => {
event.xhr.setRequestHeader("X-CSRFToken", Cookies.get("csrftoken"));
event.formData.set("item_id", item.value.id);
};
const onUpload = (event: FileUploadUploadEvent) => {
if (event.xhr.status !== 201) {
return;
}
const newImage = JSON.parse(event.xhr.responseText);
item.value.images.push(newImage);
};
</script>

<template>
Expand Down Expand Up @@ -121,6 +129,7 @@ const addHeader = (event: FileUploadBeforeSendEvent) => {
:with-credentials="true"
name="item_image"
@before-send="addHeader($event)"
@upload="onUpload($event)"
/>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion arches/app/views/controlled_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def add_new_image(self, request):
value=uploaded_file,
)
img.save()
return JSONResponse(status=201)
return JSONResponse(serialize(img), status=201)

def post(self, request, **kwargs):
if not (image_id := kwargs.get("id", None)):
Expand Down

0 comments on commit 46dac2e

Please sign in to comment.