Skip to content

Commit

Permalink
Fix Results Page (#29)
Browse files Browse the repository at this point in the history
* Fix bug in results page

* fix ui

* Fix test

* Update and generate tailwind

* Update tsconfig
  • Loading branch information
enkoder authored Jul 15, 2024
1 parent 29164fa commit 2f85a40
Show file tree
Hide file tree
Showing 13 changed files with 1,298 additions and 1,291 deletions.
12 changes: 6 additions & 6 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@cloudflare/itty-router-openapi": "^1.1.1",
"@microlabs/otel-cf-workers": "1.0.0-rc.15",
"@opentelemetry/api": "1.4.0",
"@sentry/cli": "^2.32.1",
"@sentry/cli": "^2.32.2",
"@tsndr/cloudflare-worker-jwt": "^2.5.3",
"date-fns": "^2.30.0",
"itty-router": "^4.2.2",
Expand All @@ -30,19 +30,19 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"@cloudflare/workers-types": "^4.20240712.0",
"@jest/types": "^29.6.3",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
"@types/node": "^20.14.10",
"@types/object-hash": "^3.0.6",
"@types/react-syntax-highlighter": "^15.5.13",
"eslint-plugin-import": "^2.29.1",
"jest": "^29.7.0",
"kysely": "^0.26.3",
"miniflare": "^3.20240620.0",
"ts-jest": "^29.1.5",
"miniflare": "^3.20240701.0",
"ts-jest": "^29.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"wrangler": "^3.62.0"
"wrangler": "^3.64.0"
}
}
12 changes: 6 additions & 6 deletions api/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,13 @@ export const RecalculateLeaderboardSchema = {

export const UserResultsResponseComponent = z
.object({
user_name: z.string(),
user_id: z.number(),
userName: z.string(),
userId: z.number(),
rank: z.number(),
seasonId: z.number().optional(),
seasonName: z.string().optional(),
format: FormatComponent.optional(),
factionCode: z.string().optional(),
seasonId: z.number().optional().nullable(),
seasonName: z.string().optional().nullable(),
format: FormatComponent.optional().nullable(),
factionCode: z.string().optional().nullable(),
results: z.array(ResultComponent),
})
.openapi("UserResultsResponse");
Expand Down
23 changes: 13 additions & 10 deletions api/src/routes/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ResultComponent,
type UpdateUserComponentType,
UserComponent,
UserResultsResponseComponent,
} from "../openapi.js";
import type { FactionCode, Format } from "../schema.js";
import type { Env, RequestWithDB } from "../types.d.js";
Expand Down Expand Up @@ -133,15 +134,17 @@ export class GetUserResults extends OpenAPIRoute {
}
}

