From 01c90d8f41fad51f3540ca089d08763ad5f856f6 Mon Sep 17 00:00:00 2001 From: nehalist Date: Tue, 13 Feb 2024 23:57:40 +0100 Subject: [PATCH] feat: improve match table --- messages/en.json | 50 ++++++++++++ src/app/[locale]/(home)/recent-matches.tsx | 92 ++++++++++++++++++---- src/components/rating.tsx | 3 + src/components/score.tsx | 7 ++ src/db/schema.ts | 2 + 5 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 src/components/rating.tsx create mode 100644 src/components/score.tsx diff --git a/messages/en.json b/messages/en.json index fbaa29e..cc2161d 100644 --- a/messages/en.json +++ b/messages/en.json @@ -75,5 +75,55 @@ "custom": "Custom", "chess": "Chess", "badminton": "Badminton" + }, + "achievements": { + "wins-1": "First Win", + "wins-10": "10 Wins", + "wins-50": "50 Wins", + "wins-100": "100 Wins", + "wins-500": "500 Wins", + "wins-1000": "1000 Wins", + "elo-range": "Exkarlibur", + "elo-minus300": "It's evolving, just backwards!", + "elo-100": "Getting better", + "elo-200": "Look mom, no hands!", + "elo-300": "Whenever I need expert advice, I talk to myself", + "elo-400": "Call me Magnus Carlsen", + "elo-500": "Kneel before me, mortals!", + "consecutive-wins-5": "I am inevitable", + "consecutive-wins-10": "Behold!", + "consecutive-losses-10": "Are you even trying?", + "matches-1": "First Match", + "matches-10": "10 Matches", + "matches-50": "50 Matches", + "matches-100": "100 Matches", + "matches-500": "500 Matches", + "matches-1000": "I haven't left this place for years", + "score-1": "First point", + "score-10": "10 Points", + "score-100": "100 Points", + "score-1000": "1000 Points", + "score-2500": "2500 Points", + "score-5000": "5000 Points", + "underdog": "Underdog", + "badday": "Bad days happen", + "david": "David", + "goliath": "Goliath", + "weekend-match": "Everyday is work day", + "night-match": "Night shift", + "xmas-match": "Merry Christmas", + "daily-matches-5": "No-stress-day", + "daily-matches-10": "Are you even working?", + "daily-wins-5": "Probably getting paid for this", + "daily-wins-10": "Suffering from success", + "hangover": "Berliner Luft", + "contributor": "I'm doing my part", + "daily-o-clock": "No daily today?", + "threesome": "Have a threesome", + "bad-threesome": "Bad threesome", + "leap-year": "Take a leap", + "trick-or-treat": "Trick or treat", + "diff-max": "Dominator", + "diff-min": "Das tapfere Schneiderlein" } } diff --git a/src/app/[locale]/(home)/recent-matches.tsx b/src/app/[locale]/(home)/recent-matches.tsx index d3b5d5a..ba7ef8a 100644 --- a/src/app/[locale]/(home)/recent-matches.tsx +++ b/src/app/[locale]/(home)/recent-matches.tsx @@ -1,8 +1,12 @@ "use client"; +import { Rating } from "@/components/rating"; import { RatingChange } from "@/components/rating-change"; +import { Score } from "@/components/score"; import { TimeDistance } from "@/components/time-distance"; import { getRecentLeagueMatches } from "@/db/model/match"; +import { Achievement, Team } from "@/db/schema"; +import { Link } from "@/lib/navigation"; import { Table, TableBody, @@ -10,18 +14,70 @@ import { TableColumn, TableHeader, TableRow, + Tooltip, } from "@nextui-org/react"; +import { useTranslations } from "next-intl"; interface RecentMatchesProps { matches: Awaited>; } +function MatchTableTeam({ + team, + matchRating, + matchRatingChange, + matchAchievements, + score, + win, +}: { + team: Team; + matchRating: number; + matchRatingChange: number; + matchAchievements: Achievement[]; + score: number; + win: boolean; +}) { + const emoji = win ? ( + "🏆" + ) : score === 0 ? ( + "✂️" + ) : ( + + 😔 + + ); + const t = useTranslations("achievements"); + const achievements = matchAchievements.map(a => t(a.achievement)).join(", "); + + return ( +
+
{emoji}
+
+

+ {team.name}{" "} +

+
+

+ {" "} + +

+

+ + {achievements} + +

+
+
+
+ ); +} + export function RecentMatches({ matches }: RecentMatchesProps) { return ( Team 1 - Result + Result Team 2 Date @@ -29,23 +85,31 @@ export function RecentMatches({ matches }: RecentMatchesProps) { {match => ( - {match.team1.name}{" "} - {match.achievements - .filter(a => a.teamId === match.team1Id) - .map(a => a.achievement) - .join(", ")} - + a.teamId === match.team1Id, + )} + score={match.score1} + win={match.score1 > match.score2} + /> - {match.score1} {match.score2} + : - {match.team2.name}{" "} - {match.achievements - .filter(a => a.teamId === match.team2Id) - .map(a => a.achievement) - .join(", ")} - + a.teamId === match.team2Id, + )} + score={match.score2} + win={match.score2 > match.score1} + /> diff --git a/src/components/rating.tsx b/src/components/rating.tsx new file mode 100644 index 0000000..857c043 --- /dev/null +++ b/src/components/rating.tsx @@ -0,0 +1,3 @@ +export function Rating({ rating }: { rating: number }) { + return <>{Math.round(rating)}; +} diff --git a/src/components/score.tsx b/src/components/score.tsx new file mode 100644 index 0000000..d2d17f4 --- /dev/null +++ b/src/components/score.tsx @@ -0,0 +1,7 @@ +export function Score({ score }: { score: number }) { + return ( + + {score} + + ); +} diff --git a/src/db/schema.ts b/src/db/schema.ts index 1ac0c49..d78abcd 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -168,6 +168,8 @@ export const achievements = pgTable( }), ); +export type Achievement = typeof achievements.$inferSelect; + export const achievementsRelations = relations( achievements, ({ one, many }) => ({