Skip to content

Commit

Permalink
show currentserver of player in admin mode and reuse serverlist in pl…
Browse files Browse the repository at this point in the history
…atoons and stats page instead of recreating
  • Loading branch information
zefanjajobse committed Nov 28, 2024
1 parent bcc7a37 commit d4677ef
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 130 deletions.
26 changes: 26 additions & 0 deletions src/api/GametoolsApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PlaygroundInfoReturn,
seederPlayersReturn,
ServerLeaderboardReturn,
ServerList,
ServerOwnerResult,
ServerPlayersReturn,
ServerSearch,
Expand Down Expand Up @@ -249,6 +250,31 @@ export class ApiProvider extends JsonClient {
});
}

async currentServer({
game,
playerId,
lang,
platform = "pc",
}: {
game: string;
playerId: number;
lang: string,
platform: string;
}): Promise<{
[playerId: number]: ServerList;
apiUrl: string;
cache: boolean;
} | undefined> {
if (!newTitles.includes(game)) {
return undefined;
}
return await this.getJsonMethod(`/manager/currentserver/${game}`, {
platform: platform,
lang: lang,
player_ids: playerId.toString(),
});
}

async sus({
game,
playerId,
Expand Down
5 changes: 2 additions & 3 deletions src/components/routes/Servers/Search/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ export function Results(props: Views): React.ReactElement {
<Box
spacingStyle={props.spacingStyle}
className="box_hover"
link={`/servers/${props.game}/${idElement}/${result}/${
key.platform || "pc"
}${props.game == "bf2042" ? `?blazeid=${key.blazeGameId}` : ""}`}
link={`/servers/${props.game}/${idElement}/${result}/${key.platform || "pc"
}${props.game == "bf2042" ? `?blazeid=${key.blazeGameId}` : ""}`}
condition={true}
key={index}
innerStyle={props.spacingStyle}
Expand Down
63 changes: 63 additions & 0 deletions src/components/routes/Stats/Player/AdminPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import sslFix from "../../../functions/fixEaAssets";
import { Box } from "../../../Materials";
import { PlatformViews } from "./Main";
import * as styles from "./Main.module.scss";
import * as serverStyles from "../../Servers/Detailed/Main.module.scss";
import { getLanguage } from "../../../../locales/config";
import { Results } from "../../Servers/Search/Results";

function SusWeapon(
props: Readonly<
Expand Down Expand Up @@ -290,6 +293,66 @@ export function AdminPanel(props: Readonly<PlatformViews>): React.ReactElement {
stats={props.stats}
/>
</Box>
<CurrentServer
platform={props.platform}
isLoading={false}
isError={false}
errors={undefined}
game={props.game}
name={props.name}
stats={props.stats} />
</div>
);
}

function CurrentServer(props: Readonly<PlatformViews>) {
const { t } = useTranslation();

const {
isError,
isLoading,
error,
data: stats,
} = useQuery({
queryKey: ["managerCurrentServer" + props?.stats?.id],
queryFn: () =>
GametoolsApi.currentServer({
game: props.game,
lang: getLanguage(),
platform: props.platform,
playerId: props?.stats?.id,
}),
});


if (isError) {
return (
<div className={styles.spacing}>
<h3 className={styles.title}>{t("stats.adminPanel.currentServer")}</h3>
<Box>
<p>{t("stats.error", { error: error })}</p>
</Box>
</div>
);
}

if (isLoading || stats === undefined) {
return (
<div className={styles.spacing}>
<h3 className={styles.title}>{t("stats.adminPanel.currentServer")}</h3>
<Box>
<p>{t("loading")}</p>
</Box>
</div>
);
}

let key = stats[props?.stats?.id];

return (
<div className={styles.spacing}>
<h3 className={styles.title}>{t("stats.adminPanel.currentServer")}</h3>
<Results loading={props.isLoading} error={props.isError} game={props.game} stats={{ "servers": key?.gameId !== null ? [key] : [], apiUrl: stats.apiUrl, cache: stats.cache }} sortType="-prefix" mainPage={false} />
</div>
)
}
169 changes: 42 additions & 127 deletions src/components/routes/platoons/Platoon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import sslFix from "../../functions/fixEaAssets";
import useExternalScript from "../../functions/UseExternalScript";
import { BackButton, Box, ConLink } from "../../Materials";
import * as styles from "./Platoon.module.scss";
import { Results as ServerResults } from "../Servers/Search/Results";

interface Views {
loading: boolean;
Expand Down Expand Up @@ -155,7 +156,7 @@ function Member(props: {
className={styles.memberImage}
src={sslFix(
item?.avatar ||
"https://secure.download.dm.origin.com/production/avatar/prod/1/599/208x208.JPEG",
"https://secure.download.dm.origin.com/production/avatar/prod/1/599/208x208.JPEG",
)}
loading="lazy"
/>
Expand Down Expand Up @@ -262,141 +263,41 @@ function Members(props: {
<div>
{props.loading
? [...Array(6)].map((key) => (
<Member
platform={props.platform}
item={{
id: "loading",
name: t("loading"),
role: "notApplicable",
avatar: "",
}}
key={key}
>
<>&nbsp;</>
</Member>
))
<Member
platform={props.platform}
item={{
id: "loading",
name: t("loading"),
role: "notApplicable",
avatar: "",
}}
key={key}
>
<>&nbsp;</>
</Member>
))
: members.map((key: PlatoonPlayer, index: number) => (
<Member platform={props.platform} item={key} key={index}>
<CheckBan
playerId={key?.id}
checkBanInfo={checkBanInfo}
checkBanLoading={checkBanLoading}
checkBanError={checkBanError}
adminMode={adminMode}
/>
</Member>
))}
<Member platform={props.platform} item={key} key={index}>
<CheckBan
playerId={key?.id}
checkBanInfo={checkBanInfo}
checkBanLoading={checkBanLoading}
checkBanError={checkBanError}
adminMode={adminMode}
/>
</Member>
))}
</div>
</Box>
</div>
);
}

const handleChildElementClick = (e: { stopPropagation: () => void }) => {
e.stopPropagation();
// Do other stuff here
};

function Servers(props: { servers: ServerList[] }): React.ReactElement {
const { t } = useTranslation();
const servers = props.servers;
if (servers?.length <= 0) {
return (
<div className={styles.spacing}>
<h2>{t("platoon.servers")}</h2>
<p className={styles.description}>{t("resultNotFound")}</p>
</div>
);
}
return (
<div className={styles.spacing}>
<div className="align">
<h2 className={styles.title} style={{ marginRight: "1rem" }}>
{t("platoon.servers")}
</h2>
<p style={{ margin: 0, marginBottom: "1rem" }}>
<Trans i18nKey="servers.joinme.info">
<a href="https://joinme.click/download">
https://joinme.click/download
</a>
</Trans>
</p>
</div>
{servers?.map((key: ServerList, index: number) => {
let queue: number = undefined;
queue = key.inQue;
let queueString = "";
if (queue !== undefined && queue !== 0) {
queueString = `[${queue}]`;
}
let region: string = undefined;
if (key.region !== undefined) {
region = ` - ${t(`regions.${key.region.toLowerCase()}`)}`;
}
let officialString = "";
if (key.official !== undefined) {
officialString = key.official
? ` - ${t("serverType.official")}`
: ` - ${t("serverType.custom")}`;
}
return (
<Box
className="box_hover"
link={`/servers/bf1/gameid/${key.gameId}/${key.platform}`}
condition={true}
key={index}
>
<div className="alignServerImg">
<div>
<div
className={styles.serverImage}
style={{ backgroundImage: `url("${sslFix(key.url)}")` }}
>
<div className={styles.blur}>
<h1 className={styles.serverText}>{key.smallMode}</h1>
</div>
</div>
</div>
<div className={styles.serverInfo}>
<h3>
{key.server}
{key.prefix}
</h3>
<p>
{key.playerAmount}/{key.maxPlayers}
{key.maxPlayerAmount} {queueString} - {key.mode}
{key.mode === undefined ? key.map : null}
{officialString}
{region}
</p>
</div>
<a
onClick={(e) => handleChildElementClick(e)}
href={`bf1://${key.gameId}`}
style={{ alignSelf: "end" }}
>
<button
className="bigButtonSecondaryBox"
style={{ marginBottom: ".6rem" }}
type="submit"
>
{t("servers.join")}
</button>
</a>
</div>
</Box>
);
})}
</div>
);
}

function Results(props: Views): React.ReactElement {
const { t } = useTranslation();
const platoon = props.platoon;
document.title = `${t("siteFullName")} ${t("pageTitle.platoon")} | ${
platoon?.name || t("loading")
}`;
document.title = `${t("siteFullName")} ${t("pageTitle.platoon")} | ${platoon?.name || t("loading")
}`;
const ConditionalLink = ({ children, to, condition }: ConLink) =>
!!condition && to ? <Link to={to}>{children}</Link> : <>{children}</>;

Expand Down Expand Up @@ -461,7 +362,21 @@ function Results(props: Views): React.ReactElement {
/>
</div>
<div className="pageRow">
<Servers servers={platoon?.servers} />
<div className={styles.spacing}>
<div className="align">
<h2 className={styles.title} style={{ marginRight: "1rem" }}>
{t("platoon.servers")}
</h2>
<p style={{ margin: 0, marginBottom: "1rem" }}>
<Trans i18nKey="servers.joinme.info">
<a href="https://joinme.click/download">
https://joinme.click/download
</a>
</Trans>
</p>
</div>
<ServerResults loading={props.loading} error={props.error} game={"bf1"} stats={{ "servers": platoon?.servers, cache: platoon?.cache, apiUrl: platoon?.apiUrl }} sortType="-prefix" mainPage={false} />
</div>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/locales/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
"searchGadget": "Search for gadget",
"missingGame": "Current player doesn't have this game",
"adminPanel": {
"currentServer": "Current server",
"main": "Admin panel",
"susWeapons": "Sus weapons",
"bannedServer": {
Expand Down

0 comments on commit d4677ef

Please sign in to comment.