use the new prettier config and add a network offline loader
Some checks failed
Deploy / deploy (push) Failing after 2m17s
Some checks failed
Deploy / deploy (push) Failing after 2m17s
This commit is contained in:
parent
f32c329eb1
commit
f38925c113
@ -2,5 +2,6 @@ NEXT_PUBLIC_SITE_URL=http://localhost:3000
|
|||||||
NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY=
|
NEXT_PUBLIC_TRIGGER_PUBLIC_API_KEY=
|
||||||
|
|
||||||
TRIGGER_API_KEY=
|
TRIGGER_API_KEY=
|
||||||
TRIGGER_API_URL=https://trigger.fascinated.cc
|
TRIGGER_API_URL=https://trigger.example.com
|
||||||
MONGO_URI=mongodb://127.0.0.1:27017
|
MONGO_URI=mongodb://127.0.0.1:27017
|
||||||
|
SENTRY_AUTH_TOKEN=
|
||||||
|
12
.prettierrc.json
Normal file
12
.prettierrc.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"singleQuote": false,
|
||||||
|
"trailingComma": "es5",
|
||||||
|
"printWidth": 120,
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"jsxSingleQuote": false,
|
||||||
|
"jsxBracketSameLine": false
|
||||||
|
}
|
@ -24,6 +24,7 @@
|
|||||||
"@trigger.dev/nextjs": "^3.0.8",
|
"@trigger.dev/nextjs": "^3.0.8",
|
||||||
"@trigger.dev/react": "^3.0.8",
|
"@trigger.dev/react": "^3.0.8",
|
||||||
"@trigger.dev/sdk": "^3.0.8",
|
"@trigger.dev/sdk": "^3.0.8",
|
||||||
|
"@uidotdev/usehooks": "^2.4.1",
|
||||||
"canvas": "3.0.0-rc2",
|
"canvas": "3.0.0-rc2",
|
||||||
"chart.js": "^4.4.4",
|
"chart.js": "^4.4.4",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
|
15
pnpm-lock.yaml
generated
15
pnpm-lock.yaml
generated
@ -53,6 +53,9 @@ importers:
|
|||||||
'@trigger.dev/sdk':
|
'@trigger.dev/sdk':
|
||||||
specifier: ^3.0.8
|
specifier: ^3.0.8
|
||||||
version: 3.0.9
|
version: 3.0.9
|
||||||
|
'@uidotdev/usehooks':
|
||||||
|
specifier: ^2.4.1
|
||||||
|
version: 2.4.1(react-dom@19.0.0-rc-3edc000d-20240926(react@19.0.0-rc-3edc000d-20240926))(react@19.0.0-rc-3edc000d-20240926)
|
||||||
canvas:
|
canvas:
|
||||||
specifier: 3.0.0-rc2
|
specifier: 3.0.0-rc2
|
||||||
version: 3.0.0-rc2
|
version: 3.0.0-rc2
|
||||||
@ -1440,6 +1443,13 @@ packages:
|
|||||||
resolution: {integrity: sha512-c6EIQRHhcpl6+tO8EMR+kjkkV+ugUNXOmeASA1rlzkd8EPIriavpWoiEz1HR/VLhbVIdhqnV6E7JZm00cBDx2A==}
|
resolution: {integrity: sha512-c6EIQRHhcpl6+tO8EMR+kjkkV+ugUNXOmeASA1rlzkd8EPIriavpWoiEz1HR/VLhbVIdhqnV6E7JZm00cBDx2A==}
|
||||||
engines: {node: ^16.0.0 || >=18.0.0}
|
engines: {node: ^16.0.0 || >=18.0.0}
|
||||||
|
|
||||||
|
'@uidotdev/usehooks@2.4.1':
|
||||||
|
resolution: {integrity: sha512-1I+RwWyS+kdv3Mv0Vmc+p0dPYH0DTRAo04HLyXReYBL9AeseDWUJyi4THuksBJcu9F0Pih69Ak150VDnqbVnXg==}
|
||||||
|
engines: {node: '>=16'}
|
||||||
|
peerDependencies:
|
||||||
|
react: '>=18.0.0'
|
||||||
|
react-dom: '>=18.0.0'
|
||||||
|
|
||||||
'@ungap/structured-clone@1.2.0':
|
'@ungap/structured-clone@1.2.0':
|
||||||
resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==}
|
resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==}
|
||||||
|
|
||||||
@ -5106,6 +5116,11 @@ snapshots:
|
|||||||
'@typescript-eslint/types': 7.2.0
|
'@typescript-eslint/types': 7.2.0
|
||||||
eslint-visitor-keys: 3.4.3
|
eslint-visitor-keys: 3.4.3
|
||||||
|
|
||||||
|
'@uidotdev/usehooks@2.4.1(react-dom@19.0.0-rc-3edc000d-20240926(react@19.0.0-rc-3edc000d-20240926))(react@19.0.0-rc-3edc000d-20240926)':
|
||||||
|
dependencies:
|
||||||
|
react: 19.0.0-rc-3edc000d-20240926
|
||||||
|
react-dom: 19.0.0-rc-3edc000d-20240926(react@19.0.0-rc-3edc000d-20240926)
|
||||||
|
|
||||||
'@ungap/structured-clone@1.2.0': {}
|
'@ungap/structured-clone@1.2.0': {}
|
||||||
|
|
||||||
'@webassemblyjs/ast@1.12.1':
|
'@webassemblyjs/ast@1.12.1':
|
||||||
|
@ -8,10 +8,7 @@ export async function GET(request: NextRequest) {
|
|||||||
const playerIdCookie = request.cookies.get("playerId");
|
const playerIdCookie = request.cookies.get("playerId");
|
||||||
const id = request.nextUrl.searchParams.get("id");
|
const id = request.nextUrl.searchParams.get("id");
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return NextResponse.json(
|
return NextResponse.json({ error: "Unknown player. Missing: ?id=" }, { status: 400 });
|
||||||
{ error: "Unknown player. Missing: ?id=" },
|
|
||||||
{ status: 400 },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const shouldCreatePlayer = playerIdCookie?.value === id;
|
const shouldCreatePlayer = playerIdCookie?.value === id;
|
||||||
|
|
||||||
|
@ -6,10 +6,7 @@ import { PlayerTrackedSince } from "@/common/player/player-tracked-since";
|
|||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const id = request.nextUrl.searchParams.get("id");
|
const id = request.nextUrl.searchParams.get("id");
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return NextResponse.json(
|
return NextResponse.json({ error: "Unknown player. Missing: ?id=" }, { status: 400 });
|
||||||
{ error: "Unknown player. Missing: ?id=" },
|
|
||||||
{ status: 400 },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
await connectMongo(); // Connect to Mongo
|
await connectMongo(); // Connect to Mongo
|
||||||
|
|
||||||
|
@ -21,8 +21,7 @@ export async function GET(request: NextRequest) {
|
|||||||
const { status, headers } = response;
|
const { status, headers } = response;
|
||||||
if (
|
if (
|
||||||
!headers.has("content-type") ||
|
!headers.has("content-type") ||
|
||||||
(headers.has("content-type") &&
|
(headers.has("content-type") && !headers.get("content-type")?.includes("application/json"))
|
||||||
!headers.get("content-type")?.includes("application/json"))
|
|
||||||
) {
|
) {
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
error: "We only support proxying JSON responses",
|
error: "We only support proxying JSON responses",
|
||||||
@ -42,7 +41,7 @@ export async function GET(request: NextRequest) {
|
|||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,7 @@ type Props = {
|
|||||||
* @param fetchScores whether to fetch the scores
|
* @param fetchScores whether to fetch the scores
|
||||||
* @returns the player data and scores
|
* @returns the player data and scores
|
||||||
*/
|
*/
|
||||||
const getPlayerData = cache(
|
const getPlayerData = cache(async ({ params }: Props, fetchScores: boolean = true) => {
|
||||||
async ({ params }: Props, fetchScores: boolean = true) => {
|
|
||||||
const { slug } = await params;
|
const { slug } = await params;
|
||||||
const id = slug[0]; // The players id
|
const id = slug[0]; // The players id
|
||||||
const sort: ScoreSort = (slug[1] as ScoreSort) || "recent"; // The sorting method
|
const sort: ScoreSort = (slug[1] as ScoreSort) || "recent"; // The sorting method
|
||||||
@ -57,8 +56,7 @@ const getPlayerData = cache(
|
|||||||
player: player,
|
player: player,
|
||||||
scores: scores,
|
scores: scores,
|
||||||
};
|
};
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
export async function generateMetadata(props: Props): Promise<Metadata> {
|
export async function generateMetadata(props: Props): Promise<Metadata> {
|
||||||
const { player } = await getPlayerData(props, false);
|
const { player } = await getPlayerData(props, false);
|
||||||
@ -123,13 +121,7 @@ export default async function Search(props: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full w-full">
|
<div className="flex flex-col h-full w-full">
|
||||||
<PlayerData
|
<PlayerData initialPlayerData={player} initialScoreData={scores} initialSearch={search} sort={sort} page={page} />
|
||||||
initialPlayerData={player}
|
|
||||||
initialScoreData={scores}
|
|
||||||
initialSearch={search}
|
|
||||||
sort={sort}
|
|
||||||
page={page}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,7 @@ import * as Sentry from "@sentry/nextjs";
|
|||||||
import NextError from "next/error";
|
import NextError from "next/error";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function GlobalError({
|
export default function GlobalError({ error }: { error: Error & { digest?: string } }) {
|
||||||
error,
|
|
||||||
}: {
|
|
||||||
error: Error & { digest?: string };
|
|
||||||
}) {
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Sentry.captureException(error);
|
Sentry.captureException(error);
|
||||||
}, [error]);
|
}, [error]);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import "./globals.css";
|
||||||
import Footer from "@/components/footer";
|
import Footer from "@/components/footer";
|
||||||
import { PreloadResources } from "@/components/preload-resources";
|
import { PreloadResources } from "@/components/preload-resources";
|
||||||
import { QueryProvider } from "@/components/providers/query-provider";
|
import { QueryProvider } from "@/components/providers/query-provider";
|
||||||
@ -10,13 +11,12 @@ import localFont from "next/font/local";
|
|||||||
import BackgroundImage from "../components/background-image";
|
import BackgroundImage from "../components/background-image";
|
||||||
import DatabaseLoader from "../components/loaders/database-loader";
|
import DatabaseLoader from "../components/loaders/database-loader";
|
||||||
import NavBar from "../components/navbar/navbar";
|
import NavBar from "../components/navbar/navbar";
|
||||||
|
|
||||||
import "./globals.css";
|
|
||||||
import { Colors } from "@/common/colors";
|
import { Colors } from "@/common/colors";
|
||||||
|
import OfflineNetwork from "@/components/offline-network";
|
||||||
|
|
||||||
const siteFont = localFont({
|
const siteFont = localFont({
|
||||||
src: "./fonts/JetBrainsMono.ttf",
|
src: "./fonts/JetBrainsMono.ttf",
|
||||||
weight: "100 400",
|
weight: "100 300",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
@ -48,14 +48,12 @@ export const metadata: Metadata = {
|
|||||||
"Stream enhancement, Professional overlay, Easy to use overlay builder.",
|
"Stream enhancement, Professional overlay, Easy to use overlay builder.",
|
||||||
openGraph: {
|
openGraph: {
|
||||||
title: "Scoresaber Reloaded",
|
title: "Scoresaber Reloaded",
|
||||||
description:
|
description: "Scoresaber Reloaded is a new way to view your scores and get more stats about your and your plays",
|
||||||
"Scoresaber Reloaded is a new way to view your scores and get more stats about your and your plays",
|
|
||||||
url: "https://ssr.fascinated.cc",
|
url: "https://ssr.fascinated.cc",
|
||||||
locale: "en_US",
|
locale: "en_US",
|
||||||
type: "website",
|
type: "website",
|
||||||
},
|
},
|
||||||
description:
|
description: "Scoresaber Reloaded is a new way to view your scores and get more stats about your and your plays",
|
||||||
"Scoresaber Reloaded is a new way to view your scores and get more stats about your and your plays",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const viewport: Viewport = {
|
export const viewport: Viewport = {
|
||||||
@ -75,12 +73,8 @@ export default function RootLayout({
|
|||||||
<BackgroundImage />
|
<BackgroundImage />
|
||||||
<PreloadResources />
|
<PreloadResources />
|
||||||
<TooltipProvider delayDuration={100}>
|
<TooltipProvider delayDuration={100}>
|
||||||
<ThemeProvider
|
<OfflineNetwork>
|
||||||
attribute="class"
|
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem disableTransitionOnChange>
|
||||||
defaultTheme="dark"
|
|
||||||
enableSystem
|
|
||||||
disableTransitionOnChange
|
|
||||||
>
|
|
||||||
<QueryProvider>
|
<QueryProvider>
|
||||||
<AnimatePresence>
|
<AnimatePresence>
|
||||||
<main className="flex flex-col min-h-screen gap-2 text-white">
|
<main className="flex flex-col min-h-screen gap-2 text-white">
|
||||||
@ -93,6 +87,7 @@ export default function RootLayout({
|
|||||||
</AnimatePresence>
|
</AnimatePresence>
|
||||||
</QueryProvider>
|
</QueryProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
|
</OfflineNetwork>
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
</DatabaseLoader>
|
</DatabaseLoader>
|
||||||
</body>
|
</body>
|
||||||
|
@ -46,9 +46,7 @@ export const getAverageColor = cache(async (src: string) => {
|
|||||||
// Use your extractColors function to calculate the average color
|
// Use your extractColors function to calculate the average color
|
||||||
const color = await extractColors({ data, width, height });
|
const color = await extractColors({ data, width, height });
|
||||||
|
|
||||||
console.log(
|
console.log(`Found average color of "${src}" in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found average color of "${src}" in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return color[2];
|
return color[2];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error while getting average color:", error);
|
console.error("Error while getting average color:", error);
|
||||||
|
@ -3,11 +3,7 @@ import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-p
|
|||||||
import { PlayerHistory } from "@/common/player/player-history";
|
import { PlayerHistory } from "@/common/player/player-history";
|
||||||
import { config } from "../../../../../config";
|
import { config } from "../../../../../config";
|
||||||
import ky from "ky";
|
import ky from "ky";
|
||||||
import {
|
import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "@/common/time-utils";
|
||||||
formatDateMinimal,
|
|
||||||
getDaysAgoDate,
|
|
||||||
getMidnightAlignedDate,
|
|
||||||
} from "@/common/time-utils";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A ScoreSaber player.
|
* A ScoreSaber player.
|
||||||
@ -64,16 +60,14 @@ export default interface ScoreSaberPlayer extends Player {
|
|||||||
inactive: boolean;
|
inactive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getScoreSaberPlayerFromToken(
|
export async function getScoreSaberPlayerFromToken(token: ScoreSaberPlayerToken): Promise<ScoreSaberPlayer> {
|
||||||
token: ScoreSaberPlayerToken,
|
|
||||||
): Promise<ScoreSaberPlayer> {
|
|
||||||
const bio: ScoreSaberBio = {
|
const bio: ScoreSaberBio = {
|
||||||
lines: token.bio?.split("\n") || [],
|
lines: token.bio?.split("\n") || [],
|
||||||
linesStripped: token.bio?.replace(/<[^>]+>/g, "")?.split("\n") || [],
|
linesStripped: token.bio?.replace(/<[^>]+>/g, "")?.split("\n") || [],
|
||||||
};
|
};
|
||||||
const role = token.role == null ? undefined : (token.role as ScoreSaberRole);
|
const role = token.role == null ? undefined : (token.role as ScoreSaberRole);
|
||||||
const badges: ScoreSaberBadge[] =
|
const badges: ScoreSaberBadge[] =
|
||||||
token.badges?.map((badge) => {
|
token.badges?.map(badge => {
|
||||||
return {
|
return {
|
||||||
url: badge.image,
|
url: badge.image,
|
||||||
description: badge.description,
|
description: badge.description,
|
||||||
@ -103,7 +97,7 @@ export async function getScoreSaberPlayerFromToken(
|
|||||||
statisticHistory = history;
|
statisticHistory = history;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Fallback to ScoreSaber History if the player has no history
|
// Fallback to ScoreSaber History if the player has no history
|
||||||
const playerRankHistory = token.histories.split(",").map((value) => {
|
const playerRankHistory = token.histories.split(",").map(value => {
|
||||||
return parseInt(value);
|
return parseInt(value);
|
||||||
});
|
});
|
||||||
playerRankHistory.push(token.rank);
|
playerRankHistory.push(token.rank);
|
||||||
@ -124,9 +118,7 @@ export async function getScoreSaberPlayerFromToken(
|
|||||||
.sort((a, b) => Date.parse(b[0]) - Date.parse(a[0]))
|
.sort((a, b) => Date.parse(b[0]) - Date.parse(a[0]))
|
||||||
.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {});
|
.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {});
|
||||||
|
|
||||||
const yesterdayDate = formatDateMinimal(
|
const yesterdayDate = formatDateMinimal(getMidnightAlignedDate(getDaysAgoDate(1)));
|
||||||
getMidnightAlignedDate(getDaysAgoDate(1)),
|
|
||||||
);
|
|
||||||
const todayStats = statisticHistory[todayDate];
|
const todayStats = statisticHistory[todayDate];
|
||||||
const yesterdayStats = statisticHistory[yesterdayDate];
|
const yesterdayStats = statisticHistory[yesterdayDate];
|
||||||
const hasChange = !!(todayStats && yesterdayStats);
|
const hasChange = !!(todayStats && yesterdayStats);
|
||||||
|
@ -43,7 +43,7 @@ export default class Player {
|
|||||||
country: string,
|
country: string,
|
||||||
rank: number,
|
rank: number,
|
||||||
countryRank: number,
|
countryRank: number,
|
||||||
joinedDate: Date,
|
joinedDate: Date
|
||||||
) {
|
) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -12,19 +12,9 @@ export default class ScoreSaberScore extends Score {
|
|||||||
misses: number,
|
misses: number,
|
||||||
badCuts: number,
|
badCuts: number,
|
||||||
fullCombo: boolean,
|
fullCombo: boolean,
|
||||||
timestamp: Date,
|
timestamp: Date
|
||||||
) {
|
) {
|
||||||
super(
|
super(score, weight, rank, worth, modifiers, misses, badCuts, fullCombo, timestamp);
|
||||||
score,
|
|
||||||
weight,
|
|
||||||
rank,
|
|
||||||
worth,
|
|
||||||
modifiers,
|
|
||||||
misses,
|
|
||||||
badCuts,
|
|
||||||
fullCombo,
|
|
||||||
timestamp,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +23,7 @@ export default class ScoreSaberScore extends Score {
|
|||||||
* @param token the token to convert
|
* @param token the token to convert
|
||||||
*/
|
*/
|
||||||
public static fromToken(token: ScoreSaberScoreToken): ScoreSaberScore {
|
public static fromToken(token: ScoreSaberScoreToken): ScoreSaberScore {
|
||||||
const modifiers: Modifier[] = token.modifiers.split(",").map((mod) => {
|
const modifiers: Modifier[] = token.modifiers.split(",").map(mod => {
|
||||||
mod = mod.toUpperCase();
|
mod = mod.toUpperCase();
|
||||||
const modifier = Modifier[mod as keyof typeof Modifier];
|
const modifier = Modifier[mod as keyof typeof Modifier];
|
||||||
if (modifier === undefined) {
|
if (modifier === undefined) {
|
||||||
@ -51,7 +41,7 @@ export default class ScoreSaberScore extends Score {
|
|||||||
token.missedNotes,
|
token.missedNotes,
|
||||||
token.badCuts,
|
token.badCuts,
|
||||||
token.fullCombo,
|
token.fullCombo,
|
||||||
new Date(token.timeSet),
|
new Date(token.timeSet)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ export default class Score {
|
|||||||
misses: number,
|
misses: number,
|
||||||
badCuts: number,
|
badCuts: number,
|
||||||
fullCombo: boolean,
|
fullCombo: boolean,
|
||||||
timestamp: Date,
|
timestamp: Date
|
||||||
) {
|
) {
|
||||||
this._score = score;
|
this._score = score;
|
||||||
this._weight = weight;
|
this._weight = weight;
|
||||||
|
@ -16,7 +16,7 @@ const INACTIVE_CHECK_AGAIN_TIME = 3 * 24 * 60 * 60 * 1000; // 3 days
|
|||||||
*/
|
*/
|
||||||
export function sortPlayerHistory(history: Map<string, PlayerHistory>) {
|
export function sortPlayerHistory(history: Map<string, PlayerHistory>) {
|
||||||
return Array.from(history.entries()).sort(
|
return Array.from(history.entries()).sort(
|
||||||
(a, b) => Date.parse(b[0]) - Date.parse(a[0]), // Sort in descending order
|
(a, b) => Date.parse(b[0]) - Date.parse(a[0]) // Sort in descending order
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +31,10 @@ export function sortPlayerHistory(history: Map<string, PlayerHistory>) {
|
|||||||
export async function seedPlayerHistory(
|
export async function seedPlayerHistory(
|
||||||
foundPlayer: IPlayer,
|
foundPlayer: IPlayer,
|
||||||
player: ScoreSaberPlayer,
|
player: ScoreSaberPlayer,
|
||||||
rawPlayer: ScoreSaberPlayerToken,
|
rawPlayer: ScoreSaberPlayerToken
|
||||||
): Promise<Map<string, PlayerHistory>> {
|
): Promise<Map<string, PlayerHistory>> {
|
||||||
// Loop through rankHistory in reverse, from current day backwards
|
// Loop through rankHistory in reverse, from current day backwards
|
||||||
const playerRankHistory = rawPlayer.histories.split(",").map((value) => {
|
const playerRankHistory = rawPlayer.histories.split(",").map(value => {
|
||||||
return parseInt(value);
|
return parseInt(value);
|
||||||
});
|
});
|
||||||
playerRankHistory.push(player.rank);
|
playerRankHistory.push(player.rank);
|
||||||
@ -63,34 +63,23 @@ export async function seedPlayerHistory(
|
|||||||
* @param dateToday the date to use
|
* @param dateToday the date to use
|
||||||
* @param foundPlayer the player to track
|
* @param foundPlayer the player to track
|
||||||
*/
|
*/
|
||||||
export async function trackScoreSaberPlayer(
|
export async function trackScoreSaberPlayer(dateToday: Date, foundPlayer: IPlayer, io?: IO) {
|
||||||
dateToday: Date,
|
|
||||||
foundPlayer: IPlayer,
|
|
||||||
io?: IO,
|
|
||||||
) {
|
|
||||||
io && (await io.logger.info(`Updating statistics for ${foundPlayer.id}...`));
|
io && (await io.logger.info(`Updating statistics for ${foundPlayer.id}...`));
|
||||||
|
|
||||||
// Check if the player is inactive and if we check their inactive status again
|
// Check if the player is inactive and if we check their inactive status again
|
||||||
if (
|
if (
|
||||||
foundPlayer.rawPlayer &&
|
foundPlayer.rawPlayer &&
|
||||||
foundPlayer.rawPlayer.inactive &&
|
foundPlayer.rawPlayer.inactive &&
|
||||||
Date.now() - foundPlayer.getLastTracked().getTime() >
|
Date.now() - foundPlayer.getLastTracked().getTime() > INACTIVE_CHECK_AGAIN_TIME
|
||||||
INACTIVE_CHECK_AGAIN_TIME
|
|
||||||
) {
|
) {
|
||||||
io &&
|
io && (await io.logger.warn(`Player ${foundPlayer.id} is inactive, skipping...`));
|
||||||
(await io.logger.warn(
|
|
||||||
`Player ${foundPlayer.id} is inactive, skipping...`,
|
|
||||||
));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup player data from the ScoreSaber service
|
// Lookup player data from the ScoreSaber service
|
||||||
const response = await scoresaberService.lookupPlayer(foundPlayer.id, true);
|
const response = await scoresaberService.lookupPlayer(foundPlayer.id, true);
|
||||||
if (response == undefined) {
|
if (response == undefined) {
|
||||||
io &&
|
io && (await io.logger.warn(`Player ${foundPlayer.id} not found on ScoreSaber`));
|
||||||
(await io.logger.warn(
|
|
||||||
`Player ${foundPlayer.id} not found on ScoreSaber`,
|
|
||||||
));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { player, rawPlayer } = response;
|
const { player, rawPlayer } = response;
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import mongoose, { Document, Schema } from "mongoose";
|
import mongoose, { Document, Schema } from "mongoose";
|
||||||
import { PlayerHistory } from "@/common/player/player-history";
|
import { PlayerHistory } from "@/common/player/player-history";
|
||||||
import {
|
import { formatDateMinimal, getDaysAgo, getMidnightAlignedDate } from "@/common/time-utils";
|
||||||
formatDateMinimal,
|
|
||||||
getDaysAgo,
|
|
||||||
getMidnightAlignedDate,
|
|
||||||
} from "@/common/time-utils";
|
|
||||||
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
||||||
import { sortPlayerHistory } from "@/common/player-utils";
|
import { sortPlayerHistory } from "@/common/player-utils";
|
||||||
|
|
||||||
@ -95,11 +91,7 @@ PlayerSchema.methods.getLastTracked = function (): Date {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PlayerSchema.methods.getHistoryByDate = function (date: Date): PlayerHistory {
|
PlayerSchema.methods.getHistoryByDate = function (date: Date): PlayerHistory {
|
||||||
return (
|
return this.statisticHistory.get(formatDateMinimal(getMidnightAlignedDate(date))) || {};
|
||||||
this.statisticHistory.get(
|
|
||||||
formatDateMinimal(getMidnightAlignedDate(date)),
|
|
||||||
) || {}
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerSchema.methods.getHistoryPrevious = function (amount: number): {
|
PlayerSchema.methods.getHistoryPrevious = function (amount: number): {
|
||||||
@ -118,33 +110,21 @@ PlayerSchema.methods.getHistoryPrevious = function (amount: number): {
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerSchema.methods.getStatisticHistory = function (): Map<
|
PlayerSchema.methods.getStatisticHistory = function (): Map<Date, PlayerHistory> {
|
||||||
Date,
|
|
||||||
PlayerHistory
|
|
||||||
> {
|
|
||||||
if (!this.statisticHistory) {
|
if (!this.statisticHistory) {
|
||||||
this.statisticHistory = new Map();
|
this.statisticHistory = new Map();
|
||||||
}
|
}
|
||||||
return this.statisticHistory;
|
return this.statisticHistory;
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerSchema.methods.setStatisticHistory = function (
|
PlayerSchema.methods.setStatisticHistory = function (date: Date, data: PlayerHistory): void {
|
||||||
date: Date,
|
|
||||||
data: PlayerHistory,
|
|
||||||
): void {
|
|
||||||
if (!this.statisticHistory) {
|
if (!this.statisticHistory) {
|
||||||
this.statisticHistory = new Map();
|
this.statisticHistory = new Map();
|
||||||
}
|
}
|
||||||
return this.statisticHistory.set(
|
return this.statisticHistory.set(formatDateMinimal(getMidnightAlignedDate(date)), data);
|
||||||
formatDateMinimal(getMidnightAlignedDate(date)),
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PlayerSchema.methods.sortStatisticHistory = function (): Map<
|
PlayerSchema.methods.sortStatisticHistory = function (): Map<Date, PlayerHistory> {
|
||||||
Date,
|
|
||||||
PlayerHistory
|
|
||||||
> {
|
|
||||||
if (!this.statisticHistory) {
|
if (!this.statisticHistory) {
|
||||||
this.statisticHistory = new Map();
|
this.statisticHistory = new Map();
|
||||||
}
|
}
|
||||||
@ -152,18 +132,14 @@ PlayerSchema.methods.sortStatisticHistory = function (): Map<
|
|||||||
// Sort the player's history
|
// Sort the player's history
|
||||||
this.statisticHistory = new Map(
|
this.statisticHistory = new Map(
|
||||||
Array.from(this.statisticHistory.entries() as [string, PlayerHistory][])
|
Array.from(this.statisticHistory.entries() as [string, PlayerHistory][])
|
||||||
.sort(
|
.sort((a: [string, PlayerHistory], b: [string, PlayerHistory]) => Date.parse(b[0]) - Date.parse(a[0]))
|
||||||
(a: [string, PlayerHistory], b: [string, PlayerHistory]) =>
|
|
||||||
Date.parse(b[0]) - Date.parse(a[0]),
|
|
||||||
)
|
|
||||||
// Convert the date strings back to Date objects for the resulting Map
|
// Convert the date strings back to Date objects for the resulting Map
|
||||||
.map(([date, history]) => [formatDateMinimal(new Date(date)), history]),
|
.map(([date, history]) => [formatDateMinimal(new Date(date)), history])
|
||||||
);
|
);
|
||||||
return this.statisticHistory;
|
return this.statisticHistory;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mongoose Model for Player
|
// Mongoose Model for Player
|
||||||
const PlayerModel =
|
const PlayerModel = mongoose.models.Player || mongoose.model<IPlayer>("Player", PlayerSchema);
|
||||||
mongoose.models.Player || mongoose.model<IPlayer>("Player", PlayerSchema);
|
|
||||||
|
|
||||||
export { PlayerModel };
|
export { PlayerModel };
|
||||||
|
@ -18,26 +18,18 @@ class BeatSaverService extends Service {
|
|||||||
* @param useProxy whether to use the proxy or not
|
* @param useProxy whether to use the proxy or not
|
||||||
* @returns the map that match the query, or undefined if no map were found
|
* @returns the map that match the query, or undefined if no map were found
|
||||||
*/
|
*/
|
||||||
async lookupMap(
|
async lookupMap(query: string, useProxy = true): Promise<BeatSaverMap | undefined> {
|
||||||
query: string,
|
|
||||||
useProxy = true,
|
|
||||||
): Promise<BeatSaverMap | undefined> {
|
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(`Looking up map "${query}"...`);
|
this.log(`Looking up map "${query}"...`);
|
||||||
|
|
||||||
let map = await db.beatSaverMaps.get(query);
|
let map = await db.beatSaverMaps.get(query);
|
||||||
// The map is cached
|
// The map is cached
|
||||||
if (map != undefined) {
|
if (map != undefined) {
|
||||||
this.log(
|
this.log(`Found cached map "${query}" in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found cached map "${query}" in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await this.fetch<BSMap>(
|
const response = await this.fetch<BSMap>(useProxy, LOOKUP_MAP_BY_HASH_ENDPOINT.replace(":query", query));
|
||||||
useProxy,
|
|
||||||
LOOKUP_MAP_BY_HASH_ENDPOINT.replace(":query", query),
|
|
||||||
);
|
|
||||||
// Map not found
|
// Map not found
|
||||||
if (response == undefined) {
|
if (response == undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -55,9 +47,7 @@ class BeatSaverService extends Service {
|
|||||||
fullData: response,
|
fullData: response,
|
||||||
});
|
});
|
||||||
map = await db.beatSaverMaps.get(query);
|
map = await db.beatSaverMaps.get(query);
|
||||||
this.log(
|
this.log(`Found map "${query}" in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found map "${query}" in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,7 @@ import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-p
|
|||||||
import { ScoreSaberPlayersPageToken } from "@/common/model/token/scoresaber/score-saber-players-page-token";
|
import { ScoreSaberPlayersPageToken } from "@/common/model/token/scoresaber/score-saber-players-page-token";
|
||||||
import { ScoreSort } from "../../model/score/score-sort";
|
import { ScoreSort } from "../../model/score/score-sort";
|
||||||
import Service from "../service";
|
import Service from "../service";
|
||||||
import ScoreSaberPlayer, {
|
import ScoreSaberPlayer, { getScoreSaberPlayerFromToken } from "@/common/model/player/impl/scoresaber-player";
|
||||||
getScoreSaberPlayerFromToken,
|
|
||||||
} from "@/common/model/player/impl/scoresaber-player";
|
|
||||||
|
|
||||||
const API_BASE = "https://scoresaber.com/api";
|
const API_BASE = "https://scoresaber.com/api";
|
||||||
const SEARCH_PLAYERS_ENDPOINT = `${API_BASE}/players?search=:query`;
|
const SEARCH_PLAYERS_ENDPOINT = `${API_BASE}/players?search=:query`;
|
||||||
@ -29,15 +27,12 @@ class ScoreSaberService extends Service {
|
|||||||
* @param useProxy whether to use the proxy or not
|
* @param useProxy whether to use the proxy or not
|
||||||
* @returns the players that match the query, or undefined if no players were found
|
* @returns the players that match the query, or undefined if no players were found
|
||||||
*/
|
*/
|
||||||
async searchPlayers(
|
async searchPlayers(query: string, useProxy = true): Promise<ScoreSaberPlayerSearchToken | undefined> {
|
||||||
query: string,
|
|
||||||
useProxy = true,
|
|
||||||
): Promise<ScoreSaberPlayerSearchToken | undefined> {
|
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(`Searching for players matching "${query}"...`);
|
this.log(`Searching for players matching "${query}"...`);
|
||||||
const results = await this.fetch<ScoreSaberPlayerSearchToken>(
|
const results = await this.fetch<ScoreSaberPlayerSearchToken>(
|
||||||
useProxy,
|
useProxy,
|
||||||
SEARCH_PLAYERS_ENDPOINT.replace(":query", query),
|
SEARCH_PLAYERS_ENDPOINT.replace(":query", query)
|
||||||
);
|
);
|
||||||
if (results === undefined) {
|
if (results === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -46,9 +41,7 @@ class ScoreSaberService extends Service {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
results.players.sort((a, b) => a.rank - b.rank);
|
results.players.sort((a, b) => a.rank - b.rank);
|
||||||
this.log(
|
this.log(`Found ${results.players.length} players in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found ${results.players.length} players in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +54,7 @@ class ScoreSaberService extends Service {
|
|||||||
*/
|
*/
|
||||||
async lookupPlayer(
|
async lookupPlayer(
|
||||||
playerId: string,
|
playerId: string,
|
||||||
useProxy = true,
|
useProxy = true
|
||||||
): Promise<
|
): Promise<
|
||||||
| {
|
| {
|
||||||
player: ScoreSaberPlayer;
|
player: ScoreSaberPlayer;
|
||||||
@ -71,16 +64,11 @@ class ScoreSaberService extends Service {
|
|||||||
> {
|
> {
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(`Looking up player "${playerId}"...`);
|
this.log(`Looking up player "${playerId}"...`);
|
||||||
const token = await this.fetch<ScoreSaberPlayerToken>(
|
const token = await this.fetch<ScoreSaberPlayerToken>(useProxy, LOOKUP_PLAYER_ENDPOINT.replace(":id", playerId));
|
||||||
useProxy,
|
|
||||||
LOOKUP_PLAYER_ENDPOINT.replace(":id", playerId),
|
|
||||||
);
|
|
||||||
if (token === undefined) {
|
if (token === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
this.log(
|
this.log(`Found player "${playerId}" in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found player "${playerId}" in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
player: await getScoreSaberPlayerFromToken(token),
|
player: await getScoreSaberPlayerFromToken(token),
|
||||||
rawPlayer: token,
|
rawPlayer: token,
|
||||||
@ -94,22 +82,17 @@ class ScoreSaberService extends Service {
|
|||||||
* @param useProxy whether to use the proxy or not
|
* @param useProxy whether to use the proxy or not
|
||||||
* @returns the players on the page, or undefined
|
* @returns the players on the page, or undefined
|
||||||
*/
|
*/
|
||||||
async lookupPlayers(
|
async lookupPlayers(page: number, useProxy = true): Promise<ScoreSaberPlayersPageToken | undefined> {
|
||||||
page: number,
|
|
||||||
useProxy = true,
|
|
||||||
): Promise<ScoreSaberPlayersPageToken | undefined> {
|
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(`Looking up players on page "${page}"...`);
|
this.log(`Looking up players on page "${page}"...`);
|
||||||
const response = await this.fetch<ScoreSaberPlayersPageToken>(
|
const response = await this.fetch<ScoreSaberPlayersPageToken>(
|
||||||
useProxy,
|
useProxy,
|
||||||
LOOKUP_PLAYERS_ENDPOINT.replace(":page", page.toString()),
|
LOOKUP_PLAYERS_ENDPOINT.replace(":page", page.toString())
|
||||||
);
|
);
|
||||||
if (response === undefined) {
|
if (response === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
this.log(
|
this.log(`Found ${response.players.length} players in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found ${response.players.length} players in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,25 +107,18 @@ class ScoreSaberService extends Service {
|
|||||||
async lookupPlayersByCountry(
|
async lookupPlayersByCountry(
|
||||||
page: number,
|
page: number,
|
||||||
country: string,
|
country: string,
|
||||||
useProxy = true,
|
useProxy = true
|
||||||
): Promise<ScoreSaberPlayersPageToken | undefined> {
|
): Promise<ScoreSaberPlayersPageToken | undefined> {
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(
|
this.log(`Looking up players on page "${page}" for country "${country}"...`);
|
||||||
`Looking up players on page "${page}" for country "${country}"...`,
|
|
||||||
);
|
|
||||||
const response = await this.fetch<ScoreSaberPlayersPageToken>(
|
const response = await this.fetch<ScoreSaberPlayersPageToken>(
|
||||||
useProxy,
|
useProxy,
|
||||||
LOOKUP_PLAYERS_BY_COUNTRY_ENDPOINT.replace(
|
LOOKUP_PLAYERS_BY_COUNTRY_ENDPOINT.replace(":page", page.toString()).replace(":country", country)
|
||||||
":page",
|
|
||||||
page.toString(),
|
|
||||||
).replace(":country", country),
|
|
||||||
);
|
);
|
||||||
if (response === undefined) {
|
if (response === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
this.log(
|
this.log(`Found ${response.players.length} players in ${(performance.now() - before).toFixed(0)}ms`);
|
||||||
`Found ${response.players.length} players in ${(performance.now() - before).toFixed(0)}ms`,
|
|
||||||
);
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,24 +147,20 @@ class ScoreSaberService extends Service {
|
|||||||
}): Promise<ScoreSaberPlayerScoresPageToken | undefined> {
|
}): Promise<ScoreSaberPlayerScoresPageToken | undefined> {
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(
|
this.log(
|
||||||
`Looking up scores for player "${playerId}", sort "${sort}", page "${page}"${
|
`Looking up scores for player "${playerId}", sort "${sort}", page "${page}"${search ? `, search "${search}"` : ""}...`
|
||||||
search ? `, search "${search}"` : ""
|
|
||||||
}...`,
|
|
||||||
);
|
);
|
||||||
const response = await this.fetch<ScoreSaberPlayerScoresPageToken>(
|
const response = await this.fetch<ScoreSaberPlayerScoresPageToken>(
|
||||||
useProxy,
|
useProxy,
|
||||||
LOOKUP_PLAYER_SCORES_ENDPOINT.replace(":id", playerId)
|
LOOKUP_PLAYER_SCORES_ENDPOINT.replace(":id", playerId)
|
||||||
.replace(":limit", 8 + "")
|
.replace(":limit", 8 + "")
|
||||||
.replace(":sort", sort)
|
.replace(":sort", sort)
|
||||||
.replace(":page", page + "") + (search ? `&search=${search}` : ""),
|
.replace(":page", page + "") + (search ? `&search=${search}` : "")
|
||||||
);
|
);
|
||||||
if (response === undefined) {
|
if (response === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
this.log(
|
this.log(
|
||||||
`Found ${response.playerScores.length} scores for player "${playerId}" in ${(
|
`Found ${response.playerScores.length} scores for player "${playerId}" in ${(performance.now() - before).toFixed(0)}ms`
|
||||||
performance.now() - before
|
|
||||||
).toFixed(0)}ms`,
|
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@ -205,26 +177,19 @@ class ScoreSaberService extends Service {
|
|||||||
async lookupLeaderboardScores(
|
async lookupLeaderboardScores(
|
||||||
leaderboardId: string,
|
leaderboardId: string,
|
||||||
page: number,
|
page: number,
|
||||||
useProxy = true,
|
useProxy = true
|
||||||
): Promise<ScoreSaberLeaderboardScoresPageToken | undefined> {
|
): Promise<ScoreSaberLeaderboardScoresPageToken | undefined> {
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
this.log(
|
this.log(`Looking up scores for leaderboard "${leaderboardId}", page "${page}"...`);
|
||||||
`Looking up scores for leaderboard "${leaderboardId}", page "${page}"...`,
|
|
||||||
);
|
|
||||||
const response = await this.fetch<ScoreSaberLeaderboardScoresPageToken>(
|
const response = await this.fetch<ScoreSaberLeaderboardScoresPageToken>(
|
||||||
useProxy,
|
useProxy,
|
||||||
LOOKUP_LEADERBOARD_SCORES_ENDPOINT.replace(":id", leaderboardId).replace(
|
LOOKUP_LEADERBOARD_SCORES_ENDPOINT.replace(":id", leaderboardId).replace(":page", page.toString())
|
||||||
":page",
|
|
||||||
page.toString(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
if (response === undefined) {
|
if (response === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
this.log(
|
this.log(
|
||||||
`Found ${response.scores.length} scores for leaderboard "${leaderboardId}" in ${(
|
`Found ${response.scores.length} scores for leaderboard "${leaderboardId}" in ${(performance.now() - before).toFixed(0)}ms`
|
||||||
performance.now() - before
|
|
||||||
).toFixed(0)}ms`,
|
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,7 @@ export default class Service {
|
|||||||
* @param data the data to log
|
* @param data the data to log
|
||||||
*/
|
*/
|
||||||
public log(data: unknown) {
|
public log(data: unknown) {
|
||||||
console.log(
|
console.log(`[${isRunningAsWorker() ? "Worker - " : ""}${this.name}]: ${data}`);
|
||||||
`[${isRunningAsWorker() ? "Worker - " : ""}${this.name}]: ${data}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,10 +39,7 @@ export default class Service {
|
|||||||
* @param url the url to fetch
|
* @param url the url to fetch
|
||||||
* @returns the fetched data
|
* @returns the fetched data
|
||||||
*/
|
*/
|
||||||
public async fetch<T>(
|
public async fetch<T>(useProxy: boolean, url: string): Promise<T | undefined> {
|
||||||
useProxy: boolean,
|
|
||||||
url: string,
|
|
||||||
): Promise<T | undefined> {
|
|
||||||
try {
|
try {
|
||||||
return await ky
|
return await ky
|
||||||
.get<T>(this.buildRequestUrl(useProxy, url), {
|
.get<T>(this.buildRequestUrl(useProxy, url), {
|
||||||
|
@ -20,10 +20,7 @@ export function timeAgo(input: Date | number) {
|
|||||||
for (const key in ranges) {
|
for (const key in ranges) {
|
||||||
if (ranges[key] < Math.abs(secondsElapsed)) {
|
if (ranges[key] < Math.abs(secondsElapsed)) {
|
||||||
const delta = secondsElapsed / ranges[key];
|
const delta = secondsElapsed / ranges[key];
|
||||||
return formatter.format(
|
return formatter.format(Math.round(delta), key as Intl.RelativeTimeFormatUnit);
|
||||||
Math.round(delta),
|
|
||||||
key as Intl.RelativeTimeFormatUnit,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,9 +45,7 @@ export function formatDateMinimal(date: Date) {
|
|||||||
* @param date the date
|
* @param date the date
|
||||||
*/
|
*/
|
||||||
export function getMidnightAlignedDate(date: Date) {
|
export function getMidnightAlignedDate(date: Date) {
|
||||||
return new Date(
|
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()));
|
||||||
Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,11 +6,7 @@
|
|||||||
* @param author the author of the song
|
* @param author the author of the song
|
||||||
* @returns the YouTube link for the song
|
* @returns the YouTube link for the song
|
||||||
*/
|
*/
|
||||||
export function songNameToYouTubeLink(
|
export function songNameToYouTubeLink(name: string, songSubName: string, author: string) {
|
||||||
name: string,
|
|
||||||
songSubName: string,
|
|
||||||
author: string,
|
|
||||||
) {
|
|
||||||
const baseUrl = "https://www.youtube.com/results?search_query=";
|
const baseUrl = "https://www.youtube.com/results?search_query=";
|
||||||
let query = "";
|
let query = "";
|
||||||
if (name) {
|
if (name) {
|
||||||
|
@ -2,17 +2,14 @@
|
|||||||
|
|
||||||
import { useLiveQuery } from "dexie-react-hooks";
|
import { useLiveQuery } from "dexie-react-hooks";
|
||||||
import { config } from "../../config";
|
import { config } from "../../config";
|
||||||
import { getImageUrl } from "../common/image-utils";
|
import { getImageUrl } from "@/common/image-utils";
|
||||||
import useDatabase from "../hooks/use-database";
|
import useDatabase from "../hooks/use-database";
|
||||||
|
|
||||||
export default function BackgroundImage() {
|
export default function BackgroundImage() {
|
||||||
const database = useDatabase();
|
const database = useDatabase();
|
||||||
const settings = useLiveQuery(() => database.getSettings());
|
const settings = useLiveQuery(() => database.getSettings());
|
||||||
|
|
||||||
if (
|
if (settings == undefined || settings?.backgroundImage == undefined || settings?.backgroundImage == "") {
|
||||||
settings?.backgroundImage == undefined ||
|
|
||||||
settings?.backgroundImage == ""
|
|
||||||
) {
|
|
||||||
return null; // Don't render anything if the background image is not set
|
return null; // Don't render anything if the background image is not set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,14 +6,5 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function Card({ children, className }: Props) {
|
export default function Card({ children, className }: Props) {
|
||||||
return (
|
return <div className={clsx("flex flex-col bg-secondary/90 p-3 rounded-md", className)}>{children}</div>;
|
||||||
<div
|
|
||||||
className={clsx(
|
|
||||||
"flex flex-col bg-secondary/90 p-3 rounded-md",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -12,14 +12,7 @@ export const CustomizedAxisTick = ({
|
|||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<g transform={`translate(${x},${y})`}>
|
<g transform={`translate(${x},${y})`}>
|
||||||
<text
|
<text x={0} y={0} dy={16} textAnchor="end" fill="#666" transform={`rotate(${rotateAngle})`}>
|
||||||
x={0}
|
|
||||||
y={0}
|
|
||||||
dy={16}
|
|
||||||
textAnchor="end"
|
|
||||||
fill="#666"
|
|
||||||
transform={`rotate(${rotateAngle})`}
|
|
||||||
>
|
|
||||||
{payload.value}
|
{payload.value}
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
|
@ -23,10 +23,7 @@ type PaginationItemWrapperProps = {
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
function PaginationItemWrapper({
|
function PaginationItemWrapper({ isLoadingPage, children }: PaginationItemWrapperProps) {
|
||||||
isLoadingPage,
|
|
||||||
children,
|
|
||||||
}: PaginationItemWrapperProps) {
|
|
||||||
return (
|
return (
|
||||||
<PaginationItem
|
<PaginationItem
|
||||||
className={clsx(isLoadingPage ? "cursor-not-allowed" : "cursor-pointer")}
|
className={clsx(isLoadingPage ? "cursor-not-allowed" : "cursor-pointer")}
|
||||||
@ -65,13 +62,7 @@ type Props = {
|
|||||||
onPageChange: (page: number) => void;
|
onPageChange: (page: number) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Pagination({
|
export default function Pagination({ mobilePagination, page, totalPages, loadingPage, onPageChange }: Props) {
|
||||||
mobilePagination,
|
|
||||||
page,
|
|
||||||
totalPages,
|
|
||||||
loadingPage,
|
|
||||||
onPageChange,
|
|
||||||
}: Props) {
|
|
||||||
totalPages = Math.round(totalPages);
|
totalPages = Math.round(totalPages);
|
||||||
const isLoading = loadingPage !== undefined;
|
const isLoading = loadingPage !== undefined;
|
||||||
const [currentPage, setCurrentPage] = useState(page);
|
const [currentPage, setCurrentPage] = useState(page);
|
||||||
@ -81,12 +72,7 @@ export default function Pagination({
|
|||||||
}, [page]);
|
}, [page]);
|
||||||
|
|
||||||
const handlePageChange = (newPage: number) => {
|
const handlePageChange = (newPage: number) => {
|
||||||
if (
|
if (newPage < 1 || newPage > totalPages || newPage == currentPage || isLoading) {
|
||||||
newPage < 1 ||
|
|
||||||
newPage > totalPages ||
|
|
||||||
newPage == currentPage ||
|
|
||||||
isLoading
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,20 +95,15 @@ export default function Pagination({
|
|||||||
pageNumbers.push(
|
pageNumbers.push(
|
||||||
<>
|
<>
|
||||||
<PaginationItemWrapper key="start" isLoadingPage={isLoading}>
|
<PaginationItemWrapper key="start" isLoadingPage={isLoading}>
|
||||||
<PaginationLink onClick={() => handlePageChange(1)}>
|
<PaginationLink onClick={() => handlePageChange(1)}>1</PaginationLink>
|
||||||
1
|
|
||||||
</PaginationLink>
|
|
||||||
</PaginationItemWrapper>
|
</PaginationItemWrapper>
|
||||||
{/* Only show ellipsis if more than 2 pages from the start */}
|
{/* Only show ellipsis if more than 2 pages from the start */}
|
||||||
{startPage > 2 && (
|
{startPage > 2 && (
|
||||||
<PaginationItemWrapper
|
<PaginationItemWrapper key="ellipsis-start" isLoadingPage={isLoading}>
|
||||||
key="ellipsis-start"
|
|
||||||
isLoadingPage={isLoading}
|
|
||||||
>
|
|
||||||
<PaginationEllipsis />
|
<PaginationEllipsis />
|
||||||
</PaginationItemWrapper>
|
</PaginationItemWrapper>
|
||||||
)}
|
)}
|
||||||
</>,
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,17 +111,10 @@ export default function Pagination({
|
|||||||
for (let i = startPage; i <= endPage; i++) {
|
for (let i = startPage; i <= endPage; i++) {
|
||||||
pageNumbers.push(
|
pageNumbers.push(
|
||||||
<PaginationItemWrapper key={i} isLoadingPage={isLoading}>
|
<PaginationItemWrapper key={i} isLoadingPage={isLoading}>
|
||||||
<PaginationLink
|
<PaginationLink isActive={i === currentPage} onClick={() => handlePageChange(i)}>
|
||||||
isActive={i === currentPage}
|
{loadingPage === i ? <ArrowPathIcon className="w-4 h-4 animate-spin" /> : i}
|
||||||
onClick={() => handlePageChange(i)}
|
|
||||||
>
|
|
||||||
{loadingPage === i ? (
|
|
||||||
<ArrowPathIcon className="w-4 h-4 animate-spin" />
|
|
||||||
) : (
|
|
||||||
i
|
|
||||||
)}
|
|
||||||
</PaginationLink>
|
</PaginationLink>
|
||||||
</PaginationItemWrapper>,
|
</PaginationItemWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,28 +126,19 @@ export default function Pagination({
|
|||||||
<PaginationContent>
|
<PaginationContent>
|
||||||
{/* Previous button for mobile and desktop */}
|
{/* Previous button for mobile and desktop */}
|
||||||
<PaginationItemWrapper isLoadingPage={isLoading}>
|
<PaginationItemWrapper isLoadingPage={isLoading}>
|
||||||
<PaginationPrevious
|
<PaginationPrevious onClick={() => handlePageChange(currentPage - 1)} />
|
||||||
onClick={() => handlePageChange(currentPage - 1)}
|
|
||||||
/>
|
|
||||||
</PaginationItemWrapper>
|
</PaginationItemWrapper>
|
||||||
|
|
||||||
{renderPageNumbers()}
|
{renderPageNumbers()}
|
||||||
|
|
||||||
{/* For desktop, show ellipsis and link to the last page */}
|
{/* For desktop, show ellipsis and link to the last page */}
|
||||||
{!mobilePagination &&
|
{!mobilePagination && currentPage < totalPages && totalPages - currentPage > 2 && (
|
||||||
currentPage < totalPages &&
|
|
||||||
totalPages - currentPage > 2 && (
|
|
||||||
<>
|
<>
|
||||||
<PaginationItemWrapper
|
<PaginationItemWrapper key="ellipsis-end" isLoadingPage={isLoading}>
|
||||||
key="ellipsis-end"
|
|
||||||
isLoadingPage={isLoading}
|
|
||||||
>
|
|
||||||
<PaginationEllipsis className="cursor-default" />
|
<PaginationEllipsis className="cursor-default" />
|
||||||
</PaginationItemWrapper>
|
</PaginationItemWrapper>
|
||||||
<PaginationItemWrapper key="end" isLoadingPage={isLoading}>
|
<PaginationItemWrapper key="end" isLoadingPage={isLoading}>
|
||||||
<PaginationLink onClick={() => handlePageChange(totalPages)}>
|
<PaginationLink onClick={() => handlePageChange(totalPages)}>{totalPages}</PaginationLink>
|
||||||
{totalPages}
|
|
||||||
</PaginationLink>
|
|
||||||
</PaginationItemWrapper>
|
</PaginationItemWrapper>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -40,10 +40,7 @@ export default function SearchPlayer() {
|
|||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
{/* Search */}
|
{/* Search */}
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form onSubmit={form.handleSubmit(onSubmit)} className="flex items-end gap-2">
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
|
||||||
className="flex items-end gap-2"
|
|
||||||
>
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="username"
|
name="username"
|
||||||
@ -51,11 +48,7 @@ export default function SearchPlayer() {
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Username</FormLabel>
|
<FormLabel>Username</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Input className="w-full sm:w-72 text-sm" placeholder="Query..." {...field} />
|
||||||
className="w-full sm:w-72 text-sm"
|
|
||||||
placeholder="Query..."
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
@ -73,7 +66,7 @@ export default function SearchPlayer() {
|
|||||||
{results !== undefined && (
|
{results !== undefined && (
|
||||||
<ScrollArea>
|
<ScrollArea>
|
||||||
<div className="flex flex-col gap-1 max-h-60">
|
<div className="flex flex-col gap-1 max-h-60">
|
||||||
{results?.map((player) => {
|
{results?.map(player => {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
href={`/player/${player.id}`}
|
href={`/player/${player.id}`}
|
||||||
@ -86,9 +79,7 @@ export default function SearchPlayer() {
|
|||||||
</Avatar>
|
</Avatar>
|
||||||
<div>
|
<div>
|
||||||
<p>{player.name}</p>
|
<p>{player.name}</p>
|
||||||
<p className="text-gray-400 text-sm">
|
<p className="text-gray-400 text-sm">#{formatNumberWithCommas(player.rank)}</p>
|
||||||
#{formatNumberWithCommas(player.rank)}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
|
@ -9,7 +9,7 @@ type Badge = {
|
|||||||
name: string;
|
name: string;
|
||||||
create: (
|
create: (
|
||||||
score: ScoreSaberScoreToken,
|
score: ScoreSaberScoreToken,
|
||||||
leaderboard: ScoreSaberLeaderboardToken,
|
leaderboard: ScoreSaberLeaderboardToken
|
||||||
) => string | React.ReactNode | undefined;
|
) => string | React.ReactNode | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -26,10 +26,7 @@ const badges: Badge[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Accuracy",
|
name: "Accuracy",
|
||||||
create: (
|
create: (score: ScoreSaberScoreToken, leaderboard: ScoreSaberLeaderboardToken) => {
|
||||||
score: ScoreSaberScoreToken,
|
|
||||||
leaderboard: ScoreSaberLeaderboardToken,
|
|
||||||
) => {
|
|
||||||
const acc = (score.baseScore / leaderboard.maxScore) * 100;
|
const acc = (score.baseScore / leaderboard.maxScore) * 100;
|
||||||
return `${acc.toFixed(2)}%`;
|
return `${acc.toFixed(2)}%`;
|
||||||
},
|
},
|
||||||
@ -41,16 +38,8 @@ const badges: Badge[] = [
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
<p>{fullCombo ? <span className="text-green-400">FC</span> : formatNumberWithCommas(score.missedNotes)}</p>
|
||||||
{fullCombo ? (
|
<XMarkIcon className={clsx("w-5 h-5", fullCombo ? "hidden" : "text-red-400")} />
|
||||||
<span className="text-green-400">FC</span>
|
|
||||||
) : (
|
|
||||||
formatNumberWithCommas(score.missedNotes)
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
<XMarkIcon
|
|
||||||
className={clsx("w-5 h-5", fullCombo ? "hidden" : "text-red-400")}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -19,9 +19,7 @@ export default function LeaderboardScores({ leaderboard }: Props) {
|
|||||||
const { width } = useWindowDimensions();
|
const { width } = useWindowDimensions();
|
||||||
|
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [currentScores, setCurrentScores] = useState<
|
const [currentScores, setCurrentScores] = useState<ScoreSaberLeaderboardScoresPageToken | undefined>();
|
||||||
ScoreSaberLeaderboardScoresPageToken | undefined
|
|
||||||
>();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: scores,
|
data: scores,
|
||||||
@ -30,11 +28,7 @@ export default function LeaderboardScores({ leaderboard }: Props) {
|
|||||||
refetch,
|
refetch,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ["playerScores", leaderboard.id, currentPage],
|
queryKey: ["playerScores", leaderboard.id, currentPage],
|
||||||
queryFn: () =>
|
queryFn: () => scoresaberService.lookupLeaderboardScores(leaderboard.id + "", currentPage),
|
||||||
scoresaberService.lookupLeaderboardScores(
|
|
||||||
leaderboard.id + "",
|
|
||||||
currentPage,
|
|
||||||
),
|
|
||||||
staleTime: 30 * 1000, // Cache data for 30 seconds
|
staleTime: 30 * 1000, // Cache data for 30 seconds
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -53,35 +47,23 @@ export default function LeaderboardScores({ leaderboard }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div initial={{ opacity: 0, y: -50 }} exit={{ opacity: 0, y: -50 }} animate={{ opacity: 1, y: 0 }}>
|
||||||
initial={{ opacity: 0, y: -50 }}
|
|
||||||
exit={{ opacity: 0, y: -50 }}
|
|
||||||
animate={{ opacity: 1, y: 0 }}
|
|
||||||
>
|
|
||||||
<Card className="flex gap-2 border border-input mt-2">
|
<Card className="flex gap-2 border border-input mt-2">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{isError && <p>Oopsies! Something went wrong.</p>}
|
{isError && <p>Oopsies! Something went wrong.</p>}
|
||||||
{currentScores.scores.length === 0 && (
|
{currentScores.scores.length === 0 && <p>No scores found. Invalid Page?</p>}
|
||||||
<p>No scores found. Invalid Page?</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid min-w-full grid-cols-1 divide-y divide-border">
|
<div className="grid min-w-full grid-cols-1 divide-y divide-border">
|
||||||
{currentScores.scores.map((playerScore, index) => (
|
{currentScores.scores.map((playerScore, index) => (
|
||||||
<LeaderboardScore
|
<LeaderboardScore key={index} score={playerScore} leaderboard={leaderboard} />
|
||||||
key={index}
|
|
||||||
score={playerScore}
|
|
||||||
leaderboard={leaderboard}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Pagination
|
<Pagination
|
||||||
mobilePagination={width < 768}
|
mobilePagination={width < 768}
|
||||||
page={currentPage}
|
page={currentPage}
|
||||||
totalPages={Math.ceil(
|
totalPages={Math.ceil(currentScores.metadata.total / currentScores.metadata.itemsPerPage)}
|
||||||
currentScores.metadata.total / currentScores.metadata.itemsPerPage,
|
|
||||||
)}
|
|
||||||
loadingPage={isLoading ? currentPage : undefined}
|
loadingPage={isLoading ? currentPage : undefined}
|
||||||
onPageChange={setCurrentPage}
|
onPageChange={setCurrentPage}
|
||||||
/>
|
/>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import { createContext, useEffect, useState } from "react";
|
import { createContext, useEffect, useState } from "react";
|
||||||
import Database, { db } from "../../common/database/database";
|
import Database, { db } from "../../common/database/database";
|
||||||
import FullscreenLoader from "./fullscreen-loader";
|
import FullscreenLoader from "./fullscreen-loader";
|
||||||
|
import { useToast } from "@/hooks/use-toast";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The context for the database. This is used to access the database from within the app.
|
* The context for the database. This is used to access the database from within the app.
|
||||||
@ -14,21 +15,25 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function DatabaseLoader({ children }: Props) {
|
export default function DatabaseLoader({ children }: Props) {
|
||||||
|
const { toast } = useToast();
|
||||||
const [database, setDatabase] = useState<Database | undefined>(undefined);
|
const [database, setDatabase] = useState<Database | undefined>(undefined);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const before = performance.now();
|
const before = performance.now();
|
||||||
setDatabase(db);
|
setDatabase(db);
|
||||||
console.log(`Loaded database in ${performance.now() - before}ms`);
|
console.log(`Loaded database in ${performance.now() - before}ms`);
|
||||||
|
|
||||||
|
db.on("ready", err => {
|
||||||
|
toast({
|
||||||
|
title: "Database loaded",
|
||||||
|
description: "The database was loaded successfully.",
|
||||||
|
});
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DatabaseContext.Provider value={database}>
|
<DatabaseContext.Provider value={database}>
|
||||||
{database == undefined ? (
|
{database == undefined ? <FullscreenLoader reason="Loading database..." /> : children}
|
||||||
<FullscreenLoader reason="Loading database..." />
|
|
||||||
) : (
|
|
||||||
children
|
|
||||||
)}
|
|
||||||
</DatabaseContext.Provider>
|
</DatabaseContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,7 @@ type BeatSaverLogoProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function BeatSaverLogo({
|
export default function BeatSaverLogo({ size = 32, className }: BeatSaverLogoProps) {
|
||||||
size = 32,
|
|
||||||
className,
|
|
||||||
}: BeatSaverLogoProps) {
|
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
@ -18,10 +15,7 @@ export default function BeatSaverLogo({
|
|||||||
>
|
>
|
||||||
<g fill="none" stroke="#fff" strokeWidth="10">
|
<g fill="none" stroke="#fff" strokeWidth="10">
|
||||||
<path d="M 100,7 189,47 100,87 12,47 Z" strokeLinejoin="round"></path>
|
<path d="M 100,7 189,47 100,87 12,47 Z" strokeLinejoin="round"></path>
|
||||||
<path
|
<path d="M 189,47 189,155 100,196 12,155 12,47" strokeLinejoin="round"></path>
|
||||||
d="M 189,47 189,155 100,196 12,155 12,47"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
></path>
|
|
||||||
<path d="M 100,87 100,196" strokeLinejoin="round"></path>
|
<path d="M 100,87 100,196" strokeLinejoin="round"></path>
|
||||||
<path d="M 26,77 85,106 53,130 Z" strokeLinejoin="round"></path>
|
<path d="M 26,77 85,106 53,130 Z" strokeLinejoin="round"></path>
|
||||||
</g>
|
</g>
|
||||||
|
@ -2,12 +2,6 @@ import Image from "next/image";
|
|||||||
|
|
||||||
export default function ScoreSaberLogo() {
|
export default function ScoreSaberLogo() {
|
||||||
return (
|
return (
|
||||||
<Image
|
<Image width={32} height={32} unoptimized src={"/assets/logos/scoresaber.png"} alt={"ScoreSaber Logo"}></Image>
|
||||||
width={32}
|
|
||||||
height={32}
|
|
||||||
unoptimized
|
|
||||||
src={"/assets/logos/scoresaber.png"}
|
|
||||||
alt={"ScoreSaber Logo"}
|
|
||||||
></Image>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,7 @@ type YouTubeLogoProps = {
|
|||||||
className?: string;
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function YouTubeLogo({
|
export default function YouTubeLogo({ size = 32, className }: YouTubeLogoProps) {
|
||||||
size = 32,
|
|
||||||
className,
|
|
||||||
}: YouTubeLogoProps) {
|
|
||||||
return (
|
return (
|
||||||
<svg
|
<svg
|
||||||
height={size}
|
height={size}
|
||||||
|
@ -19,10 +19,7 @@ export default function ProfileButton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link href={`/player/${settings.playerId}`} className="flex items-center gap-2 h-full">
|
||||||
href={`/player/${settings.playerId}`}
|
|
||||||
className="flex items-center gap-2 h-full"
|
|
||||||
>
|
|
||||||
<NavbarButton>
|
<NavbarButton>
|
||||||
<Avatar className="w-6 h-6">
|
<Avatar className="w-6 h-6">
|
||||||
<AvatarImage
|
<AvatarImage
|
||||||
|
18
src/components/offline-network.tsx
Normal file
18
src/components/offline-network.tsx
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import FullscreenLoader from "@/components/loaders/fullscreen-loader";
|
||||||
|
import { useNetworkState } from "@uidotdev/usehooks";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function OfflineNetwork({ children }: Props) {
|
||||||
|
const network = useNetworkState();
|
||||||
|
|
||||||
|
return !network.online ? (
|
||||||
|
<FullscreenLoader reason="Your device is offline. Check your internet connection." />
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
);
|
||||||
|
}
|
@ -11,22 +11,9 @@ export default function PlayerBadges({ player }: Props) {
|
|||||||
<div className="flex flex-wrap gap-2 w-full items-center justify-center">
|
<div className="flex flex-wrap gap-2 w-full items-center justify-center">
|
||||||
{player.badges?.map((badge, index) => {
|
{player.badges?.map((badge, index) => {
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip key={index} display={<p className="cursor-default pointer-events-none">{badge.description}</p>}>
|
||||||
key={index}
|
|
||||||
display={
|
|
||||||
<p className="cursor-default pointer-events-none">
|
|
||||||
{badge.description}
|
|
||||||
</p>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div>
|
<div>
|
||||||
<Image
|
<Image src={badge.url} alt={badge.description} width={80} height={30} unoptimized />
|
||||||
src={badge.url}
|
|
||||||
alt={badge.description}
|
|
||||||
width={80}
|
|
||||||
height={30}
|
|
||||||
unoptimized
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
@ -17,18 +17,12 @@ import PlayerTrackedStatus from "@/components/player/player-tracked-status";
|
|||||||
* @param tooltip the tooltip to display
|
* @param tooltip the tooltip to display
|
||||||
* @param format the function to format the value
|
* @param format the function to format the value
|
||||||
*/
|
*/
|
||||||
const renderChange = (
|
const renderChange = (change: number, tooltip: ReactElement, format?: (value: number) => string) => {
|
||||||
change: number,
|
|
||||||
tooltip: ReactElement,
|
|
||||||
format?: (value: number) => string,
|
|
||||||
) => {
|
|
||||||
format = format ?? formatNumberWithCommas;
|
format = format ?? formatNumberWithCommas;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip display={tooltip}>
|
<Tooltip display={tooltip}>
|
||||||
<p
|
<p className={`text-sm ${change > 0 ? "text-green-400" : "text-red-400"}`}>
|
||||||
className={`text-sm ${change > 0 ? "text-green-400" : "text-red-400"}`}
|
|
||||||
>
|
|
||||||
{change > 0 ? "+" : ""}
|
{change > 0 ? "+" : ""}
|
||||||
{format(change)}
|
{format(change)}
|
||||||
</p>
|
</p>
|
||||||
@ -49,11 +43,7 @@ const playerData = [
|
|||||||
return (
|
return (
|
||||||
<div className="text-gray-300 flex gap-1 items-center">
|
<div className="text-gray-300 flex gap-1 items-center">
|
||||||
<p>#{formatNumberWithCommas(player.rank)}</p>
|
<p>#{formatNumberWithCommas(player.rank)}</p>
|
||||||
{rankChange != 0 &&
|
{rankChange != 0 && renderChange(rankChange, <p>The change in your rank compared to yesterday</p>)}
|
||||||
renderChange(
|
|
||||||
rankChange,
|
|
||||||
<p>The change in your rank compared to yesterday</p>,
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -70,11 +60,7 @@ const playerData = [
|
|||||||
return (
|
return (
|
||||||
<div className="text-gray-300 flex gap-1 items-center">
|
<div className="text-gray-300 flex gap-1 items-center">
|
||||||
<p>#{formatNumberWithCommas(player.countryRank)}</p>
|
<p>#{formatNumberWithCommas(player.countryRank)}</p>
|
||||||
{rankChange != 0 &&
|
{rankChange != 0 && renderChange(rankChange, <p>The change in your rank compared to yesterday</p>)}
|
||||||
renderChange(
|
|
||||||
rankChange,
|
|
||||||
<p>The change in your rank compared to yesterday</p>,
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -89,13 +75,9 @@ const playerData = [
|
|||||||
<div className="text-pp flex gap-1 items-center">
|
<div className="text-pp flex gap-1 items-center">
|
||||||
<p>{formatPp(player.pp)}pp</p>
|
<p>{formatPp(player.pp)}pp</p>
|
||||||
{ppChange != 0 &&
|
{ppChange != 0 &&
|
||||||
renderChange(
|
renderChange(ppChange, <p>The change in your pp compared to yesterday</p>, number => {
|
||||||
ppChange,
|
|
||||||
<p>The change in your pp compared to yesterday</p>,
|
|
||||||
(number) => {
|
|
||||||
return `${formatPp(number)}pp`;
|
return `${formatPp(number)}pp`;
|
||||||
},
|
})}
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -111,10 +93,7 @@ export default function PlayerHeader({ player }: Props) {
|
|||||||
<Card>
|
<Card>
|
||||||
<div className="flex gap-3 flex-col items-center text-center lg:flex-row lg:items-start lg:text-start relative select-none">
|
<div className="flex gap-3 flex-col items-center text-center lg:flex-row lg:items-start lg:text-start relative select-none">
|
||||||
<Avatar className="w-32 h-32 pointer-events-none">
|
<Avatar className="w-32 h-32 pointer-events-none">
|
||||||
<AvatarImage
|
<AvatarImage alt="Profile Picture" src={`https://img.fascinated.cc/upload/w_128,h_128/${player.avatar}`} />
|
||||||
alt="Profile Picture"
|
|
||||||
src={`https://img.fascinated.cc/upload/w_128,h_128/${player.avatar}`}
|
|
||||||
/>
|
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="w-full flex gap-2 flex-col justify-center items-center lg:justify-start lg:items-start">
|
<div className="w-full flex gap-2 flex-col justify-center items-center lg:justify-start lg:items-start">
|
||||||
<div>
|
<div>
|
||||||
@ -124,20 +103,13 @@ export default function PlayerHeader({ player }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<div>
|
<div>
|
||||||
{player.inactive && (
|
{player.inactive && <p className="text-gray-400">Inactive Account</p>}
|
||||||
<p className="text-gray-400">Inactive Account</p>
|
{player.banned && <p className="text-red-500">Banned Account</p>}
|
||||||
)}
|
|
||||||
{player.banned && (
|
|
||||||
<p className="text-red-500">Banned Account</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
{playerData.map((subName, index) => {
|
{playerData.map((subName, index) => {
|
||||||
// Check if the player is inactive or banned and if the data should be shown
|
// Check if the player is inactive or banned and if the data should be shown
|
||||||
if (
|
if (!subName.showWhenInactiveOrBanned && (player.inactive || player.banned)) {
|
||||||
!subName.showWhenInactiveOrBanned &&
|
|
||||||
(player.inactive || player.banned)
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,30 +2,13 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { formatNumberWithCommas } from "@/common/number-utils";
|
import { formatNumberWithCommas } from "@/common/number-utils";
|
||||||
import {
|
import { CategoryScale, Chart, Legend, LinearScale, LineElement, PointElement, Title, Tooltip } from "chart.js";
|
||||||
CategoryScale,
|
|
||||||
Chart,
|
|
||||||
Legend,
|
|
||||||
LinearScale,
|
|
||||||
LineElement,
|
|
||||||
PointElement,
|
|
||||||
Title,
|
|
||||||
Tooltip,
|
|
||||||
} from "chart.js";
|
|
||||||
import { Line } from "react-chartjs-2";
|
import { Line } from "react-chartjs-2";
|
||||||
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
||||||
import { getDaysAgo, parseDate } from "@/common/time-utils";
|
import { getDaysAgo, parseDate } from "@/common/time-utils";
|
||||||
import { useIsMobile } from "@/hooks/use-is-mobile";
|
import { useIsMobile } from "@/hooks/use-is-mobile";
|
||||||
|
|
||||||
Chart.register(
|
Chart.register(LinearScale, CategoryScale, PointElement, LineElement, Title, Tooltip, Legend);
|
||||||
LinearScale,
|
|
||||||
CategoryScale,
|
|
||||||
PointElement,
|
|
||||||
LineElement,
|
|
||||||
Title,
|
|
||||||
Tooltip,
|
|
||||||
Legend,
|
|
||||||
);
|
|
||||||
|
|
||||||
type AxisPosition = "left" | "right";
|
type AxisPosition = "left" | "right";
|
||||||
|
|
||||||
@ -71,7 +54,7 @@ const generateAxis = (
|
|||||||
reverse: boolean,
|
reverse: boolean,
|
||||||
display: boolean,
|
display: boolean,
|
||||||
position: AxisPosition,
|
position: AxisPosition,
|
||||||
displayName: string,
|
displayName: string
|
||||||
): Axis => ({
|
): Axis => ({
|
||||||
id,
|
id,
|
||||||
position,
|
position,
|
||||||
@ -99,12 +82,7 @@ const generateAxis = (
|
|||||||
* @param borderColor the border color of the dataset
|
* @param borderColor the border color of the dataset
|
||||||
* @param yAxisID the ID of the y-axis
|
* @param yAxisID the ID of the y-axis
|
||||||
*/
|
*/
|
||||||
const generateDataset = (
|
const generateDataset = (label: string, data: (number | null)[], borderColor: string, yAxisID: string): Dataset => ({
|
||||||
label: string,
|
|
||||||
data: (number | null)[],
|
|
||||||
borderColor: string,
|
|
||||||
yAxisID: string,
|
|
||||||
): Dataset => ({
|
|
||||||
label,
|
label,
|
||||||
data,
|
data,
|
||||||
borderColor,
|
borderColor,
|
||||||
@ -155,8 +133,7 @@ const datasetConfig: DatasetConfig[] = [
|
|||||||
displayName: "Country Rank",
|
displayName: "Country Rank",
|
||||||
position: "left",
|
position: "left",
|
||||||
},
|
},
|
||||||
labelFormatter: (value: number) =>
|
labelFormatter: (value: number) => `Country Rank #${formatNumberWithCommas(value)}`,
|
||||||
`Country Rank #${formatNumberWithCommas(value)}`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "PP",
|
title: "PP",
|
||||||
@ -181,10 +158,7 @@ type Props = {
|
|||||||
export default function PlayerRankChart({ player }: Props) {
|
export default function PlayerRankChart({ player }: Props) {
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
if (
|
if (!player.statisticHistory || Object.keys(player.statisticHistory).length === 0) {
|
||||||
!player.statisticHistory ||
|
|
||||||
Object.keys(player.statisticHistory).length === 0
|
|
||||||
) {
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center">
|
<div className="flex justify-center">
|
||||||
<p>Unable to load player rank chart, missing data...</p>
|
<p>Unable to load player rank chart, missing data...</p>
|
||||||
@ -200,7 +174,7 @@ export default function PlayerRankChart({ player }: Props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const statisticEntries = Object.entries(player.statisticHistory).sort(
|
const statisticEntries = Object.entries(player.statisticHistory).sort(
|
||||||
([a], [b]) => parseDate(a).getTime() - parseDate(b).getTime(),
|
([a], [b]) => parseDate(a).getTime() - parseDate(b).getTime()
|
||||||
);
|
);
|
||||||
|
|
||||||
let previousDate: Date | null = null;
|
let previousDate: Date | null = null;
|
||||||
@ -211,18 +185,11 @@ export default function PlayerRankChart({ player }: Props) {
|
|||||||
|
|
||||||
// Insert nulls for missing days
|
// Insert nulls for missing days
|
||||||
if (previousDate) {
|
if (previousDate) {
|
||||||
const diffDays = Math.floor(
|
const diffDays = Math.floor((currentDate.getTime() - previousDate.getTime()) / (1000 * 60 * 60 * 24));
|
||||||
(currentDate.getTime() - previousDate.getTime()) /
|
|
||||||
(1000 * 60 * 60 * 24),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (let i = 1; i < diffDays; i++) {
|
for (let i = 1; i < diffDays; i++) {
|
||||||
labels.push(
|
labels.push(`${getDaysAgo(new Date(currentDate.getTime() - i * 24 * 60 * 60 * 1000))} days ago`);
|
||||||
`${getDaysAgo(
|
datasetConfig.forEach(config => {
|
||||||
new Date(currentDate.getTime() - i * 24 * 60 * 60 * 1000),
|
|
||||||
)} days ago`,
|
|
||||||
);
|
|
||||||
datasetConfig.forEach((config) => {
|
|
||||||
histories[config.field].push(null);
|
histories[config.field].push(null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -232,10 +199,8 @@ export default function PlayerRankChart({ player }: Props) {
|
|||||||
labels.push(daysAgo === 0 ? "Today" : `${daysAgo} days ago`);
|
labels.push(daysAgo === 0 ? "Today" : `${daysAgo} days ago`);
|
||||||
|
|
||||||
// stupid typescript crying wahh wahh wahh - https://youtu.be/hBEKgHDzm_s?si=ekOdMMdb-lFnA1Yz&t=11
|
// stupid typescript crying wahh wahh wahh - https://youtu.be/hBEKgHDzm_s?si=ekOdMMdb-lFnA1Yz&t=11
|
||||||
datasetConfig.forEach((config) => {
|
datasetConfig.forEach(config => {
|
||||||
(histories as any)[config.field].push(
|
(histories as any)[config.field].push((history as any)[config.field] ?? null);
|
||||||
(history as any)[config.field] ?? null,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
previousDate = currentDate;
|
previousDate = currentDate;
|
||||||
@ -252,23 +217,16 @@ export default function PlayerRankChart({ player }: Props) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const datasets: Dataset[] = datasetConfig
|
const datasets: Dataset[] = datasetConfig
|
||||||
.map((config) => {
|
.map(config => {
|
||||||
if (histories[config.field].some((value) => value !== null)) {
|
if (histories[config.field].some(value => value !== null)) {
|
||||||
axes[config.axisId] = generateAxis(
|
axes[config.axisId] = generateAxis(
|
||||||
config.axisId,
|
config.axisId,
|
||||||
config.axisConfig.reverse,
|
config.axisConfig.reverse,
|
||||||
isMobile && config.axisConfig.hideOnMobile
|
isMobile && config.axisConfig.hideOnMobile ? false : config.axisConfig.display,
|
||||||
? false
|
|
||||||
: config.axisConfig.display,
|
|
||||||
config.axisConfig.position,
|
config.axisConfig.position,
|
||||||
config.axisConfig.displayName,
|
config.axisConfig.displayName
|
||||||
);
|
|
||||||
return generateDataset(
|
|
||||||
config.title,
|
|
||||||
histories[config.field],
|
|
||||||
config.color,
|
|
||||||
config.axisId,
|
|
||||||
);
|
);
|
||||||
|
return generateDataset(config.title, histories[config.field], config.color, config.axisId);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
@ -298,9 +256,7 @@ export default function PlayerRankChart({ player }: Props) {
|
|||||||
callbacks: {
|
callbacks: {
|
||||||
label(context: any) {
|
label(context: any) {
|
||||||
const value = Number(context.parsed.y);
|
const value = Number(context.parsed.y);
|
||||||
const config = datasetConfig.find(
|
const config = datasetConfig.find(cfg => cfg.title === context.dataset.label);
|
||||||
(cfg) => cfg.title === context.dataset.label,
|
|
||||||
);
|
|
||||||
return config?.labelFormatter(value) ?? "";
|
return config?.labelFormatter(value) ?? "";
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -14,8 +14,7 @@ import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player";
|
|||||||
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
import { scoresaberService } from "@/common/service/impl/scoresaber";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { clsx } from "clsx";
|
import { clsx } from "clsx";
|
||||||
|
import { useDebounce } from "@uidotdev/usehooks";
|
||||||
const INPUT_DEBOUNCE_DELAY = 250; // milliseconds
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
initialScoreData?: ScoreSaberPlayerScoresPageToken;
|
initialScoreData?: ScoreSaberPlayerScoresPageToken;
|
||||||
@ -49,40 +48,19 @@ const scoreAnimation: Variants = {
|
|||||||
visible: { opacity: 1, x: 0, transition: { staggerChildren: 0.03 } },
|
visible: { opacity: 1, x: 0, transition: { staggerChildren: 0.03 } },
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function PlayerScores({
|
export default function PlayerScores({ initialScoreData, initialSearch, player, sort, page }: Props) {
|
||||||
initialScoreData,
|
|
||||||
initialSearch,
|
|
||||||
player,
|
|
||||||
sort,
|
|
||||||
page,
|
|
||||||
}: Props) {
|
|
||||||
const { width } = useWindowDimensions();
|
const { width } = useWindowDimensions();
|
||||||
const controls = useAnimation();
|
const controls = useAnimation();
|
||||||
|
|
||||||
const [pageState, setPageState] = useState<PageState>({ page, sort });
|
const [pageState, setPageState] = useState<PageState>({ page, sort });
|
||||||
const [previousPage, setPreviousPage] = useState(page);
|
const [previousPage, setPreviousPage] = useState(page);
|
||||||
const [currentScores, setCurrentScores] = useState<
|
const [currentScores, setCurrentScores] = useState<ScoreSaberPlayerScoresPageToken | undefined>(initialScoreData);
|
||||||
ScoreSaberPlayerScoresPageToken | undefined
|
const [searchTerm, setSearchTerm] = useState(initialSearch || "");
|
||||||
>(initialScoreData);
|
const debouncedSearchTerm = useDebounce(searchTerm, 250);
|
||||||
const [searchState, setSearchState] = useState({
|
|
||||||
query: initialSearch || "",
|
|
||||||
});
|
|
||||||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(
|
|
||||||
initialSearch || "",
|
|
||||||
);
|
|
||||||
|
|
||||||
const isSearchActive = debouncedSearchTerm.length >= 3;
|
const isSearchActive = debouncedSearchTerm.length >= 3;
|
||||||
const [shouldFetch, setShouldFetch] = useState(false); // New state to control fetching
|
const [shouldFetch, setShouldFetch] = useState(false); // New state to control fetching
|
||||||
|
|
||||||
// Debounce the search query
|
|
||||||
useEffect(() => {
|
|
||||||
const handler = setTimeout(() => {
|
|
||||||
setDebouncedSearchTerm(searchState.query);
|
|
||||||
}, INPUT_DEBOUNCE_DELAY);
|
|
||||||
|
|
||||||
return () => clearTimeout(handler);
|
|
||||||
}, [searchState.query]);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: scores,
|
data: scores,
|
||||||
isError,
|
isError,
|
||||||
@ -98,15 +76,11 @@ export default function PlayerScores({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
staleTime: 30 * 1000, // 30 seconds
|
staleTime: 30 * 1000, // 30 seconds
|
||||||
enabled:
|
enabled: shouldFetch && (debouncedSearchTerm.length >= 3 || debouncedSearchTerm.length === 0), // Only enable if we set shouldFetch to true
|
||||||
shouldFetch &&
|
|
||||||
(debouncedSearchTerm.length >= 3 || debouncedSearchTerm.length === 0), // Only enable if we set shouldFetch to true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleScoreLoad = useCallback(async () => {
|
const handleScoreLoad = useCallback(async () => {
|
||||||
await controls.start(
|
await controls.start(previousPage >= pageState.page ? "hiddenRight" : "hiddenLeft");
|
||||||
previousPage >= pageState.page ? "hiddenRight" : "hiddenLeft",
|
|
||||||
);
|
|
||||||
setCurrentScores(scores);
|
setCurrentScores(scores);
|
||||||
await controls.start("visible");
|
await controls.start("visible");
|
||||||
}, [scores, controls, previousPage, pageState.page]);
|
}, [scores, controls, previousPage, pageState.page]);
|
||||||
@ -124,15 +98,11 @@ export default function PlayerScores({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newUrl = `/player/${player.id}/${pageState.sort}/${pageState.page}${isSearchActive ? `?search=${debouncedSearchTerm}` : ""}`;
|
const newUrl = `/player/${player.id}/${pageState.sort}/${pageState.page}${isSearchActive ? `?search=${debouncedSearchTerm}` : ""}`;
|
||||||
window.history.replaceState(
|
window.history.replaceState({ ...window.history.state, as: newUrl, url: newUrl }, "", newUrl);
|
||||||
{ ...window.history.state, as: newUrl, url: newUrl },
|
|
||||||
"",
|
|
||||||
newUrl,
|
|
||||||
);
|
|
||||||
}, [pageState, debouncedSearchTerm, player.id, isSearchActive]);
|
}, [pageState, debouncedSearchTerm, player.id, isSearchActive]);
|
||||||
|
|
||||||
const handleSearchChange = (query: string) => {
|
const handleSearchChange = (query: string) => {
|
||||||
setSearchState({ query });
|
setSearchTerm(query);
|
||||||
if (query.length >= 3) {
|
if (query.length >= 3) {
|
||||||
setShouldFetch(true); // Set to true to trigger fetch
|
setShouldFetch(true); // Set to true to trigger fetch
|
||||||
} else {
|
} else {
|
||||||
@ -141,23 +111,18 @@ export default function PlayerScores({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const clearSearch = () => {
|
const clearSearch = () => {
|
||||||
setSearchState({ query: "" });
|
setSearchTerm("");
|
||||||
setDebouncedSearchTerm(""); // Clear the debounced term
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const invalidSearch =
|
const invalidSearch = searchTerm.length >= 1 && searchTerm.length < 3;
|
||||||
searchState.query.length >= 1 && searchState.query.length < 3;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="flex gap-1">
|
<Card className="flex gap-1">
|
||||||
<div className="flex flex-col items-center w-full gap-2 relative">
|
<div className="flex flex-col items-center w-full gap-2 relative">
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
{scoreSort.map((sortOption) => (
|
{scoreSort.map(sortOption => (
|
||||||
<Button
|
<Button
|
||||||
key={sortOption.value}
|
key={sortOption.value}
|
||||||
variant={
|
variant={sortOption.value === pageState.sort ? "default" : "outline"}
|
||||||
sortOption.value === pageState.sort ? "default" : "outline"
|
|
||||||
}
|
|
||||||
onClick={() => handleSortChange(sortOption.value)}
|
onClick={() => handleSortChange(sortOption.value)}
|
||||||
size="sm"
|
size="sm"
|
||||||
className="flex items-center gap-1"
|
className="flex items-center gap-1"
|
||||||
@ -174,12 +139,12 @@ export default function PlayerScores({
|
|||||||
placeholder="Search..."
|
placeholder="Search..."
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"pr-10", // Add padding right for the clear button
|
"pr-10", // Add padding right for the clear button
|
||||||
invalidSearch && "border-red-500",
|
invalidSearch && "border-red-500"
|
||||||
)}
|
)}
|
||||||
value={searchState.query}
|
value={searchTerm}
|
||||||
onChange={(e) => handleSearchChange(e.target.value)}
|
onChange={e => handleSearchChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
{searchState.query && ( // Show clear button only if there's a query
|
{searchTerm && ( // Show clear button only if there's a query
|
||||||
<button
|
<button
|
||||||
onClick={clearSearch}
|
onClick={clearSearch}
|
||||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-300 hover:brightness-75 transform-gpu transition-all cursor-default"
|
className="absolute right-2 top-1/2 -translate-y-1/2 text-gray-300 hover:brightness-75 transform-gpu transition-all cursor-default"
|
||||||
@ -194,10 +159,7 @@ export default function PlayerScores({
|
|||||||
{currentScores && (
|
{currentScores && (
|
||||||
<>
|
<>
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
{isError ||
|
{isError || (currentScores.playerScores.length === 0 && <p>No scores found. Invalid Page or Search?</p>)}
|
||||||
(currentScores.playerScores.length === 0 && (
|
|
||||||
<p>No scores found. Invalid Page or Search?</p>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<motion.div
|
<motion.div
|
||||||
@ -216,12 +178,9 @@ export default function PlayerScores({
|
|||||||
<Pagination
|
<Pagination
|
||||||
mobilePagination={width < 768}
|
mobilePagination={width < 768}
|
||||||
page={pageState.page}
|
page={pageState.page}
|
||||||
totalPages={Math.ceil(
|
totalPages={Math.ceil(currentScores.metadata.total / currentScores.metadata.itemsPerPage)}
|
||||||
currentScores.metadata.total /
|
|
||||||
currentScores.metadata.itemsPerPage,
|
|
||||||
)}
|
|
||||||
loadingPage={isLoading ? pageState.page : undefined}
|
loadingPage={isLoading ? pageState.page : undefined}
|
||||||
onPageChange={(newPage) => {
|
onPageChange={newPage => {
|
||||||
setPreviousPage(pageState.page);
|
setPreviousPage(pageState.page);
|
||||||
setPageState({ ...pageState, page: newPage });
|
setPageState({ ...pageState, page: newPage });
|
||||||
setShouldFetch(true); // Set to true to trigger fetch on page change
|
setShouldFetch(true); // Set to true to trigger fetch on page change
|
||||||
|
@ -56,23 +56,14 @@ type Props = {
|
|||||||
|
|
||||||
export default function PlayerStats({ player }: Props) {
|
export default function PlayerStats({ player }: Props) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={`flex flex-wrap gap-2 w-full justify-center lg:justify-start`}>
|
||||||
className={`flex flex-wrap gap-2 w-full justify-center lg:justify-start`}
|
|
||||||
>
|
|
||||||
{badges.map((badge, index) => {
|
{badges.map((badge, index) => {
|
||||||
const toRender = badge.create(player);
|
const toRender = badge.create(player);
|
||||||
if (toRender === undefined) {
|
if (toRender === undefined) {
|
||||||
return <div key={index} />;
|
return <div key={index} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <StatValue key={index} color={badge.color} name={badge.name} value={toRender} />;
|
||||||
<StatValue
|
|
||||||
key={index}
|
|
||||||
color={badge.color}
|
|
||||||
name={badge.name}
|
|
||||||
value={toRender}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -18,12 +18,7 @@ type Props = {
|
|||||||
export default function PlayerTrackedStatus({ player }: Props) {
|
export default function PlayerTrackedStatus({ player }: Props) {
|
||||||
const { data, isLoading, isError } = useQuery({
|
const { data, isLoading, isError } = useQuery({
|
||||||
queryKey: ["playerIsBeingTracked", player.id],
|
queryKey: ["playerIsBeingTracked", player.id],
|
||||||
queryFn: () =>
|
queryFn: () => ky.get<PlayerTrackedSince>(`${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`).json(),
|
||||||
ky
|
|
||||||
.get<PlayerTrackedSince>(
|
|
||||||
`${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`,
|
|
||||||
)
|
|
||||||
.json(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLoading || isError || !data?.tracked) {
|
if (isLoading || isError || !data?.tracked) {
|
||||||
|
@ -9,7 +9,5 @@ type Props = {
|
|||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
export function QueryProvider({ children }: Props) {
|
export function QueryProvider({ children }: Props) {
|
||||||
return (
|
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>;
|
||||||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,7 @@ type Variants = {
|
|||||||
itemsPerPage: number;
|
itemsPerPage: number;
|
||||||
icon: (player: ScoreSaberPlayer) => ReactElement;
|
icon: (player: ScoreSaberPlayer) => ReactElement;
|
||||||
getPage: (player: ScoreSaberPlayer, itemsPerPage: number) => number;
|
getPage: (player: ScoreSaberPlayer, itemsPerPage: number) => number;
|
||||||
query: (
|
query: (page: number, country: string) => Promise<ScoreSaberPlayersPageToken | undefined>;
|
||||||
page: number,
|
|
||||||
country: string,
|
|
||||||
) => Promise<ScoreSaberPlayersPageToken | undefined>;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -95,7 +92,7 @@ export default function Mini({ type, player }: MiniProps) {
|
|||||||
let players = data; // So we can update it later
|
let players = data; // So we can update it later
|
||||||
if (players && (!isLoading || !isError)) {
|
if (players && (!isLoading || !isError)) {
|
||||||
// Find the player's position and show 3 players above and 1 below
|
// Find the player's position and show 3 players above and 1 below
|
||||||
const playerPosition = players.findIndex((p) => p.id === player.id);
|
const playerPosition = players.findIndex(p => p.id === player.id);
|
||||||
players = players.slice(playerPosition - 3, playerPosition + 2);
|
players = players.slice(playerPosition - 3, playerPosition + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +106,7 @@ export default function Mini({ type, player }: MiniProps) {
|
|||||||
{isLoading && <p className="text-gray-400">Loading...</p>}
|
{isLoading && <p className="text-gray-400">Loading...</p>}
|
||||||
{isError && <p className="text-red-500">Error</p>}
|
{isError && <p className="text-red-500">Error</p>}
|
||||||
{players?.map((playerRanking, index) => {
|
{players?.map((playerRanking, index) => {
|
||||||
const rank =
|
const rank = type == "Global" ? playerRanking.rank : playerRanking.countryRank;
|
||||||
type == "Global" ? playerRanking.rank : playerRanking.countryRank;
|
|
||||||
const playerName =
|
const playerName =
|
||||||
playerRanking.name.length > PLAYER_NAME_MAX_LENGTH
|
playerRanking.name.length > PLAYER_NAME_MAX_LENGTH
|
||||||
? playerRanking.name.substring(0, PLAYER_NAME_MAX_LENGTH) + "..."
|
? playerRanking.name.substring(0, PLAYER_NAME_MAX_LENGTH) + "..."
|
||||||
@ -126,29 +122,14 @@ export default function Mini({ type, player }: MiniProps) {
|
|||||||
<p className="text-gray-400">#{formatNumberWithCommas(rank)}</p>
|
<p className="text-gray-400">#{formatNumberWithCommas(rank)}</p>
|
||||||
<div className="flex gap-1 items-center">
|
<div className="flex gap-1 items-center">
|
||||||
<Avatar className="w-6 h-6 pointer-events-none">
|
<Avatar className="w-6 h-6 pointer-events-none">
|
||||||
<AvatarImage
|
<AvatarImage alt="Profile Picture" src={playerRanking.profilePicture} />
|
||||||
alt="Profile Picture"
|
|
||||||
src={playerRanking.profilePicture}
|
|
||||||
/>
|
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<p
|
<p className={playerRanking.id === player.id ? "text-pp font-semibold" : ""}>{playerName}</p>
|
||||||
className={
|
|
||||||
playerRanking.id === player.id
|
|
||||||
? "text-pp font-semibold"
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{playerName}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="inline-flex min-w-[10.75em] gap-1 items-center">
|
<div className="inline-flex min-w-[10.75em] gap-1 items-center">
|
||||||
<p className="text-pp text-right">
|
<p className="text-pp text-right">{formatPp(playerRanking.pp)}pp</p>
|
||||||
{formatPp(playerRanking.pp)}pp
|
|
||||||
</p>
|
|
||||||
{playerRanking.id !== player.id && (
|
{playerRanking.id !== player.id && (
|
||||||
<p
|
<p className={`text-xs text-right ${ppDifference > 0 ? "text-green-400" : "text-red-400"}`}>
|
||||||
className={`text-xs text-right ${ppDifference > 0 ? "text-green-400" : "text-red-400"}`}
|
|
||||||
>
|
|
||||||
{ppDifference > 0 ? "+" : ""}
|
{ppDifference > 0 ? "+" : ""}
|
||||||
{formatPp(ppDifference)}
|
{formatPp(ppDifference)}
|
||||||
</p>
|
</p>
|
||||||
|
@ -8,10 +8,7 @@ type Props = {
|
|||||||
setIsLeaderboardExpanded: Dispatch<SetStateAction<boolean>>;
|
setIsLeaderboardExpanded: Dispatch<SetStateAction<boolean>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function LeaderboardButton({
|
export default function LeaderboardButton({ isLeaderboardExpanded, setIsLeaderboardExpanded }: Props) {
|
||||||
isLeaderboardExpanded,
|
|
||||||
setIsLeaderboardExpanded,
|
|
||||||
}: Props) {
|
|
||||||
return (
|
return (
|
||||||
<div className="pr-2 flex items-center justify-center h-full cursor-default">
|
<div className="pr-2 flex items-center justify-center h-full cursor-default">
|
||||||
<Button
|
<Button
|
||||||
@ -20,10 +17,7 @@ export default function LeaderboardButton({
|
|||||||
onClick={() => setIsLeaderboardExpanded(!isLeaderboardExpanded)}
|
onClick={() => setIsLeaderboardExpanded(!isLeaderboardExpanded)}
|
||||||
>
|
>
|
||||||
<ArrowDownIcon
|
<ArrowDownIcon
|
||||||
className={clsx(
|
className={clsx("w-6 h-6 transition-all transform-gpu", isLeaderboardExpanded ? "" : "rotate-180")}
|
||||||
"w-6 h-6 transition-all transform-gpu",
|
|
||||||
isLeaderboardExpanded ? "" : "rotate-180",
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/components/ui/tooltip";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
/**
|
/**
|
||||||
|
@ -53,10 +53,7 @@ export default function ScoreButtons({
|
|||||||
{/* Open map in BeatSaver */}
|
{/* Open map in BeatSaver */}
|
||||||
<ScoreButton
|
<ScoreButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
window.open(
|
window.open(`https://beatsaver.com/maps/${beatSaverMap.bsr}`, "_blank");
|
||||||
`https://beatsaver.com/maps/${beatSaverMap.bsr}`,
|
|
||||||
"_blank",
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
tooltip={<p>Click to open the map</p>}
|
tooltip={<p>Click to open the map</p>}
|
||||||
>
|
>
|
||||||
@ -69,12 +66,8 @@ export default function ScoreButtons({
|
|||||||
<ScoreButton
|
<ScoreButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
window.open(
|
window.open(
|
||||||
songNameToYouTubeLink(
|
songNameToYouTubeLink(leaderboard.songName, leaderboard.songSubName, leaderboard.songAuthorName),
|
||||||
leaderboard.songName,
|
"_blank"
|
||||||
leaderboard.songSubName,
|
|
||||||
leaderboard.songAuthorName,
|
|
||||||
),
|
|
||||||
"_blank",
|
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
tooltip={<p>Click to open the song in YouTube</p>}
|
tooltip={<p>Click to open the song in YouTube</p>}
|
||||||
|
@ -14,13 +14,9 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function ScoreSongInfo({ leaderboard, beatSaverMap }: Props) {
|
export default function ScoreSongInfo({ leaderboard, beatSaverMap }: Props) {
|
||||||
const diff = getDifficultyFromScoreSaberDifficulty(
|
const diff = getDifficultyFromScoreSaberDifficulty(leaderboard.difficulty.difficulty);
|
||||||
leaderboard.difficulty.difficulty,
|
|
||||||
);
|
|
||||||
const mappersProfile =
|
const mappersProfile =
|
||||||
beatSaverMap != undefined
|
beatSaverMap != undefined ? `https://beatsaver.com/profile/${beatSaverMap?.fullData.uploader.id}` : undefined;
|
||||||
? `https://beatsaver.com/profile/${beatSaverMap?.fullData.uploader.id}`
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-3 items-center">
|
<div className="flex gap-3 items-center">
|
||||||
@ -72,13 +68,7 @@ export default function ScoreSongInfo({ leaderboard, beatSaverMap }: Props) {
|
|||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-400">{leaderboard.songAuthorName}</p>
|
<p className="text-sm text-gray-400">{leaderboard.songAuthorName}</p>
|
||||||
<FallbackLink href={mappersProfile}>
|
<FallbackLink href={mappersProfile}>
|
||||||
<p
|
<p className={clsx("text-sm", mappersProfile && "hover:brightness-75 transform-gpu transition-all")}>
|
||||||
className={clsx(
|
|
||||||
"text-sm",
|
|
||||||
mappersProfile &&
|
|
||||||
"hover:brightness-75 transform-gpu transition-all",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{leaderboard.levelAuthorName}
|
{leaderboard.levelAuthorName}
|
||||||
</p>
|
</p>
|
||||||
</FallbackLink>
|
</FallbackLink>
|
||||||
|
@ -26,9 +26,7 @@ export default function ScoreRankInfo({ score }: Props) {
|
|||||||
</p>
|
</p>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<p className="text-sm cursor-default">
|
<p className="text-sm cursor-default">{timeAgo(new Date(score.timeSet))}</p>
|
||||||
{timeAgo(new Date(score.timeSet))}
|
|
||||||
</p>
|
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -9,13 +9,10 @@ import Tooltip from "@/components/tooltip";
|
|||||||
|
|
||||||
type Badge = {
|
type Badge = {
|
||||||
name: string;
|
name: string;
|
||||||
color?: (
|
color?: (score: ScoreSaberScoreToken, leaderboard: ScoreSaberLeaderboardToken) => string | undefined;
|
||||||
score: ScoreSaberScoreToken,
|
|
||||||
leaderboard: ScoreSaberLeaderboardToken,
|
|
||||||
) => string | undefined;
|
|
||||||
create: (
|
create: (
|
||||||
score: ScoreSaberScoreToken,
|
score: ScoreSaberScoreToken,
|
||||||
leaderboard: ScoreSaberLeaderboardToken,
|
leaderboard: ScoreSaberLeaderboardToken
|
||||||
) => string | React.ReactNode | undefined;
|
) => string | React.ReactNode | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -35,17 +32,11 @@ const badges: Badge[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Accuracy",
|
name: "Accuracy",
|
||||||
color: (
|
color: (score: ScoreSaberScoreToken, leaderboard: ScoreSaberLeaderboardToken) => {
|
||||||
score: ScoreSaberScoreToken,
|
|
||||||
leaderboard: ScoreSaberLeaderboardToken,
|
|
||||||
) => {
|
|
||||||
const acc = (score.baseScore / leaderboard.maxScore) * 100;
|
const acc = (score.baseScore / leaderboard.maxScore) * 100;
|
||||||
return getScoreBadgeFromAccuracy(acc).color;
|
return getScoreBadgeFromAccuracy(acc).color;
|
||||||
},
|
},
|
||||||
create: (
|
create: (score: ScoreSaberScoreToken, leaderboard: ScoreSaberLeaderboardToken) => {
|
||||||
score: ScoreSaberScoreToken,
|
|
||||||
leaderboard: ScoreSaberLeaderboardToken,
|
|
||||||
) => {
|
|
||||||
const acc = (score.baseScore / leaderboard.maxScore) * 100;
|
const acc = (score.baseScore / leaderboard.maxScore) * 100;
|
||||||
const scoreBadge = getScoreBadgeFromAccuracy(acc);
|
const scoreBadge = getScoreBadgeFromAccuracy(acc);
|
||||||
let accDetails = `Accuracy ${scoreBadge.name != "-" ? scoreBadge.name : ""}`;
|
let accDetails = `Accuracy ${scoreBadge.name != "-" ? scoreBadge.name : ""}`;
|
||||||
@ -93,16 +84,8 @@ const badges: Badge[] = [
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<p>
|
<p>{fullCombo ? <span className="text-green-400">FC</span> : formatNumberWithCommas(score.missedNotes)}</p>
|
||||||
{fullCombo ? (
|
<XMarkIcon className={clsx("w-5 h-5", fullCombo ? "hidden" : "text-red-400")} />
|
||||||
<span className="text-green-400">FC</span>
|
|
||||||
) : (
|
|
||||||
formatNumberWithCommas(score.missedNotes)
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
<XMarkIcon
|
|
||||||
className={clsx("w-5 h-5", fullCombo ? "hidden" : "text-red-400")}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -22,7 +22,7 @@ export default function StatValue({ name, color, value }: Props) {
|
|||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"flex min-w-16 gap-2 h-[28px] p-1 items-center justify-center rounded-md text-sm",
|
"flex min-w-16 gap-2 h-[28px] p-1 items-center justify-center rounded-md text-sm",
|
||||||
color ? color : "bg-accent",
|
color ? color : "bg-accent"
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: (!color?.includes("bg") && color) || undefined,
|
backgroundColor: (!color?.includes("bg") && color) || undefined,
|
||||||
@ -34,9 +34,7 @@ export default function StatValue({ name, color, value }: Props) {
|
|||||||
<div className="h-4 w-[1px] bg-primary" />
|
<div className="h-4 w-[1px] bg-primary" />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div className="flex gap-1 items-center">
|
<div className="flex gap-1 items-center">{typeof value === "string" ? <p>{value}</p> : value}</div>
|
||||||
{typeof value === "string" ? <p>{value}</p> : value}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { Tooltip as ShadCnTooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
||||||
Tooltip as ShadCnTooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "./ui/tooltip";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
/**
|
/**
|
||||||
|
@ -11,10 +11,7 @@ const Avatar = React.forwardRef<
|
|||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<AvatarPrimitive.Root
|
<AvatarPrimitive.Root
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full", className)}
|
||||||
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
@ -24,11 +21,7 @@ const AvatarImage = React.forwardRef<
|
|||||||
React.ElementRef<typeof AvatarPrimitive.Image>,
|
React.ElementRef<typeof AvatarPrimitive.Image>,
|
||||||
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<AvatarPrimitive.Image
|
<AvatarPrimitive.Image ref={ref} className={cn("aspect-square h-full w-full", className)} {...props} />
|
||||||
ref={ref}
|
|
||||||
className={cn("aspect-square h-full w-full", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
));
|
||||||
AvatarImage.displayName = AvatarPrimitive.Image.displayName;
|
AvatarImage.displayName = AvatarPrimitive.Image.displayName;
|
||||||
|
|
||||||
@ -38,10 +31,7 @@ const AvatarFallback = React.forwardRef<
|
|||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<AvatarPrimitive.Fallback
|
<AvatarPrimitive.Fallback
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn("flex h-full w-full items-center justify-center rounded-full bg-muted", className)}
|
||||||
"flex h-full w-full items-center justify-center rounded-full bg-muted",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
@ -9,14 +9,10 @@ const buttonVariants = cva(
|
|||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default:
|
default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
||||||
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
|
destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
||||||
destructive:
|
outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
||||||
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
|
secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
||||||
outline:
|
|
||||||
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
|
|
||||||
secondary:
|
|
||||||
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
|
|
||||||
ghost: "hover:bg-accent hover:text-accent-foreground",
|
ghost: "hover:bg-accent hover:text-accent-foreground",
|
||||||
link: "text-primary underline-offset-4 hover:underline",
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
},
|
},
|
||||||
@ -31,7 +27,7 @@ const buttonVariants = cva(
|
|||||||
variant: "default",
|
variant: "default",
|
||||||
size: "default",
|
size: "default",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface ButtonProps
|
export interface ButtonProps
|
||||||
@ -43,14 +39,8 @@ export interface ButtonProps
|
|||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||||
({ className, variant, size, asChild = false, ...props }, ref) => {
|
({ className, variant, size, asChild = false, ...props }, ref) => {
|
||||||
const Comp = asChild ? Slot : "button";
|
const Comp = asChild ? Slot : "button";
|
||||||
return (
|
return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />;
|
||||||
<Comp
|
}
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
|
||||||
ref={ref}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
Button.displayName = "Button";
|
Button.displayName = "Button";
|
||||||
|
|
||||||
|
@ -2,82 +2,40 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/common/utils";
|
import { cn } from "@/common/utils";
|
||||||
|
|
||||||
const Card = React.forwardRef<
|
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => (
|
||||||
HTMLDivElement,
|
<div ref={ref} className={cn("rounded-xl border bg-card text-card-foreground shadow", className)} {...props} />
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<div
|
|
||||||
ref={ref}
|
|
||||||
className={cn(
|
|
||||||
"rounded-xl border bg-card text-card-foreground shadow",
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
));
|
||||||
Card.displayName = "Card";
|
Card.displayName = "Card";
|
||||||
|
|
||||||
const CardHeader = React.forwardRef<
|
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||||
HTMLDivElement,
|
({ className, ...props }, ref) => (
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
<div ref={ref} className={cn("flex flex-col space-y-1.5 p-6", className)} {...props} />
|
||||||
>(({ className, ...props }, ref) => (
|
)
|
||||||
<div
|
);
|
||||||
ref={ref}
|
|
||||||
className={cn("flex flex-col space-y-1.5 p-6", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
CardHeader.displayName = "CardHeader";
|
CardHeader.displayName = "CardHeader";
|
||||||
|
|
||||||
const CardTitle = React.forwardRef<
|
const CardTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
|
||||||
HTMLParagraphElement,
|
({ className, ...props }, ref) => (
|
||||||
React.HTMLAttributes<HTMLHeadingElement>
|
<h3 ref={ref} className={cn("font-semibold leading-none tracking-tight", className)} {...props} />
|
||||||
>(({ className, ...props }, ref) => (
|
)
|
||||||
<h3
|
);
|
||||||
ref={ref}
|
|
||||||
className={cn("font-semibold leading-none tracking-tight", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
CardTitle.displayName = "CardTitle";
|
CardTitle.displayName = "CardTitle";
|
||||||
|
|
||||||
const CardDescription = React.forwardRef<
|
const CardDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
||||||
HTMLParagraphElement,
|
({ className, ...props }, ref) => (
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
<p ref={ref} className={cn("text-sm text-muted-foreground", className)} {...props} />
|
||||||
>(({ className, ...props }, ref) => (
|
)
|
||||||
<p
|
);
|
||||||
ref={ref}
|
|
||||||
className={cn("text-sm text-muted-foreground", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
CardDescription.displayName = "CardDescription";
|
CardDescription.displayName = "CardDescription";
|
||||||
|
|
||||||
const CardContent = React.forwardRef<
|
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||||
HTMLDivElement,
|
({ className, ...props }, ref) => <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
);
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
|
|
||||||
));
|
|
||||||
CardContent.displayName = "CardContent";
|
CardContent.displayName = "CardContent";
|
||||||
|
|
||||||
const CardFooter = React.forwardRef<
|
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||||
HTMLDivElement,
|
({ className, ...props }, ref) => <div ref={ref} className={cn("flex items-center p-6 pt-0", className)} {...props} />
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
);
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<div
|
|
||||||
ref={ref}
|
|
||||||
className={cn("flex items-center p-6 pt-0", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
CardFooter.displayName = "CardFooter";
|
CardFooter.displayName = "CardFooter";
|
||||||
|
|
||||||
export {
|
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
|
||||||
Card,
|
|
||||||
CardContent,
|
|
||||||
CardDescription,
|
|
||||||
CardFooter,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle,
|
|
||||||
};
|
|
||||||
|
@ -3,14 +3,7 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as LabelPrimitive from "@radix-ui/react-label";
|
import * as LabelPrimitive from "@radix-ui/react-label";
|
||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import {
|
import { Controller, ControllerProps, FieldPath, FieldValues, FormProvider, useFormContext } from "react-hook-form";
|
||||||
Controller,
|
|
||||||
ControllerProps,
|
|
||||||
FieldPath,
|
|
||||||
FieldValues,
|
|
||||||
FormProvider,
|
|
||||||
useFormContext,
|
|
||||||
} from "react-hook-form";
|
|
||||||
|
|
||||||
import { cn } from "@/common/utils";
|
import { cn } from "@/common/utils";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
@ -24,9 +17,7 @@ type FormFieldContextValue<
|
|||||||
name: TName;
|
name: TName;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FormFieldContext = React.createContext<FormFieldContextValue>(
|
const FormFieldContext = React.createContext<FormFieldContextValue>({} as FormFieldContextValue);
|
||||||
{} as FormFieldContextValue,
|
|
||||||
);
|
|
||||||
|
|
||||||
const FormField = <
|
const FormField = <
|
||||||
TFieldValues extends FieldValues = FieldValues,
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
@ -68,14 +59,10 @@ type FormItemContextValue = {
|
|||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FormItemContext = React.createContext<FormItemContextValue>(
|
const FormItemContext = React.createContext<FormItemContextValue>({} as FormItemContextValue);
|
||||||
{} as FormItemContextValue,
|
|
||||||
);
|
|
||||||
|
|
||||||
const FormItem = React.forwardRef<
|
const FormItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
|
||||||
HTMLDivElement,
|
({ className, ...props }, ref) => {
|
||||||
React.HTMLAttributes<HTMLDivElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const id = React.useId();
|
const id = React.useId();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -83,7 +70,8 @@ const FormItem = React.forwardRef<
|
|||||||
<div ref={ref} className={cn("space-y-2", className)} {...props} />
|
<div ref={ref} className={cn("space-y-2", className)} {...props} />
|
||||||
</FormItemContext.Provider>
|
</FormItemContext.Provider>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
FormItem.displayName = "FormItem";
|
FormItem.displayName = "FormItem";
|
||||||
|
|
||||||
const FormLabel = React.forwardRef<
|
const FormLabel = React.forwardRef<
|
||||||
@ -92,61 +80,40 @@ const FormLabel = React.forwardRef<
|
|||||||
>(({ className, ...props }, ref) => {
|
>(({ className, ...props }, ref) => {
|
||||||
const { error, formItemId } = useFormField();
|
const { error, formItemId } = useFormField();
|
||||||
|
|
||||||
return (
|
return <Label ref={ref} className={cn(error && "text-destructive", className)} htmlFor={formItemId} {...props} />;
|
||||||
<Label
|
|
||||||
ref={ref}
|
|
||||||
className={cn(error && "text-destructive", className)}
|
|
||||||
htmlFor={formItemId}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
FormLabel.displayName = "FormLabel";
|
FormLabel.displayName = "FormLabel";
|
||||||
|
|
||||||
const FormControl = React.forwardRef<
|
const FormControl = React.forwardRef<React.ElementRef<typeof Slot>, React.ComponentPropsWithoutRef<typeof Slot>>(
|
||||||
React.ElementRef<typeof Slot>,
|
({ ...props }, ref) => {
|
||||||
React.ComponentPropsWithoutRef<typeof Slot>
|
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
||||||
>(({ ...props }, ref) => {
|
|
||||||
const { error, formItemId, formDescriptionId, formMessageId } =
|
|
||||||
useFormField();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slot
|
<Slot
|
||||||
ref={ref}
|
ref={ref}
|
||||||
id={formItemId}
|
id={formItemId}
|
||||||
aria-describedby={
|
aria-describedby={!error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`}
|
||||||
!error
|
|
||||||
? `${formDescriptionId}`
|
|
||||||
: `${formDescriptionId} ${formMessageId}`
|
|
||||||
}
|
|
||||||
aria-invalid={!!error}
|
aria-invalid={!!error}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
FormControl.displayName = "FormControl";
|
FormControl.displayName = "FormControl";
|
||||||
|
|
||||||
const FormDescription = React.forwardRef<
|
const FormDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
||||||
HTMLParagraphElement,
|
({ className, ...props }, ref) => {
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
|
||||||
>(({ className, ...props }, ref) => {
|
|
||||||
const { formDescriptionId } = useFormField();
|
const { formDescriptionId } = useFormField();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<p
|
<p ref={ref} id={formDescriptionId} className={cn("text-[0.8rem] text-muted-foreground", className)} {...props} />
|
||||||
ref={ref}
|
);
|
||||||
id={formDescriptionId}
|
}
|
||||||
className={cn("text-[0.8rem] text-muted-foreground", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
});
|
|
||||||
FormDescription.displayName = "FormDescription";
|
FormDescription.displayName = "FormDescription";
|
||||||
|
|
||||||
const FormMessage = React.forwardRef<
|
const FormMessage = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
|
||||||
HTMLParagraphElement,
|
({ className, children, ...props }, ref) => {
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
|
||||||
>(({ className, children, ...props }, ref) => {
|
|
||||||
const { error, formMessageId } = useFormField();
|
const { error, formMessageId } = useFormField();
|
||||||
const body = error ? String(error?.message) : children;
|
const body = error ? String(error?.message) : children;
|
||||||
|
|
||||||
@ -164,16 +131,8 @@ const FormMessage = React.forwardRef<
|
|||||||
{body}
|
{body}
|
||||||
</p>
|
</p>
|
||||||
);
|
);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
FormMessage.displayName = "FormMessage";
|
FormMessage.displayName = "FormMessage";
|
||||||
|
|
||||||
export {
|
export { useFormField, Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField };
|
||||||
useFormField,
|
|
||||||
Form,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormControl,
|
|
||||||
FormDescription,
|
|
||||||
FormMessage,
|
|
||||||
FormField,
|
|
||||||
};
|
|
||||||
|
@ -2,24 +2,21 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/common/utils";
|
import { cn } from "@/common/utils";
|
||||||
|
|
||||||
export interface InputProps
|
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
|
||||||
extends React.InputHTMLAttributes<HTMLInputElement> {}
|
|
||||||
|
|
||||||
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {
|
||||||
({ className, type, ...props }, ref) => {
|
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
type={type}
|
type={type}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
Input.displayName = "Input";
|
Input.displayName = "Input";
|
||||||
|
|
||||||
export { Input };
|
export { Input };
|
||||||
|
@ -6,20 +6,13 @@ import * as React from "react";
|
|||||||
|
|
||||||
import { cn } from "@/common/utils";
|
import { cn } from "@/common/utils";
|
||||||
|
|
||||||
const labelVariants = cva(
|
const labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
|
||||||
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
||||||
);
|
|
||||||
|
|
||||||
const Label = React.forwardRef<
|
const Label = React.forwardRef<
|
||||||
React.ElementRef<typeof LabelPrimitive.Root>,
|
React.ElementRef<typeof LabelPrimitive.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
|
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants>
|
||||||
VariantProps<typeof labelVariants>
|
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<LabelPrimitive.Root
|
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />
|
||||||
ref={ref}
|
|
||||||
className={cn(labelVariants(), className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
));
|
||||||
Label.displayName = LabelPrimitive.Root.displayName;
|
Label.displayName = LabelPrimitive.Root.displayName;
|
||||||
|
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { ChevronLeftIcon, ChevronRightIcon, DotsHorizontalIcon } from "@radix-ui/react-icons";
|
||||||
ChevronLeftIcon,
|
|
||||||
ChevronRightIcon,
|
|
||||||
DotsHorizontalIcon,
|
|
||||||
} from "@radix-ui/react-icons";
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
|
||||||
import { cn } from "@/common/utils";
|
import { cn } from "@/common/utils";
|
||||||
@ -18,22 +14,14 @@ const Pagination = ({ className, ...props }: React.ComponentProps<"nav">) => (
|
|||||||
);
|
);
|
||||||
Pagination.displayName = "Pagination";
|
Pagination.displayName = "Pagination";
|
||||||
|
|
||||||
const PaginationContent = React.forwardRef<
|
const PaginationContent = React.forwardRef<HTMLUListElement, React.ComponentProps<"ul">>(
|
||||||
HTMLUListElement,
|
({ className, ...props }, ref) => (
|
||||||
React.ComponentProps<"ul">
|
<ul ref={ref} className={cn("flex flex-row items-center gap-1", className)} {...props} />
|
||||||
>(({ className, ...props }, ref) => (
|
)
|
||||||
<ul
|
);
|
||||||
ref={ref}
|
|
||||||
className={cn("flex flex-row items-center gap-1", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
|
||||||
PaginationContent.displayName = "PaginationContent";
|
PaginationContent.displayName = "PaginationContent";
|
||||||
|
|
||||||
const PaginationItem = React.forwardRef<
|
const PaginationItem = React.forwardRef<HTMLLIElement, React.ComponentProps<"li">>(({ className, ...props }, ref) => (
|
||||||
HTMLLIElement,
|
|
||||||
React.ComponentProps<"li">
|
|
||||||
>(({ className, ...props }, ref) => (
|
|
||||||
<li ref={ref} className={cn("", className)} {...props} />
|
<li ref={ref} className={cn("", className)} {...props} />
|
||||||
));
|
));
|
||||||
PaginationItem.displayName = "PaginationItem";
|
PaginationItem.displayName = "PaginationItem";
|
||||||
@ -43,12 +31,7 @@ type PaginationLinkProps = {
|
|||||||
} & Pick<ButtonProps, "size"> &
|
} & Pick<ButtonProps, "size"> &
|
||||||
React.ComponentProps<"a">;
|
React.ComponentProps<"a">;
|
||||||
|
|
||||||
const PaginationLink = ({
|
const PaginationLink = ({ className, isActive, size = "icon", ...props }: PaginationLinkProps) => (
|
||||||
className,
|
|
||||||
isActive,
|
|
||||||
size = "icon",
|
|
||||||
...props
|
|
||||||
}: PaginationLinkProps) => (
|
|
||||||
<a
|
<a
|
||||||
aria-current={isActive ? "page" : undefined}
|
aria-current={isActive ? "page" : undefined}
|
||||||
className={cn(
|
className={cn(
|
||||||
@ -56,52 +39,29 @@ const PaginationLink = ({
|
|||||||
variant: isActive ? "outline" : "ghost",
|
variant: isActive ? "outline" : "ghost",
|
||||||
size,
|
size,
|
||||||
}),
|
}),
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
PaginationLink.displayName = "PaginationLink";
|
PaginationLink.displayName = "PaginationLink";
|
||||||
|
|
||||||
const PaginationPrevious = ({
|
const PaginationPrevious = ({ className, ...props }: React.ComponentProps<typeof PaginationLink>) => (
|
||||||
className,
|
<PaginationLink aria-label="Go to previous page" size="default" className={cn("gap-1", className)} {...props}>
|
||||||
...props
|
|
||||||
}: React.ComponentProps<typeof PaginationLink>) => (
|
|
||||||
<PaginationLink
|
|
||||||
aria-label="Go to previous page"
|
|
||||||
size="default"
|
|
||||||
className={cn("gap-1", className)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<ChevronLeftIcon className="h-4 w-4" />
|
<ChevronLeftIcon className="h-4 w-4" />
|
||||||
</PaginationLink>
|
</PaginationLink>
|
||||||
);
|
);
|
||||||
PaginationPrevious.displayName = "PaginationPrevious";
|
PaginationPrevious.displayName = "PaginationPrevious";
|
||||||
|
|
||||||
const PaginationNext = ({
|
const PaginationNext = ({ className, ...props }: React.ComponentProps<typeof PaginationLink>) => (
|
||||||
className,
|
<PaginationLink aria-label="Go to next page" size="default" className={cn("gap-1", className)} {...props}>
|
||||||
...props
|
|
||||||
}: React.ComponentProps<typeof PaginationLink>) => (
|
|
||||||
<PaginationLink
|
|
||||||
aria-label="Go to next page"
|
|
||||||
size="default"
|
|
||||||
className={cn("gap-1", className)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<ChevronRightIcon className="h-4 w-4" />
|
<ChevronRightIcon className="h-4 w-4" />
|
||||||
</PaginationLink>
|
</PaginationLink>
|
||||||
);
|
);
|
||||||
PaginationNext.displayName = "PaginationNext";
|
PaginationNext.displayName = "PaginationNext";
|
||||||
|
|
||||||
const PaginationEllipsis = ({
|
const PaginationEllipsis = ({ className, ...props }: React.ComponentProps<"span">) => (
|
||||||
className,
|
<span aria-hidden className={cn("flex h-9 w-9 items-center justify-center", className)} {...props}>
|
||||||
...props
|
|
||||||
}: React.ComponentProps<"span">) => (
|
|
||||||
<span
|
|
||||||
aria-hidden
|
|
||||||
className={cn("flex h-9 w-9 items-center justify-center", className)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<DotsHorizontalIcon className="h-4 w-4" />
|
<DotsHorizontalIcon className="h-4 w-4" />
|
||||||
<span className="sr-only">More pages</span>
|
<span className="sr-only">More pages</span>
|
||||||
</span>
|
</span>
|
||||||
|
@ -9,14 +9,8 @@ const ScrollArea = React.forwardRef<
|
|||||||
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
|
||||||
>(({ className, children, ...props }, ref) => (
|
>(({ className, children, ...props }, ref) => (
|
||||||
<ScrollAreaPrimitive.Root
|
<ScrollAreaPrimitive.Root ref={ref} className={cn("relative overflow-hidden", className)} {...props}>
|
||||||
ref={ref}
|
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">{children}</ScrollAreaPrimitive.Viewport>
|
||||||
className={cn("relative overflow-hidden", className)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
|
|
||||||
{children}
|
|
||||||
</ScrollAreaPrimitive.Viewport>
|
|
||||||
<ScrollBar />
|
<ScrollBar />
|
||||||
<ScrollAreaPrimitive.Corner />
|
<ScrollAreaPrimitive.Corner />
|
||||||
</ScrollAreaPrimitive.Root>
|
</ScrollAreaPrimitive.Root>
|
||||||
@ -32,11 +26,9 @@ const ScrollBar = React.forwardRef<
|
|||||||
orientation={orientation}
|
orientation={orientation}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex touch-none select-none transition-colors",
|
"flex touch-none select-none transition-colors",
|
||||||
orientation === "vertical" &&
|
orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]",
|
||||||
"h-full w-2.5 border-l border-l-transparent p-[1px]",
|
orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-[1px]",
|
||||||
orientation === "horizontal" &&
|
className
|
||||||
"h-2.5 flex-col border-t border-t-transparent p-[1px]",
|
|
||||||
className,
|
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
@ -17,7 +17,7 @@ const ToastViewport = React.forwardRef<
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@ -30,28 +30,20 @@ const toastVariants = cva(
|
|||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "border bg-secondary text-foreground",
|
default: "border bg-secondary text-foreground",
|
||||||
destructive:
|
destructive: "destructive group border-destructive bg-destructive text-destructive-foreground",
|
||||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
variant: "default",
|
variant: "default",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const Toast = React.forwardRef<
|
const Toast = React.forwardRef<
|
||||||
React.ElementRef<typeof ToastPrimitives.Root>,
|
React.ElementRef<typeof ToastPrimitives.Root>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & VariantProps<typeof toastVariants>
|
||||||
VariantProps<typeof toastVariants>
|
|
||||||
>(({ className, variant, ...props }, ref) => {
|
>(({ className, variant, ...props }, ref) => {
|
||||||
return (
|
return <ToastPrimitives.Root ref={ref} className={cn(toastVariants({ variant }), className)} {...props} />;
|
||||||
<ToastPrimitives.Root
|
|
||||||
ref={ref}
|
|
||||||
className={cn(toastVariants({ variant }), className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
Toast.displayName = ToastPrimitives.Root.displayName;
|
Toast.displayName = ToastPrimitives.Root.displayName;
|
||||||
|
|
||||||
@ -63,7 +55,7 @@ const ToastAction = React.forwardRef<
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-none focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
@ -78,7 +70,7 @@ const ToastClose = React.forwardRef<
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
"absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
toast-close=""
|
toast-close=""
|
||||||
{...props}
|
{...props}
|
||||||
@ -92,11 +84,7 @@ const ToastTitle = React.forwardRef<
|
|||||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Title
|
<ToastPrimitives.Title ref={ref} className={cn("text-sm font-semibold [&+div]:text-xs", className)} {...props} />
|
||||||
ref={ref}
|
|
||||||
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
));
|
||||||
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
||||||
|
|
||||||
@ -104,11 +92,7 @@ const ToastDescription = React.forwardRef<
|
|||||||
React.ElementRef<typeof ToastPrimitives.Description>,
|
React.ElementRef<typeof ToastPrimitives.Description>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Description
|
<ToastPrimitives.Description ref={ref} className={cn("text-sm opacity-90", className)} {...props} />
|
||||||
ref={ref}
|
|
||||||
className={cn("text-sm opacity-90", className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
));
|
));
|
||||||
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
ToastDescription.displayName = ToastPrimitives.Description.displayName;
|
||||||
|
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import {
|
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport } from "@/components/ui/toast";
|
||||||
Toast,
|
|
||||||
ToastClose,
|
|
||||||
ToastDescription,
|
|
||||||
ToastProvider,
|
|
||||||
ToastTitle,
|
|
||||||
ToastViewport,
|
|
||||||
} from "@/components/ui/toast";
|
|
||||||
|
|
||||||
export function Toaster() {
|
export function Toaster() {
|
||||||
const { toasts } = useToast();
|
const { toasts } = useToast();
|
||||||
@ -20,9 +13,7 @@ export function Toaster() {
|
|||||||
<Toast key={id} {...props}>
|
<Toast key={id} {...props}>
|
||||||
<div className="grid gap-1">
|
<div className="grid gap-1">
|
||||||
{title && <ToastTitle>{title}</ToastTitle>}
|
{title && <ToastTitle>{title}</ToastTitle>}
|
||||||
{description && (
|
{description && <ToastDescription>{description}</ToastDescription>}
|
||||||
<ToastDescription>{description}</ToastDescription>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
{action}
|
{action}
|
||||||
<ToastClose />
|
<ToastClose />
|
||||||
|
@ -20,7 +20,7 @@ const TooltipContent = React.forwardRef<
|
|||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
@ -82,9 +82,7 @@ export const reducer = (state: State, action: Action): State => {
|
|||||||
case "UPDATE_TOAST":
|
case "UPDATE_TOAST":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: state.toasts.map((t) =>
|
toasts: state.toasts.map(t => (t.id === action.toast.id ? { ...t, ...action.toast } : t)),
|
||||||
t.id === action.toast.id ? { ...t, ...action.toast } : t,
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
case "DISMISS_TOAST": {
|
case "DISMISS_TOAST": {
|
||||||
@ -95,20 +93,20 @@ export const reducer = (state: State, action: Action): State => {
|
|||||||
if (toastId) {
|
if (toastId) {
|
||||||
addToRemoveQueue(toastId);
|
addToRemoveQueue(toastId);
|
||||||
} else {
|
} else {
|
||||||
state.toasts.forEach((toast) => {
|
state.toasts.forEach(toast => {
|
||||||
addToRemoveQueue(toast.id);
|
addToRemoveQueue(toast.id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: state.toasts.map((t) =>
|
toasts: state.toasts.map(t =>
|
||||||
t.id === toastId || toastId === undefined
|
t.id === toastId || toastId === undefined
|
||||||
? {
|
? {
|
||||||
...t,
|
...t,
|
||||||
open: false,
|
open: false,
|
||||||
}
|
}
|
||||||
: t,
|
: t
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -121,7 +119,7 @@ export const reducer = (state: State, action: Action): State => {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
toasts: state.toasts.filter(t => t.id !== action.toastId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -132,7 +130,7 @@ let memoryState: State = { toasts: [] };
|
|||||||
|
|
||||||
function dispatch(action: Action) {
|
function dispatch(action: Action) {
|
||||||
memoryState = reducer(memoryState, action);
|
memoryState = reducer(memoryState, action);
|
||||||
listeners.forEach((listener) => {
|
listeners.forEach(listener => {
|
||||||
listener(memoryState);
|
listener(memoryState);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -155,7 +153,7 @@ function toast({ ...props }: Toast) {
|
|||||||
...props,
|
...props,
|
||||||
id,
|
id,
|
||||||
open: true,
|
open: true,
|
||||||
onOpenChange: (open) => {
|
onOpenChange: open => {
|
||||||
if (!open) dismiss();
|
if (!open) dismiss();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -9,9 +9,7 @@ function getWindowDimensions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function useWindowDimensions() {
|
export default function useWindowDimensions() {
|
||||||
const [windowDimensions, setWindowDimensions] = useState(
|
const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
|
||||||
getWindowDimensions(),
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function handleResize() {
|
function handleResize() {
|
||||||
|
@ -19,9 +19,7 @@ client.defineJob({
|
|||||||
|
|
||||||
await io.logger.info("Finding players...");
|
await io.logger.info("Finding players...");
|
||||||
const players: IPlayer[] = await PlayerModel.find({});
|
const players: IPlayer[] = await PlayerModel.find({});
|
||||||
await io.logger.info(
|
await io.logger.info(`Found ${players.length} player${players.length > 1 ? "s" : ""}.`);
|
||||||
`Found ${players.length} player${players.length > 1 ? "s" : ""}.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const dateToday = getMidnightAlignedDate(new Date());
|
const dateToday = getMidnightAlignedDate(new Date());
|
||||||
for (const foundPlayer of players) {
|
for (const foundPlayer of players) {
|
||||||
|
Reference in New Issue
Block a user