Skip to content

Commit 9b92737

Browse files
committed
fix: show notification banner on successful copy
1 parent 5e95b81 commit 9b92737

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

VINScanner/index.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
margin-top: 1rem;
167167
width: -moz-fit-content;
168168
width: fit-content;
169+
z-index: 2;
169170

170171
/* Fade in animation */
171172
opacity: 0;
@@ -253,7 +254,7 @@ <h3 id="camera-view-title">VIN Scanner</h3>
253254
</div>
254255
<h3 id="scan-title"></h3>
255256
<div style="display: flex; justify-content: center">
256-
<h3 id="notification">Test</h3>
257+
<h3 id="notification"></h3>
257258
</div>
258259
</div>
259260
</div>
@@ -517,6 +518,7 @@ <h3 style="margin: 0">Result</h3>
517518
settingsModal.style.display = "none";
518519

519520
// Show success notification on scan mode switch
521+
notification.className = "";
520522
notification.classList.add("banner-success");
521523
notification.innerText = `Now ${SCAN_MODE_TITLES[mode]}`;
522524
// Fade in animation for notificaiton
@@ -590,14 +592,29 @@ <h3 style="margin: 0">Result</h3>
590592
copyResultButton.addEventListener("click", () => {
591593
const results = document.querySelector("#results").innerText;
592594

595+
// Reset notification
596+
notification.className = "";
597+
593598
navigator.clipboard
594599
.writeText(results)
595600
.then(function () {
596-
console.log("Result copied successfully!");
601+
// Show notification that the result is copied
602+
notification.classList.add("banner-success");
603+
notification.innerText = `Result copied successfully!`;
597604
})
598605
.catch((ex) => {
599606
let errMsg = ex.message || ex;
600607
console.error("Failed to copy result", errMsg);
608+
// Show notification that copy failed
609+
notification.classList.add("banner-error");
610+
notification.innerText = `Failed to copy result.`;
611+
})
612+
.finally(() => {
613+
// Fade in animation for notificaiton
614+
notification.style.opacity = 1;
615+
setTimeout(function () {
616+
notification.style.opacity = 0;
617+
}, 5000);
601618
});
602619
});
603620

0 commit comments

Comments
 (0)