Skip to content
Snippets Groups Projects
Commit b641f8b0 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Improved upload API

parent 508a9bf4
Branches
No related tags found
No related merge requests found
...@@ -30,6 +30,9 @@ element.addEventListener("change", () => { ...@@ -30,6 +30,9 @@ element.addEventListener("change", () => {
image_title.setAttribute("placeholder", "Title"); image_title.setAttribute("placeholder", "Title");
image_container.appendChild(image_title); image_container.appendChild(image_title);
const image_link = document.createElement("a");
image_link.classList.add("image");
const image_progress = document.createElement("div"); const image_progress = document.createElement("div");
image_progress.classList.add("progress"); image_progress.classList.add("progress");
...@@ -37,13 +40,12 @@ element.addEventListener("change", () => { ...@@ -37,13 +40,12 @@ element.addEventListener("change", () => {
image_progress_indeterminate.classList.add("indeterminate"); image_progress_indeterminate.classList.add("indeterminate");
image_progress.appendChild(image_progress_indeterminate); image_progress.appendChild(image_progress_indeterminate);
image_container.appendChild(image_progress); image_link.appendChild(image_progress);
const image_link = document.createElement("a");
image_link.classList.add("image");
const image = document.createElement("img"); const image = document.createElement("img");
image.src = dataUrl; image.src = dataUrl;
image_link.appendChild(image); image_link.appendChild(image);
image_container.appendChild(image_link); image_container.appendChild(image_link);
const image_description = document.createElement("p"); const image_description = document.createElement("p");
...@@ -60,6 +62,7 @@ element.addEventListener("change", () => { ...@@ -60,6 +62,7 @@ element.addEventListener("change", () => {
data.append("file", file, file.name); data.append("file", file, file.name);
postData("/upload/", data).then((json) => { postData("/upload/", data).then((json) => {
image_container.classList.remove("uploading");
if (json.success) { if (json.success) {
image_link.href = "/" + json.id; image_link.href = "/" + json.id;
image.src = "/" + json.id; image.src = "/" + json.id;
...@@ -68,7 +71,6 @@ element.addEventListener("change", () => { ...@@ -68,7 +71,6 @@ element.addEventListener("change", () => {
image_error.classList.add("alert", "error"); image_error.classList.add("alert", "error");
image_error.innerText = JSON.stringify(json.errors); image_error.innerText = JSON.stringify(json.errors);
image_container.insertBefore(image_error, image_description); image_container.insertBefore(image_error, image_description);
image_container.classList.remove("uploading");
} }
console.log(json); console.log(json);
......
...@@ -148,7 +148,9 @@ ...@@ -148,7 +148,9 @@
border-top-left-radius: 4px border-top-left-radius: 4px
border-top-right-radius: 4px border-top-right-radius: 4px
.progress .progress
position: relative top: -4px
left: 0
right: 0
height: 4px height: 4px
display: block display: block
background-color: rgba(255, 193, 7, 0.2) background-color: rgba(255, 193, 7, 0.2)
...@@ -176,13 +178,14 @@ ...@@ -176,13 +178,14 @@
animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite animation: indeterminate-short 2.1s cubic-bezier(0.165, 0.84, 0.44, 1) infinite
animation-delay: 1.125s animation-delay: 1.125s
&:not(.uploading) .progress &:not(.uploading) .progress
display: none opacity: 0
.image .image
background: #000 background: #000
display: flex display: flex
flex-direction: row flex-direction: row
justify-content: center justify-content: center
align-items: start align-items: start
position: absolute
img img
max-width: 100% max-width: 100%
.description .description
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment