|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
import './style.css';
|
|
|
|
|
|
|
|
|
|
const IS_SUCCESS = 'is-success';
|
|
|
|
|
const IS_ERROR = 'is-error';
|
|
|
|
|
const DELAY = 1000;
|
|
|
|
|
const CODE = import.meta.env.VITE_KEYPAD_CODE || generateCode(4);
|
|
|
|
|
let builder = '';
|
|
|
|
|
|
|
|
|
@ -18,19 +21,20 @@ function generateCode(len: number): string {
|
|
|
|
|
function resetCode() {
|
|
|
|
|
builder = '';
|
|
|
|
|
display.innerText = '_'.repeat(CODE.length);
|
|
|
|
|
light.classList.remove('is-success', 'is-error');
|
|
|
|
|
light.classList.remove(IS_SUCCESS, IS_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function composeDigit(digit: number) {
|
|
|
|
|
builder += digit.toString();
|
|
|
|
|
display.innerText = builder + '_'.repeat(CODE.length - builder.length);
|
|
|
|
|
if (!CODE.startsWith(builder)) {
|
|
|
|
|
light.classList.add('is-error');
|
|
|
|
|
setTimeout(resetCode, 1000);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (CODE === builder) {
|
|
|
|
|
light.classList.add('is-success');
|
|
|
|
|
if (CODE.startsWith(builder)) {
|
|
|
|
|
light.classList.add(IS_SUCCESS);
|
|
|
|
|
if (builder !== CODE) {
|
|
|
|
|
setTimeout(() => light.classList.remove(IS_SUCCESS), DELAY);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
light.classList.add(IS_ERROR);
|
|
|
|
|
setTimeout(resetCode, DELAY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|