Skip to content

Commit

Permalink
Refactor i18n usage on PIN page
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos authored and ReenigneArcher committed May 27, 2024
1 parent b5a40a8 commit 6edb4b0
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src_assets/common/assets/web/pin.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Navbar></Navbar>
<div id="content" class="container">
<h1 class="my-4 text-center">{{ $t('pin.pin_pairing') }}</h1>
<form action="" class="form d-flex flex-column align-items-center" id="form">
<form class="form d-flex flex-column align-items-center" id="form" @submit.prevent="registerDevice">
<div class="card flex-column d-flex p-4 mb-4">
<input type="text" pattern="\d*" :placeholder="`${$t('navbar.pin')}`" autofocus id="pin-input" class="form-control mt-2" required />
<input type="text" :placeholder="`${$t('pin.device_name')}`" id="name-input" class="form-control my-4" required />
Expand All @@ -25,40 +25,38 @@ <h1 class="my-4 text-center">{{ $t('pin.pin_pairing') }}</h1>

<script type="module">
import { createApp } from 'vue'
import i18nLocale from './locale.js'
import { initApp } from './init'
import Navbar from './Navbar.vue'
import {initApp} from "./init";

let app = createApp({
components: {
Navbar
},
inject: ['i18n'],
methods: {
registerDevice(e) {
let pin = document.querySelector("#pin-input").value;
let name = document.querySelector("#name-input").value;
document.querySelector("#status").innerHTML = "";
let b = JSON.stringify({pin: pin, name: name});
fetch("/api/pin", {method: "POST", body: b})
.then((response) => response.json())
.then((response) => {
if (response.status.toString().toLowerCase() === "true") {
document.querySelector(
"#status"
).innerHTML = `<div class="alert alert-success" role="alert">${this.i18n.t('pin.pair_success')}</div>`;
document.querySelector("#pin-input").value = "";
document.querySelector("#name-input").value = "";
} else {
document.querySelector(
"#status"
).innerHTML = `<div class="alert alert-danger" role="alert">${this.i18n.t('pin.pair_failure')}</div>`;
}
});
}
}
});

initApp(app, (async app => {
// this must be after mounting the app
const i18n = await i18nLocale()
document.querySelector("#form").addEventListener("submit", (e) => {
e.preventDefault();
let pin = document.querySelector("#pin-input").value;
let name = document.querySelector("#name-input").value;
document.querySelector("#status").innerHTML = "";
let b = JSON.stringify({ pin: pin, name: name });
fetch("/api/pin", { method: "POST", body: b })
.then((response) => response.json())
.then((response) => {
if (response.status.toString().toLowerCase() === "true") {
document.querySelector(
"#status"
).innerHTML = `<div class="alert alert-success" role="alert">${i18n.global.t('pin.pair_success')}</div>`;
document.querySelector("#pin-input").value = "";
document.querySelector("#name-input").value = "";
} else {
document.querySelector(
"#status"
).innerHTML = `<div class="alert alert-danger" role="alert">${i18n.global.t('pin.pair_failure')}</div>`;
}
});
});
}));
initApp(app);
</script>

0 comments on commit 6edb4b0

Please sign in to comment.