added copy OTP feature

This commit is contained in:
Gourav Kumar 2024-06-15 23:41:54 +05:30
parent 8210f4957e
commit 726e8a208a
2 changed files with 26 additions and 24 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -3,13 +3,23 @@
<div class="card-top">
<span class="issuer">{{ issuer }}</span>
<button class="edit-button" @click="editSecret">
<img src="../assets/edit-icon.png" class="edit-icon" /></button
<img src="../assets/edit-icon.png" class="button-icon" /></button
><br />
</div>
<span class="user">{{ username }}</span> <br />
<span class="otp">{{ generateTotp(secret) }}</span>
<div class="timer" id="timer" :style="{ width: timerWidth + '%' }"></div>
<span
class="otp"
@click="copyOtp"
@mouseenter="otpHidden = false"
@mouseleave="otpHidden = true"
>
<span v-if="otpHidden">******</span>
<span v-else>{{ generateTotp(secret) }}</span>
</span>
<button class="edit-button" @click="copyOtp">
<img src="../assets/copy-icon.png" class="button-icon" />
</button>
</div>
</template>
@ -26,9 +36,7 @@ export default {
return {
otp: 123456,
notes: "",
remainingTime: 0,
timerWidth: 0,
totalTime: 30,
otpHidden: true,
};
},
@ -39,17 +47,19 @@ export default {
this.remainingTime = remaining / 1000;
this.timerWidth = remaining * 100;
// console.log("hello");
this.otp = otp;
return otp;
},
startTimer() {
this.interval = setInterval(() => {
if (this.remainingTime > 0) {
this.timerWidth = (this.remainingTime / this.totalTime) * 10;
} else {
clearInterval(this.interval);
}
}, 100);
async copyOtp() {
await navigator.clipboard
.writeText(this.otp)
.then(() => {
console.log("copying successful");
})
.catch((err) => {
console.log("copy failed", err);
});
},
editSecret() {
@ -57,9 +67,7 @@ export default {
},
},
mounted() {
// this.startTimer();
},
mounted() {},
};
</script>
@ -87,12 +95,6 @@ export default {
font-size: 2rem;
}
.timer {
/* width: 100%; */
height: 3px;
background-color: green;
}
.card-top {
display: flex;
justify-content: space-between;
@ -104,7 +106,7 @@ export default {
border: none;
}
.edit-icon {
.button-icon {
width: 16px;
height: 16px;
}