Fix invite link in Join Lobby (#1695)

Closes #1694 

## Description:

Currently when you paste the invitation (
[https://openfront.io#join=QwIr5aK4](https://openfront.io/#join=QwIr5aK4)
) it puts undefined in the input so I made this issue to make a PR and
fix the problem.

<img width="410" height="370" alt="image"
src="https://github.com/user-attachments/assets/d2cf4321-49e3-4e81-987e-66eff2e4d14c"
/>

## 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
- [x] I have read and accepted the CLA agreement (only required once).

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

kipstzz
This commit is contained in:
Kipstz Avenger
2025-08-03 20:49:46 +02:00
committed by GitHub
parent 5690414de6
commit 7eb1bf732d
+16 -13
View File
@@ -135,14 +135,25 @@ export class JoinPrivateLobbyModal extends LitElement {
);
}
private setLobbyId(id: string) {
if (id.startsWith("http")) {
this.lobbyIdInput.value = id.split("join/")[1];
private extractLobbyIdFromUrl(input: string): string {
if (input.startsWith("http")) {
if (input.includes("#join=")) {
const params = new URLSearchParams(input.split("#")[1]);
return params.get("join") ?? input;
} else if (input.includes("join/")) {
return input.split("join/")[1];
} else {
return input;
}
} else {
this.lobbyIdInput.value = id;
return input;
}
}
private setLobbyId(id: string) {
this.lobbyIdInput.value = this.extractLobbyIdFromUrl(id);
}
private handleChange(e: Event) {
const value = (e.target as HTMLInputElement).value.trim();
this.setLobbyId(value);
@@ -151,15 +162,7 @@ export class JoinPrivateLobbyModal extends LitElement {
private async pasteFromClipboard() {
try {
const clipText = await navigator.clipboard.readText();
let lobbyId: string;
if (clipText.startsWith("http")) {
lobbyId = clipText.split("join/")[1];
} else {
lobbyId = clipText;
}
this.lobbyIdInput.value = lobbyId;
this.setLobbyId(clipText);
} catch (err) {
console.error("Failed to read clipboard contents: ", err);
}