Skip to content

Commit 145cb45

Browse files
Fix ac table loading
1 parent 6201819 commit 145cb45

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

frontend/src/routes/_mod.admin.anticheat.tsx

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** biome-ignore-all lint/correctness/noChildrenProp: form needs it */
12
import FilterAltIcon from "@mui/icons-material/FilterAlt";
23
import FilterListIcon from "@mui/icons-material/FilterList";
34
import Button from "@mui/material/Button";
@@ -10,9 +11,13 @@ import Select from "@mui/material/Select";
1011
import { useTheme } from "@mui/material/styles";
1112
import Typography from "@mui/material/Typography";
1213
import { useQuery } from "@tanstack/react-query";
13-
import { createFileRoute, useLoaderData, useNavigate } from "@tanstack/react-router";
14-
import { createColumnHelper, type PaginationState, type SortingState } from "@tanstack/react-table";
15-
import { useCallback, useState } from "react";
14+
import { createFileRoute, useNavigate } from "@tanstack/react-router";
15+
import {
16+
createColumnHelper,
17+
type PaginationState,
18+
type SortingState,
19+
} from "@tanstack/react-table";
20+
import { useCallback, useMemo, useState } from "react";
1621
import { z } from "zod/v4";
1722
import { apiGetAnticheatLogs, apiGetServers } from "../api";
1823
import { ContainerWithHeader } from "../component/ContainerWithHeader.tsx";
@@ -21,15 +26,32 @@ import { PersonCell } from "../component/PersonCell.tsx";
2126
import { FullTable } from "../component/table/FullTable.tsx";
2227
import { TableCellString } from "../component/table/TableCellString.tsx";
2328
import { useAppForm } from "../contexts/formContext.tsx";
24-
import { DetectionCollection, Detections, type StacEntry } from "../schema/anticheat.ts";
25-
import type { ServerSimple } from "../schema/server.ts";
29+
import {
30+
DetectionCollection,
31+
Detections,
32+
type StacEntry,
33+
} from "../schema/anticheat.ts";
2634
import { stringToColour } from "../util/colours.ts";
27-
import { commonTableSearchSchema, initPagination, initSortOrder, RowsPerPage } from "../util/table.ts";
35+
import {
36+
commonTableSearchSchema,
37+
initPagination,
38+
initSortOrder,
39+
RowsPerPage,
40+
} from "../util/table.ts";
2841
import { renderDateTime } from "../util/time.ts";
2942

3043
const searchSchema = commonTableSearchSchema.extend({
3144
sortColumn: z
32-
.enum(["anticheat_id", "name", "personaname", "summary", "detection", "steam_id", "created_on", "server_name"])
45+
.enum([
46+
"anticheat_id",
47+
"name",
48+
"personaname",
49+
"summary",
50+
"detection",
51+
"steam_id",
52+
"created_on",
53+
"server_name",
54+
])
3355
.optional(),
3456
name: z.string().optional(),
3557
summary: z.string().optional(),
@@ -48,7 +70,6 @@ export const Route = createFileRoute("/_mod/admin/anticheat")({
4870
queryFn: apiGetServers,
4971
});
5072
return {
51-
appInfo: context.appInfo,
5273
servers: unsorted.sort((a, b) => {
5374
if (a.server_name > b.server_name) {
5475
return 1;
@@ -61,7 +82,10 @@ export const Route = createFileRoute("/_mod/admin/anticheat")({
6182
};
6283
},
6384
head: ({ match }) => ({
64-
meta: [{ name: "description", content: "Anti-Cheat Logs" }, match.context.title("Anti-Cheat Logs")],
85+
meta: [
86+
{ name: "description", content: "Anti-Cheat Logs" },
87+
match.context.title("Anti-Cheat Logs"),
88+
],
6589
}),
6690
});
6791

@@ -79,10 +103,10 @@ function AdminAnticheat() {
79103
const defaultRows = RowsPerPage.TwentyFive;
80104
const navigate = useNavigate({ from: Route.fullPath });
81105
const search = Route.useSearch();
82-
const { servers } = useLoaderData({ from: "/_mod/admin/anticheat" }) as {
83-
servers: ServerSimple[];
84-
};
85-
const [pagination, setPagination] = useState<PaginationState>(initPagination(search.pageIndex, search.pageSize));
106+
const { servers } = Route.useLoaderData();
107+
const [pagination, setPagination] = useState<PaginationState>(
108+
initPagination(search.pageIndex, search.pageSize),
109+
);
86110
const [sorting] = useState<SortingState>(
87111
initSortOrder(search.sortColumn, search.sortOrder, {
88112
id: "created_on",
@@ -140,17 +164,17 @@ function AdminAnticheat() {
140164
},
141165
});
142166

143-
const clear = async () => {
167+
const clear = useCallback(async () => {
144168
//setColumnFilters([]);
145169
form.reset();
146170
await navigate({
147171
to: "/admin/anticheat",
148172
search: (prev) => ({ ...prev }),
149173
});
150-
};
174+
}, [form, navigate]);
151175

152176
const theme = useTheme();
153-
const columns = useCallback(() => {
177+
const columns = useMemo(() => {
154178
return [
155179
columnHelper.accessor("anticheat_id", {
156180
header: "ID",
@@ -164,7 +188,10 @@ function AdminAnticheat() {
164188
return (
165189
<Button
166190
sx={{
167-
color: stringToColour(info.row.original.server_name, theme.palette.mode),
191+
color: stringToColour(
192+
info.row.original.server_name,
193+
theme.palette.mode,
194+
),
168195
}}
169196
onClick={async () => {
170197
await navigate({
@@ -205,7 +232,9 @@ function AdminAnticheat() {
205232
columnHelper.accessor("created_on", {
206233
header: "Created",
207234
size: 140,
208-
cell: (info) => <TableCellString>{renderDateTime(info.getValue())}</TableCellString>,
235+
cell: (info) => (
236+
<TableCellString>{renderDateTime(info.getValue())}</TableCellString>
237+
),
209238
}),
210239
columnHelper.accessor("demo_id", {
211240
header: "Demo",
@@ -233,7 +262,11 @@ function AdminAnticheat() {
233262
return (
234263
<Grid container spacing={2}>
235264
<Grid size={{ xs: 12 }}>
236-
<ContainerWithHeader title={"Filters"} iconLeft={<FilterListIcon />} marginTop={2}>
265+
<ContainerWithHeader
266+
title={"Filters"}
267+
iconLeft={<FilterListIcon />}
268+
marginTop={2}
269+
>
237270
<form
238271
onSubmit={async (e) => {
239272
e.preventDefault();
@@ -265,7 +298,9 @@ function AdminAnticheat() {
265298
children={({ state, handleChange, handleBlur }) => {
266299
return (
267300
<FormControl fullWidth>
268-
<InputLabel id="server-select-label">Servers</InputLabel>
301+
<InputLabel id="server-select-label">
302+
Servers
303+
</InputLabel>
269304
<Select
270305
fullWidth
271306
value={state.value}
@@ -330,7 +365,10 @@ function AdminAnticheat() {
330365
</ContainerWithHeader>
331366
</Grid>
332367
<Grid size={{ xs: 12 }}>
333-
<ContainerWithHeaderAndButtons title={`Entries`} iconLeft={<FilterAltIcon />}>
368+
<ContainerWithHeaderAndButtons
369+
title={`Entries`}
370+
iconLeft={<FilterAltIcon />}
371+
>
334372
<FullTable<StacEntry>
335373
// columnFilters={columnFilters}
336374
pagination={pagination}

0 commit comments

Comments
 (0)