mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 00:51:56 +00:00
76723e6739
## Description: Noticed things were a bit not centered and title had Modal in it. <img width="643" height="271" alt="image" src="https://github.com/user-attachments/assets/15e113b7-9d77-42d8-8eb0-9b55f8cdbd19" /> <div>↓</div> <img width="643" height="271" alt="image" src="https://github.com/user-attachments/assets/aaa64ede-dd1f-44e3-afde-982bd67a1367" /> <div>---------------------------------------------------------------------------------------------------------------------------</div> <img width="867" height="420" alt="image" src="https://github.com/user-attachments/assets/af545ff4-3d2b-417d-8a96-c8594ffea754" /> <div>↓</div> <img width="867" height="420" alt="image" src="https://github.com/user-attachments/assets/d3380df7-1c78-40be-8dd2-162768773af6" /> ## 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: boostry
117 lines
2.8 KiB
TypeScript
117 lines
2.8 KiB
TypeScript
import { LitElement, css, html } from "lit";
|
|
import { customElement, state } from "lit/decorators.js";
|
|
import { renderPlayerFlag } from "../core/CustomFlag";
|
|
import { FlagSchema } from "../core/Schemas";
|
|
import { translateText } from "./Utils";
|
|
|
|
const flagKey: string = "flag";
|
|
|
|
@customElement("flag-input")
|
|
export class FlagInput extends LitElement {
|
|
@state() public flag: string = "";
|
|
|
|
static styles = css`
|
|
@media (max-width: 768px) {
|
|
.flag-modal {
|
|
width: 80vw;
|
|
}
|
|
|
|
.dropdown-item {
|
|
width: calc(100% / 3 - 15px);
|
|
}
|
|
}
|
|
`;
|
|
|
|
public getCurrentFlag(): string {
|
|
return this.flag;
|
|
}
|
|
|
|
private getStoredFlag(): string {
|
|
const storedFlag = localStorage.getItem(flagKey);
|
|
if (storedFlag) {
|
|
return storedFlag;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
private dispatchFlagEvent() {
|
|
this.dispatchEvent(
|
|
new CustomEvent("flag-change", {
|
|
detail: { flag: this.flag },
|
|
bubbles: true,
|
|
composed: true,
|
|
}),
|
|
);
|
|
}
|
|
|
|
private updateFlag = (ev: Event) => {
|
|
const e = ev as CustomEvent<{ flag: string }>;
|
|
if (!FlagSchema.safeParse(e.detail.flag).success) return;
|
|
if (this.flag !== e.detail.flag) {
|
|
this.flag = e.detail.flag;
|
|
}
|
|
};
|
|
|
|
connectedCallback() {
|
|
super.connectedCallback();
|
|
this.flag = this.getStoredFlag();
|
|
this.dispatchFlagEvent();
|
|
window.addEventListener("flag-change", this.updateFlag as EventListener);
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
super.disconnectedCallback();
|
|
window.removeEventListener("flag-change", this.updateFlag as EventListener);
|
|
}
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<div class="flex relative">
|
|
<button
|
|
id="flag-input_"
|
|
class="border rounded-lg flex cursor-pointer border-black/30
|
|
dark:border-gray-300/60 bg-white/70 dark:bg-[rgba(55,65,81,0.7)]
|
|
"
|
|
title=${translateText("flag_input.button_title")}
|
|
>
|
|
<span
|
|
id="flag-preview"
|
|
style="display:inline-block;
|
|
vertical-align:middle; background:#333; border-radius:6px;
|
|
overflow:hidden;"
|
|
></span>
|
|
</button>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
updated() {
|
|
const preview = this.renderRoot.querySelector(
|
|
"#flag-preview",
|
|
) as HTMLElement;
|
|
if (!preview) return;
|
|
|
|
preview.innerHTML = "";
|
|
|
|
if (this.flag?.startsWith("!")) {
|
|
renderPlayerFlag(this.flag, preview);
|
|
} else {
|
|
const img = document.createElement("img");
|
|
img.src = this.flag ? `/flags/${this.flag}.svg` : `/flags/xx.svg`;
|
|
img.style.width = "100%";
|
|
img.style.height = "100%";
|
|
img.style.objectFit = "contain";
|
|
img.onerror = () => {
|
|
if (!img.src.endsWith("/flags/xx.svg")) {
|
|
img.src = "/flags/xx.svg";
|
|
}
|
|
};
|
|
preview.appendChild(img);
|
|
}
|
|
}
|
|
}
|