1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

userpage: respect 12h/24h choice

This commit is contained in:
Harvey Tindall 2023-06-24 12:32:28 +01:00
parent 753f5fc517
commit fc7ae0ec4e
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
2 changed files with 14 additions and 4 deletions

View File

@ -47,11 +47,12 @@ export class lang implements Lang {
} }
} }
export var TimeFmtChange = new CustomEvent("timefmt-change");
export const loadLangSelector = (page: string) => { export const loadLangSelector = (page: string) => {
if (page == "admin") { if (page == "admin" || "user") {
const ev = new CustomEvent("timefmt-change");
const setTimefmt = (fmt: string) => { const setTimefmt = (fmt: string) => {
document.dispatchEvent(ev); document.dispatchEvent(TimeFmtChange);
localStorage.setItem("timefmt", fmt); localStorage.setItem("timefmt", fmt);
}; };
const t12 = document.getElementById("lang-12h") as HTMLInputElement; const t12 = document.getElementById("lang-12h") as HTMLInputElement;

View File

@ -243,11 +243,16 @@ class ExpiryCard {
private _aside: HTMLElement; private _aside: HTMLElement;
private _countdown: HTMLElement; private _countdown: HTMLElement;
private _interval: number = null; private _interval: number = null;
private _expiryUnix: number = 0;
constructor(card: HTMLElement) { constructor(card: HTMLElement) {
this._card = card; this._card = card;
this._aside = this._card.querySelector(".user-expiry") as HTMLElement; this._aside = this._card.querySelector(".user-expiry") as HTMLElement;
this._countdown = this._card.querySelector(".user-expiry-countdown") as HTMLElement; this._countdown = this._card.querySelector(".user-expiry-countdown") as HTMLElement;
document.addEventListener("timefmt-change", () => {
this.expiry = this._expiryUnix;
});
} }
private _drawCountdown = () => { private _drawCountdown = () => {
@ -297,7 +302,11 @@ class ExpiryCard {
window.clearInterval(this._interval); window.clearInterval(this._interval);
this._interval = null; this._interval = null;
} }
if (expiryUnix == 0) return; this._expiryUnix = expiryUnix;
if (expiryUnix == 0) {
this._card.classList.add("unfocused");
return;
}
this._expiry = new Date(expiryUnix * 1000); this._expiry = new Date(expiryUnix * 1000);
this._aside.textContent = window.lang.strings("yourAccountIsValidUntil").replace("{date}", toDateString(this._expiry)); this._aside.textContent = window.lang.strings("yourAccountIsValidUntil").replace("{date}", toDateString(this._expiry));
this._card.classList.remove("unfocused"); this._card.classList.remove("unfocused");