mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:30:45 +00:00
Feat/auto copy lobby code (#3758)
Resolves #3757 ## Description: Simple patch that would remove an extra click that users have to do each time they create a private lobby. On top of the existing button, the game link will automatically be copied to the clipboard when clicking "Create Lobby". ## 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: zixer._
This commit is contained in:
@@ -22,7 +22,7 @@ import { generateID } from "../core/Util";
|
||||
import { getPlayToken } from "./Auth";
|
||||
import "./components/baseComponents/Modal";
|
||||
import { BaseModal } from "./components/BaseModal";
|
||||
import "./components/CopyButton";
|
||||
import { CopyButton } from "./components/CopyButton";
|
||||
import "./components/GameConfigSettings";
|
||||
import "./components/LobbyPlayerView";
|
||||
import "./components/ToggleInputCard";
|
||||
@@ -439,6 +439,14 @@ export class HostLobbyModal extends BaseModal {
|
||||
// Note: clientID will be assigned by server when we join the lobby
|
||||
// lobbyCreatorClientID stays empty until then
|
||||
|
||||
// Copy immediately so the host can share the link without waiting for the
|
||||
// server. If lobby creation fails, clear the clipboard to avoid a dead link.
|
||||
void this.constructUrl().then(async (url) => {
|
||||
this.updateHistory(url);
|
||||
await this.updateComplete;
|
||||
void (this.querySelector("copy-button") as CopyButton)?.handleCopy();
|
||||
});
|
||||
|
||||
// Pass auth token for creator identification (server extracts persistentID from it)
|
||||
createLobby(this.lobbyId)
|
||||
.then(async (lobby) => {
|
||||
@@ -447,8 +455,6 @@ export class HostLobbyModal extends BaseModal {
|
||||
throw new Error(`Invalid lobby ID format: ${this.lobbyId}`);
|
||||
}
|
||||
crazyGamesSDK.showInviteButton(this.lobbyId);
|
||||
const url = await this.constructUrl();
|
||||
this.updateHistory(url);
|
||||
})
|
||||
.then(() => {
|
||||
this.dispatchEvent(
|
||||
@@ -461,6 +467,10 @@ export class HostLobbyModal extends BaseModal {
|
||||
composed: true,
|
||||
}),
|
||||
);
|
||||
})
|
||||
.catch(() => {
|
||||
// Clear clipboard so the host doesn't accidentally share a dead link
|
||||
void navigator.clipboard.writeText("").catch(() => {});
|
||||
});
|
||||
if (this.modalEl) {
|
||||
this.modalEl.onClose = () => {
|
||||
|
||||
@@ -80,7 +80,7 @@ export class CopyButton extends LitElement {
|
||||
return await this.buildCopyUrl();
|
||||
}
|
||||
|
||||
private async handleCopy() {
|
||||
async handleCopy() {
|
||||
const text = await this.resolveCopyText();
|
||||
if (!text) {
|
||||
alert("Error copying game id");
|
||||
|
||||
Reference in New Issue
Block a user