Skip to content

Commit

Permalink
added toast
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamJoker committed Aug 20, 2020
1 parent ae80e8a commit d6af039
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 40 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>
</section>
<div class="image-vector"></div>

<div class="toast">Sample message</div>
<script src="index.js"></script>
</body>

Expand Down
79 changes: 48 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const copyURLBtn = document.querySelector("#copyURLBtn");
const fileURL = document.querySelector("#fileURL");
const emailForm = document.querySelector("#emailForm");

const toast = document.querySelector(".toast");

const uploadURL = "http:https://localhost:3000/api/files";
const emailURL = "http:https://localhost:3000/api/files/send";

Expand Down Expand Up @@ -52,42 +54,13 @@ fileInput.addEventListener("change", () => {
copyURLBtn.addEventListener("click", () => {
fileURL.select();
document.execCommand("copy");
showToast("Copied to clipboard");
});

fileURL.addEventListener("click", () => {
fileURL.select();
});

emailForm.addEventListener("submit", (e) => {
e.preventDefault(); // stop submission

// disable the button
emailForm[2].setAttribute("disabled", "true");
emailForm[2].innerText = "Sending";

const url = fileURL.value;

const formData = {
uuid: url.split("/").splice(-1, 1)[0],
emailTo: emailForm.elements["to-email"].value,
emailFrom: emailForm.elements["from-email"].value,
};
console.log(formData);
fetch(emailURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
})
.then((res) => res.json())
.then((data) => {
if (data.success) {
sharingContainer.style.display = "none";
}
});
});

const uploadFile = () => {
console.log("file added uploading");

Expand Down Expand Up @@ -130,12 +103,56 @@ const uploadFile = () => {
const onFileUploadSuccess = (res) => {
fileInput.value = ""; // reset the input
status.innerText = "Uploaded";

// remove the disabled attribute from form btn & make text send
emailForm[2].removeAttribute("disabled");
emailForm[2].innerText = "Send";
progressContainer.style.display = "none";
progressContainer.style.display = "none"; // hide the box

const { file: url } = JSON.parse(res);
console.log(url);
sharingContainer.style.display = "block";
fileURL.value = url;
};

emailForm.addEventListener("submit", (e) => {
e.preventDefault(); // stop submission

// disable the button
emailForm[2].setAttribute("disabled", "true");
emailForm[2].innerText = "Sending";

const url = fileURL.value;

const formData = {
uuid: url.split("/").splice(-1, 1)[0],
emailTo: emailForm.elements["to-email"].value,
emailFrom: emailForm.elements["from-email"].value,
};
console.log(formData);
fetch(emailURL, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
})
.then((res) => res.json())
.then((data) => {
if (data.success) {
showToast("Email Sent");
sharingContainer.style.display = "none"; // hide the box
}
});
});

let toastTimer;
// the toast function
const showToast = (msg) => {
clearTimeout(toastTimer);
toast.innerText = msg;
toast.classList.add("show");
toastTimer = setTimeout(() => {
toast.classList.remove("show");
}, 2000);
};
35 changes: 27 additions & 8 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ body {
font-family: system-ui;
background: var(--main-bg-color);
height: 98vh;
overflow: hidden;
}

.image-vector{
.image-vector {
width: 50vw;
height: 50vh;
background: url(/undraw-upload.svg) no-repeat center;
background-size: contain;

}

body,
Expand Down Expand Up @@ -177,7 +177,6 @@ body,
color: #607d8b;
}


.sharing-container img {
height: 22px;
width: 30px;
Expand All @@ -188,7 +187,7 @@ body,
background: #f5fcff;
}

.email-container form{
.email-container form {
border: 2px solid var(--border-color);
width: 100%;
padding: 15px;
Expand All @@ -198,7 +197,8 @@ body,
flex-direction: column;
align-items: center;
}
.email-container, .send-btn-container {
.email-container,
.send-btn-container {
display: flex;
flex-direction: column;
align-items: center;
Expand All @@ -216,7 +216,7 @@ body,
text-align: center;
}

.email-container input:focus{
.email-container input:focus {
outline: none;
}

Expand All @@ -227,7 +227,7 @@ body,
width: 400px;
}

.send-btn-container button{
.send-btn-container button {
font-size: 18px;
padding: 8px 40px;
margin-top: 15px;
Expand All @@ -236,4 +236,23 @@ body,
border-radius: 5px;
color: #607d8b;
cursor: pointer;
}
}

.toast {
position: absolute;
bottom: 10px;
right: 50%;
transform: translate(50%, 60px);
padding: 10px 20px;
background: var(--light-blue);
color: #fff;
border-radius: 5px;
font-size: 18px;
box-shadow: 0px 10px 15px -3px rgba(0, 0, 0, 0.1),
0px 4px 6px -2px rgba(0, 0, 0, 0.05);
transition: transform ease-in-out 0.2s;
}

.show.toast {
transform:translate(50%, 0);
}

0 comments on commit d6af039

Please sign in to comment.