mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-29 03:44:40 +00:00
df05d21fc2
## Description: Continuation from #3276 Adds the complete client-side clan UI as a Lit web component (`<clan-modal>`), a typed API client with Zod-validated responses, shared response schemas, and a reusable `<confirm-dialog>` component. ### New: `ClanModal.ts` | View | What it does | |------|-------------| | **My Clans** | Lists joined clans + pending join requests (built from `/users/@me`, no extra fetches) | | **Browse** | Search by tag (min 3 chars), paginated results, configurable per-page (10/25/50) | | **Clan Detail** | Stats, paginated + searchable member list, role badges, join/leave/request actions | | **Manage** | Edit name (max 35 chars) + description, toggle open/invite-only, disband | | **Transfer** | Leadership transfer with member selector + confirmation | | **Requests** | Approve/deny join requests (leader/officer) | | **Bans** | View and unban (leader/officer) | | **My Requests** | View and withdraw outgoing requests | ### New: `ConfirmDialog.ts` Reusable `<confirm-dialog>` Lit component — replaces native `confirm()`/`prompt()` which are blocked or broken on mobile and CrazyGames iframes. Supports danger/warning variants and an optional textarea (used for ban reasons). Fires `confirm`/`cancel` events. ### New: `ClanApi.ts` Typed API client covering all clan endpoints. Every response is Zod-validated. Auth header is always last in the spread (can't be overridden by callers). Unknown server error messages always fall back to a generic client-side string — never displayed verbatim. ### New: `ClanApiSchemas.ts` (in `src/core/`) Shared Zod schemas for clan API responses with max-length constraints on `name` (35) and `description` (200). Lives in `core/` so it can be consumed by both client code and the leaderboard table. ### Modified: `ApiSchemas.ts` - Added `clans` and `clanRequests` arrays to `UserMeResponseSchema` - Moved clan leaderboard schemas out to `ClanApiSchemas.ts` - Renamed `LeaderboardClanTagSchema` → `RequiredClanTagSchema` ### Modified: `Api.ts` - Added `invalidateUserMe()` to bust the cached `/users/me` response after mutations - Removed `fetchClanLeaderboard` (moved to `ClanApi.ts`) ### Tests - `ClanModal.test.ts` — rendering, view navigation, user actions - `ClanApiQueries.test.ts` — fetch functions, error handling, pagination - `ClanApiMutations.test.ts` — join, leave, kick, ban, promote, transfer, etc. - `ClanApiBans.test.ts` — ban/unban calls and error paths - `ClanApiSchemas.test.ts` — Zod schema validation edge cases - `LeaderboardModal.test.ts` — updated imports ## Notable design decisions - **Not-logged-in state** — shows "Sign in to join clans" instead of false "no clans" empty state - **Rate limit feedback** — reads `Retry-After` header and surfaces wait time to the user ## 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 --------- Co-authored-by: evanpelle <evanpelle@gmail.com>
209 lines
7.5 KiB
TypeScript
209 lines
7.5 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement } from "lit/decorators.js";
|
|
import { assetUrl } from "../../core/AssetUrls";
|
|
import { NavNotificationsController } from "./NavNotificationsController";
|
|
|
|
@customElement("desktop-nav-bar")
|
|
export class DesktopNavBar extends LitElement {
|
|
private _notifications = new NavNotificationsController(this);
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
|
|
connectedCallback() {
|
|
super.connectedCallback();
|
|
window.addEventListener("showPage", this._onShowPage);
|
|
|
|
const current = window.currentPageId;
|
|
if (current) {
|
|
// Wait for render
|
|
this.updateComplete.then(() => {
|
|
this._updateActiveState(current);
|
|
});
|
|
}
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
super.disconnectedCallback();
|
|
window.removeEventListener("showPage", this._onShowPage);
|
|
}
|
|
|
|
private _onShowPage = (e: Event) => {
|
|
const pageId = (e as CustomEvent).detail;
|
|
this._updateActiveState(pageId);
|
|
};
|
|
|
|
private _updateActiveState(pageId: string) {
|
|
this.querySelectorAll(".nav-menu-item").forEach((el) => {
|
|
if ((el as HTMLElement).dataset.page === pageId) {
|
|
el.classList.add("active");
|
|
} else {
|
|
el.classList.remove("active");
|
|
}
|
|
});
|
|
}
|
|
|
|
render() {
|
|
window.currentPageId ??= "page-play";
|
|
const currentPage = window.currentPageId;
|
|
|
|
return html`
|
|
<nav
|
|
class="hidden lg:flex w-full bg-zinc-900/90 backdrop-blur-md items-center justify-center gap-8 py-4 shrink-0 z-50 relative"
|
|
>
|
|
<div class="flex flex-col items-center justify-center">
|
|
<div class="h-8">
|
|
<img
|
|
class="block h-full aspect-[1364/259]"
|
|
src=${assetUrl("images/OpenFrontLogo.svg")}
|
|
alt="OpenFront"
|
|
/>
|
|
</div>
|
|
<div
|
|
id="game-version"
|
|
class="l-header__highlightText text-center"
|
|
></div>
|
|
</div>
|
|
<button
|
|
class="nav-menu-item ${currentPage === "page-play"
|
|
? "active"
|
|
: ""} text-white/70 hover:text-malibu-blue font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-malibu-blue "
|
|
data-page="page-play"
|
|
data-i18n="main.play"
|
|
></button>
|
|
<!-- Desktop Navigation Menu Items -->
|
|
<div class="relative">
|
|
<button
|
|
class="nav-menu-item ${currentPage === "page-news"
|
|
? "active"
|
|
: ""} text-white/70 hover:text-malibu-blue font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-malibu-blue "
|
|
data-page="page-news"
|
|
data-i18n="main.news"
|
|
@click=${this._notifications.onNewsClick}
|
|
></button>
|
|
${this._notifications.showNewsDot()
|
|
? html`
|
|
<span
|
|
class="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full animate-ping"
|
|
></span>
|
|
<span
|
|
class="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full"
|
|
></span>
|
|
`
|
|
: ""}
|
|
</div>
|
|
<div class="relative no-crazygames">
|
|
<button
|
|
class="nav-menu-item ${currentPage === "page-item-store"
|
|
? "active"
|
|
: ""} text-white/70 hover:text-malibu-blue font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-malibu-blue "
|
|
data-page="page-item-store"
|
|
data-i18n="main.store"
|
|
@click=${this._notifications.onStoreClick}
|
|
></button>
|
|
${this._notifications.showStoreDot()
|
|
? html`
|
|
<span
|
|
class="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full animate-ping"
|
|
></span>
|
|
<span
|
|
class="absolute -top-1 -right-1 w-2 h-2 bg-red-500 rounded-full"
|
|
></span>
|
|
`
|
|
: ""}
|
|
</div>
|
|
<button
|
|
class="nav-menu-item text-white/70 hover:text-malibu-blue font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-malibu-blue "
|
|
data-page="page-settings"
|
|
data-i18n="main.settings"
|
|
></button>
|
|
<button
|
|
class="nav-menu-item text-white/70 hover:text-malibu-blue font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-malibu-blue "
|
|
data-page="page-leaderboard"
|
|
data-i18n="main.leaderboard"
|
|
></button>
|
|
<button
|
|
class="nav-menu-item text-white/70 hover:text-blue-500 font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-blue-500"
|
|
data-page="page-clan"
|
|
data-i18n="main.clans"
|
|
></button>
|
|
<div class="relative">
|
|
<button
|
|
class="nav-menu-item text-white/70 hover:text-malibu-blue font-medium tracking-wider uppercase cursor-pointer transition-colors [&.active]:text-malibu-blue "
|
|
data-page="page-help"
|
|
data-i18n="main.help"
|
|
@click=${this._notifications.onHelpClick}
|
|
></button>
|
|
${this._notifications.showHelpDot()
|
|
? html`
|
|
<span
|
|
class="absolute -top-1 -right-1 w-2 h-2 bg-yellow-400 rounded-full animate-ping"
|
|
></span>
|
|
<span
|
|
class="absolute -top-1 -right-1 w-2 h-2 bg-yellow-400 rounded-full"
|
|
></span>
|
|
`
|
|
: ""}
|
|
</div>
|
|
<button
|
|
id="nav-account-button"
|
|
class="no-crazygames nav-menu-item relative h-10 rounded-full overflow-hidden flex items-center justify-center gap-2 px-3 bg-transparent border border-white/20 text-white/80 hover:text-white cursor-pointer transition-colors [&.active]:text-white"
|
|
data-page="page-account"
|
|
data-i18n-aria-label="main.account"
|
|
data-i18n-title="main.account"
|
|
>
|
|
<img
|
|
id="nav-account-avatar"
|
|
class="no-crazygames hidden w-8 h-8 rounded-full object-cover"
|
|
alt=""
|
|
data-i18n-alt="main.discord_avatar_alt"
|
|
referrerpolicy="no-referrer"
|
|
/>
|
|
<svg
|
|
id="nav-account-person-icon"
|
|
class="w-5 h-5"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="1.5"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
aria-hidden="true"
|
|
>
|
|
<path d="M20 21a8 8 0 0 0-16 0" />
|
|
<path d="M12 13a4 4 0 1 0-4-4 4 4 0 0 0 4 4Z" />
|
|
</svg>
|
|
<span
|
|
id="nav-account-email-badge"
|
|
class="hidden absolute bottom-1 right-1 w-4 h-4 rounded-full bg-slate-900/80 border border-white/20 flex items-center justify-center"
|
|
aria-hidden="true"
|
|
>
|
|
<svg
|
|
class="w-2.5 h-2.5 text-white/80"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 24 24"
|
|
fill="none"
|
|
stroke="currentColor"
|
|
stroke-width="2"
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
>
|
|
<path d="M4 4h16v16H4z" opacity="0" />
|
|
<path d="M4 6h16v12H4z" />
|
|
<path d="m4 7 8 6 8-6" />
|
|
</svg>
|
|
</span>
|
|
<span
|
|
id="nav-account-signin-text"
|
|
class="text-xs font-bold tracking-widest"
|
|
data-i18n="main.sign_in"
|
|
>
|
|
</span>
|
|
</button>
|
|
</nav>
|
|
`;
|
|
}
|
|
}
|