Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/client/JoinPrivateLobbyModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ export class JoinPrivateLobbyModal extends BaseModal {
if (this.leaveLobbyOnClose) {
this.leaveLobby();
// Reset URL to base when modal closes
history.replaceState(null, "", window.location.origin + "/");
const currentHash = window.location.hash;
if (!(currentHash && currentHash.startsWith("#news"))) {
history.replaceState(null, "", window.location.origin + "/");
}
}

this.hasJoined = false;
Expand Down
9 changes: 9 additions & 0 deletions src/client/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import "./Matchmaking";
import { MatchmakingModal } from "./Matchmaking";
import { initNavigation } from "./Navigation";
import "./NewsModal";
import { NewsModal } from "./NewsModal";
import "./PatternInput";
import "./PublicLobby";
import { PublicLobby } from "./PublicLobby";
Expand Down Expand Up @@ -222,6 +223,7 @@ class Client {
private patternsModal: TerritoryPatternsModal;
private tokenLoginModal: TokenLoginModal;
private matchmakingModal: MatchmakingModal;
private newsModal: NewsModal;

private gutterAds: GutterAds;

Expand Down Expand Up @@ -394,6 +396,8 @@ class Client {
console.warn("Territory patterns modal element not found");
}

this.newsModal = document.querySelector("news-modal") as NewsModal;

// We no longer need to manually manage the preview button as PatternInput handles it component-side.
// However, we still want to ensure the modal can be opened.
// The setupPatternInput above handles the click event for the new buttons.
Expand Down Expand Up @@ -743,6 +747,11 @@ class Client {
console.log(`joining lobby ${lobbyId}`);
return;
}

if (decodedHash.startsWith("#news")) {
window.showPage?.("page-news");
}

if (decodedHash.startsWith("#affiliate=")) {
const affiliateCode = decodedHash.replace("#affiliate=", "");
strip();
Expand Down
33 changes: 31 additions & 2 deletions src/client/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ export function initNavigation() {
}
});

// Maintain URL hash for News: set when showing news, clear when navigating away
try {
const h = window.location.hash || "";
if (pageId === "page-news") {
if (!h.startsWith("#news")) {
history.replaceState(
null,
"",
window.location.pathname + window.location.search + "#news",
);
}
} else {
if (h.startsWith("#news")) {
history.replaceState(
null,
"",
window.location.pathname + window.location.search,
);
}
}
} catch (e) {
/* ignore */
}

// Dispatch CustomEvent to notify listeners of page change
window.dispatchEvent(new CustomEvent("showPage", { detail: pageId }));
};
Expand Down Expand Up @@ -106,9 +130,14 @@ export function initNavigation() {
}
});

// Set default page to play if no menu item is active
// Set default page to play (or news if URL hash indicates it) if no menu item is active
const anyActive = document.querySelector(".nav-menu-item.active");
if (!anyActive) {
showPage("page-play");
const h = window.location.hash || "";
if (h.startsWith("#news")) {
showPage("page-news");
} else {
showPage("page-play");
}
}
}
10 changes: 10 additions & 0 deletions src/client/NewsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ export class NewsModal extends BaseModal {
.then((markdown) => (this.markdown = markdown));
}
}

protected onClose(): void {
if (window.location.hash.startsWith("#news")) {
history.replaceState(
null,
"",
window.location.pathname + window.location.search,
);
}
}
}

@customElement("news-button")
Expand Down
7 changes: 6 additions & 1 deletion src/client/components/BaseModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ export abstract class BaseModal extends LitElement {
if (this.inline) {
this.style.pointerEvents = "none";
if (window.showPage) {
window.showPage?.("page-play");
const h = window.location.hash || "";
if (h.startsWith("#news") || h.startsWith("#page-news")) {
window.showPage?.("page-news");
} else {
window.showPage?.("page-play");
}
}
} else {
this.modalEl?.close();
Expand Down
Loading