return json({
user_id: user.id,
user_name: user.name,
season_id: seasonId || null,
seasonName: seasonName,
format: format,
factionCode: faction?.code || null,
rank: currentRank,
results: results.map((result) => ResultComponent.parse(result)),
});
return json(
UserResultsResponseComponent.parse({
userId: user.id,
userName: user.name,
seasonId: seasonId === undefined ? null : seasonId,
seasonName: seasonName,
format: format,
factionCode: faction?.code || null,
rank: currentRank,
results: results.map((result) => ResultComponent.parse(result)),
}),
);
}
}
7 changes: 3 additions & 4 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"extends": "../tsconfig.json",
"include": [
"src/*",
"../node_modules/.pnpm/@nora-soderlund+cloudflare-d1-backups@1.2.0/node_modules/@nora-soderlund/cloudflare-d1-backups/example/global.d.ts"
"src/*"
],
"compilerOptions": {
"target": "ES6",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"removeComments": true,
"inlineSourceMap": true,
Expand Down
20 changes: 10 additions & 10 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
"@cloudflare/workers-types": "^4.20240712.0",
"@svgr/webpack": "^8.1.0",
"@tailwindcss/typography": "^0.5.13",
"@types/react": "18.2.0",
Expand All @@ -28,32 +28,32 @@
"prop-types": "^15.8.1",
"react-scripts": "^5.0.1",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.4.4",
"tailwindcss": "^3.4.5",
"typescript": "^4.9.5",
"webpack": "^5.92.1",
"wrangler": "^3.62.0"
"webpack": "^5.93.0",
"wrangler": "^3.64.0"
},
"dependencies": {
"@floating-ui/react": "^0.26.19",
"@fontsource/inter": "^5.0.18",
"@fontsource/inter": "^5.0.19",
"@fontsource/jetbrains-mono": "^5.0.20",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/react-fontawesome": "^0.2.2",
"@headlessui/react": "^1.7.19",
"@heroicons/react": "^2.1.4",
"@tanstack/react-query": "^5.49.2",
"@types/node": "^20.14.9",
"@heroicons/react": "^2.1.5",
"@tanstack/react-query": "^5.51.1",
"@types/node": "^20.14.10",
"clsx": "^2.1.1",
"init": "^0.1.2",
"install": "^0.13.0",
"mathjs": "^12.4.3",
"moment": "^2.30.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.24.0",
"react-router-dom": "^6.24.1",
"react-syntax-highlighter": "^15.5.0",
"tailwind-merge": "^2.3.0",
"tailwind-merge": "^2.4.0",
"web-vitals": "^2.1.4"
},
"browserslist": {
Expand Down
4 changes: 2 additions & 2 deletions app/src/client/models/UserResultsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { Format } from './Format';
import type { Result } from './Result';

export type UserResultsResponse = {
user_name: string;
user_id: number;
userName: string;
userId: number;
rank: number;
seasonId?: number;
seasonName?: string;
Expand Down
17 changes: 9 additions & 8 deletions app/src/components/FilterSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ export function FilterSection({
});

useEffect(() => {
if (
(values.seasonId === undefined || values.seasonId > -1) &&
seasons &&
startSeason > -1
) {
const initialSeason =
seasons.find((s) => s.id === startSeason) || EMPTY_SEASON;
handleFilterChange("seasonId", initialSeason.id);
if (seasons === undefined) return;

let seasonId: number | null = null;
// No season selected, use default given
if (values.seasonId === undefined && startSeason > -1) {
seasonId = startSeason;
} else if (values.seasonId !== undefined && values.seasonId > -1) {
seasonId = values.seasonId;
}
handleFilterChange("seasonId", seasonId);
}, [seasons, startSeason]);

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
Expand Down
10 changes: 1 addition & 9 deletions app/src/output.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/routes/leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function ExpandedSection({
<TooltipTrigger asChild={true}>
<tr
className={"text-left"}
key={`${results.user_id}/${result.tournament_id}`}
key={`${results.userId}/${result.tournament_id}`}
>
<td
className={clsx(
Expand Down
4 changes: 2 additions & 2 deletions app/src/routes/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function Results() {
<div className={"mb-4"}>
{results && (
<>
<PageHeading text={results.user_name} includeUnderline={true} />
<PageHeading text={results.userName} includeUnderline={true} />
{results.results.length === 0 ? (
<text className={"text-gray-400 text-lg"}>
No results found for search filters
Expand Down Expand Up @@ -159,7 +159,7 @@ export function Results() {
<TooltipTrigger asChild={true}>
<tr
className={"text-left even:bg-slate-950 odd:bg-slate-900"}
key={`${results.user_id}/${result.tournament_id}`}
key={`${results.userId}/${result.tournament_id}`}
>
<td className={"whitespace-pre-wrap py-2"}>
<span>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
"lint-staged": "^15.2.7",
"nodemon": "^3.1.4",
"openapi-typescript-codegen": "^0.25.0",
"pm2": "^5.4.1",
"pm2": "^5.4.2",
"pre-commit": "^1.2.2",
"prettier": "^3.3.2",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.5.14",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"wrangler": "^3.62.0"
"wrangler": "^3.64.0"
}
}
Loading

0 comments on commit 2f85a40

Please sign in to comment.