Files
OpenFrontIO/src/client/TokenLoginModal.ts
T
Ryan 70f2abb181 Homepage update & add 3 public lobbies (#3191)
## Description:

Update UI 
check https://homepageupdate.openfront.dev/ 

Improved mobile UI (now fills whole screen for all modals) e.g.:
<img width="432" height="852" alt="image"
src="https://github.com/user-attachments/assets/56de40af-4137-4c57-96b7-3910c9a665b8"
/>

Converted PublicLobby to be "GameModeSelector" to get a nicer 4x4 grid
div, where <GameModeSelector> now handles all the username validation
now (removed redundant code from modals such as matchmaking) also fixed
a bug where someone could have "[XX] X" as thier username (when the
minimum should be 3 chars for their name)

Now visually displays the 3 lobbies ffa/team/special (which is a
continuation from the work done in: #3196 )
<img width="818" height="563" alt="image"
src="https://github.com/user-attachments/assets/a15cd31b-6061-4fb8-83ee-ffde6225cfa7"
/>

updated the background:
<img width="1919" height="807" alt="image"
src="https://github.com/user-attachments/assets/358a7434-51b8-4540-baf2-d1be05053c44"
/>



slightly updated the glassy-look to be less glassy:
<img width="825" height="729" alt="image"
src="https://github.com/user-attachments/assets/1801871b-bbf8-43db-ac53-489337ae80a5"
/>



## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

w.o.n
2026-02-18 23:11:01 -06:00

151 lines
3.8 KiB
TypeScript

import { html } from "lit";
import { customElement } from "lit/decorators.js";
import { tempTokenLogin } from "./Auth";
import { BaseModal } from "./components/BaseModal";
import "./components/Difficulties";
import "./components/PatternButton";
import { modalHeader } from "./components/ui/ModalHeader";
import { translateText } from "./Utils";
@customElement("token-login")
export class TokenLoginModal extends BaseModal {
private isAttemptingLogin = false;
private retryInterval: NodeJS.Timeout | undefined = undefined;
private token: string | null = null;
private email: string | null = null;
private attemptCount = 0;
constructor() {
super();
}
render() {
const title = translateText("token_login_modal.title");
const content = html`
<div class="${this.modalContainerClass}">
${modalHeader({
title,
onBack: () => this.close(),
ariaLabel: translateText("common.back"),
})}
<div class="flex-1 flex flex-col gap-4 p-6">
${this.email ? this.loginSuccess(this.email) : this.loggingIn()}
</div>
</div>
`;
if (this.inline) {
return content;
}
return html`
<o-modal
id="token-login-modal"
title="${title}"
hideHeader
hideCloseButton
maxWidth="620px"
>
${content}
</o-modal>
`;
}
private loggingIn() {
const loggingText = translateText("token_login_modal.logging_in");
return html`
<div class="flex items-center gap-4">
<div
class="w-12 h-12 rounded-full border border-blue-400/40 bg-blue-500/10 flex items-center justify-center"
>
<div
class="w-6 h-6 border-2 border-blue-400/30 border-t-blue-400 rounded-full animate-spin"
></div>
</div>
<div class="flex flex-col gap-2">
<p class="text-lg font-semibold text-white">${loggingText}</p>
<div class="h-1 w-full bg-white/10 rounded-full overflow-hidden">
<div class="h-full w-1/2 bg-blue-400/80 animate-pulse"></div>
</div>
</div>
</div>
`;
}
private loginSuccess(email: string) {
const successText = translateText("token_login_modal.success", { email });
return html`
<div class="flex items-center gap-4">
<div
class="w-12 h-12 rounded-full border border-emerald-400/40 bg-emerald-500/10 flex items-center justify-center"
>
<div class="w-2 h-2 bg-emerald-400 rounded-full animate-pulse"></div>
</div>
<p class="text-base text-white/90">${successText}</p>
</div>
`;
}
public open(): void {
if (!this.token) {
return;
}
super.open();
clearInterval(this.retryInterval);
this.retryInterval = setInterval(() => this.tryLogin(), 3000);
}
public openWithToken(token: string): void {
this.token = token;
this.email = null;
this.attemptCount = 0;
this.isAttemptingLogin = false;
this.open();
}
public close() {
this.token = null;
clearInterval(this.retryInterval);
this.attemptCount = 0;
super.close();
this.isAttemptingLogin = false;
}
private async tryLogin() {
if (this.isAttemptingLogin) {
return;
}
if (this.attemptCount > 3) {
this.close();
alert("Login failed. Please try again later.");
return;
}
this.attemptCount++;
this.isAttemptingLogin = true;
if (this.token === null) {
this.close();
return;
}
try {
this.email = await tempTokenLogin(this.token);
if (!this.email) {
return;
}
clearInterval(this.retryInterval);
setTimeout(() => {
this.close();
window.location.reload();
}, 1000);
this.requestUpdate();
} catch (e) {
console.error(e);
} finally {
this.isAttemptingLogin = false;
}
}
}