Skip to content

Commit

Permalink
add servertype filter
Browse files Browse the repository at this point in the history
  • Loading branch information
zefanjajobse committed Nov 25, 2024
1 parent dd3e398 commit 28d10fa
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 13 deletions.
86 changes: 73 additions & 13 deletions src/components/routes/Servers/Search/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function Main(): React.ReactElement {
);

const [regionFilter, setRegionFilter] = React.useState<string[]>(["all"]);
const [serverTypeFilter, setServerTypeFilter] = React.useState<string[]>([]);
const [gamemodeFilter, setGamemodeFilter] = React.useState<string[]>([]);
const [mapFilter, setMapFilter] = React.useState<string[]>([]);
const [playerFilter, setPlayerFilter] = React.useState<string[]>([]);
Expand All @@ -222,6 +223,7 @@ function Main(): React.ReactElement {
setGamemodeFilter([]);
setPlayerFilter([]);
setMapFilter([]);
setServerTypeFilter([]);
setRegionFilter([]);
setIsPasswordProtected("");
setbf2042OwnerList([]);
Expand All @@ -239,6 +241,7 @@ function Main(): React.ReactElement {
const limitQuery = query.get("limit");
const typeQuery = query.get("searchtype");
const gamemodeQuery = query.get("gamemode");
const serverTypeQuery = query.get("server_type");
const mapQuery = query.get("map");
const playerFilterQuery = query.get("player_filter");
const isPasswordProtectedQuery = query.get("is_password_protected");
Expand All @@ -249,6 +252,7 @@ function Main(): React.ReactElement {
gameQuery !== null ? setGameName(gameQuery) : null;
regionQuery !== null ? setRegionFilter(regionQuery.split(",")) : null;
gamemodeQuery !== null ? setGamemodeFilter(gamemodeQuery.split(",")) : null;
serverTypeQuery !== null ? setServerTypeFilter(serverTypeQuery.split(",")) : null;
playerFilterQuery !== null
? setPlayerFilter(playerFilterQuery.split(","))
: null;
Expand Down Expand Up @@ -288,6 +292,9 @@ function Main(): React.ReactElement {
playerFilter.length > 0
? params.append("player_filter", playerFilter.join(","))
: params.delete("player_filter");
serverTypeFilter.length > 0
? params.append("server_type", serverTypeFilter.join(","))
: params.delete("server_type");
bf2042OwnerList.length > 0
? params.append("bf2042_owner_list", JSON.stringify(bf2042OwnerList))
: params.delete("bf2042_owner_list");
Expand All @@ -307,6 +314,7 @@ function Main(): React.ReactElement {
mapFilter,
isPasswordProtected,
playerFilter,
serverTypeFilter,
bf2042OwnerList,
platform,
limit,
Expand All @@ -319,6 +327,7 @@ function Main(): React.ReactElement {
regionFilter.length > 0 ||
gamemodeFilter.length > 0 ||
playerFilter.length > 0 ||
serverTypeFilter.length > 0 ||
mapFilter.length > 0 ||
isPasswordProtected != "" ||
bf2042OwnerList.length > 0
Expand All @@ -337,6 +346,9 @@ function Main(): React.ReactElement {
if (playerFilter.length > 0) {
extraQueries["player_filters"] = playerFilter.join(",");
}
if (serverTypeFilter.length > 0) {
extraQueries["server_type_filters"] = serverTypeFilter.join(",");
}
if (mapFilter.length > 0) {
if (gameName === "bf2042") {
extraQueries["maps"] = mapFilter.join(";");
Expand Down Expand Up @@ -374,13 +386,13 @@ function Main(): React.ReactElement {
} = useQuery({
queryKey: [
"servers" +
gameName +
searchTerm +
searchType +
regionFilter +
platform +
limit +
JSON.stringify(extraQueries),
gameName +
searchTerm +
searchType +
regionFilter +
platform +
limit +
JSON.stringify(extraQueries),
],
queryFn: () =>
GametoolsApi.serverSearch({
Expand Down Expand Up @@ -571,6 +583,54 @@ function Main(): React.ReactElement {
innerStyle={{ maxHeight: width >= 1000 ? "600px" : "300px" }}
>
<div className={styles.serverPageFilters}>
{gameName == "bf1" && (
<div className={styles.serverPageFilterRow}>
<h2 style={{ marginBottom: "0.4rem" }}>
{t("serverSearch.serverTypeFilter")}
<DropdownArrow
item={"serverTypeFilter"}
dropdownOpen={dropdownOpen}
setDropdownOpen={setDropdownOpen}
/>
</h2>
{!dropdownOpen["serverTypeFilter"] &&
Object.keys(
t(`servers.${backendType}.serverTypeFilter`, {
returnObjects: true,
}),
).map((key, index) => {
return (
<CheckItem
key={index}
item={key}
currrentItems={serverTypeFilter}
callback={(e: {
target: {
checked: boolean;
value: string;
};
}) => {
if (e.target.checked) {
setServerTypeFilter((oldArray) => [
...oldArray,
e.target.value,
]);
} else {
setServerTypeFilter((oldArray) => [
...oldArray.filter(
(item) => item !== e.target.value,
),
]);
}
}}
name={t(
`servers.${backendType}.serverTypeFilter.${key}`,
)}
/>
);
})}
</div>
)}
{gameName !== "bf3" && gameName !== "bfh" && (
<div className={styles.serverPageFilterRow}>
<h2 style={{ marginBottom: "0.4rem" }}>
Expand Down Expand Up @@ -844,12 +904,12 @@ export function ServerSearch(): React.ReactElement {
} = useQuery({
queryKey: [
"servers" +
gameName +
searchTerm +
"servername" +
regionFilter +
platform +
"4",
gameName +
searchTerm +
"servername" +
regionFilter +
platform +
"4",
],
queryFn: () =>
GametoolsApi.serverSearch({
Expand Down
7 changes: 7 additions & 0 deletions src/locales/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"platform": "platform",
"gamemode": "Gamemode",
"playerFilter": "Available space",
"serverTypeFilter": "Server type",
"showFilters": "Show filters",
"serverOwner": {
"main": "Server owner",
Expand Down Expand Up @@ -776,6 +777,12 @@
"sixtoten": "6-10",
"tenplus": "10+",
"none": "None"
},
"serverTypeFilter": {
"official": "Official",
"ranked": "Ranked",
"unranked": "Unranked",
"private": "Private"
}
},
"battlelog": {
Expand Down

0 comments on commit 28d10fa

Please sign in to comment.