mirror of
https://github.com/ershisan99/www.git
synced 2025-12-17 12:34:17 +00:00
wip
This commit is contained in:
19
bun.lock
19
bun.lock
@@ -44,6 +44,7 @@
|
||||
"drizzle-orm": "^0.41.0",
|
||||
"embla-carousel-react": "^8.5.2",
|
||||
"input-otp": "^1.4.2",
|
||||
"ioredis": "^5.6.0",
|
||||
"ky": "^1.8.0",
|
||||
"lucide-react": "^0.487.0",
|
||||
"next": "^15.2.3",
|
||||
@@ -218,6 +219,8 @@
|
||||
|
||||
"@img/sharp-win32-x64": ["@img/sharp-win32-x64@0.33.5", "", { "os": "win32", "cpu": "x64" }, "sha512-MpY/o8/8kj+EcnxwvrP4aTJSWw/aZ7JIGR4aBeZkZw5B7/Jn+tY9/VNwtcoGmdT7GfggGIU4kygOMSbYnOrAbg=="],
|
||||
|
||||
"@ioredis/commands": ["@ioredis/commands@1.2.0", "", {}, "sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg=="],
|
||||
|
||||
"@next/env": ["@next/env@15.2.4", "", {}, "sha512-+SFtMgoiYP3WoSswuNmxJOCwi06TdWE733D+WPjpXIe4LXGULwEaofiiAy6kbS0+XjM5xF5n3lKuBwN2SnqD9g=="],
|
||||
|
||||
"@next/swc-darwin-arm64": ["@next/swc-darwin-arm64@15.2.4", "", { "os": "darwin", "cpu": "arm64" }, "sha512-1AnMfs655ipJEDC/FHkSr0r3lXBgpqKo4K1kiwfUf3iE68rDFXZ1TtHdMvf7D0hMItgDZ7Vuq3JgNMbt/+3bYw=="],
|
||||
@@ -434,6 +437,8 @@
|
||||
|
||||
"clsx": ["clsx@2.1.1", "", {}, "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA=="],
|
||||
|
||||
"cluster-key-slot": ["cluster-key-slot@1.1.2", "", {}, "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA=="],
|
||||
|
||||
"cmdk": ["cmdk@1.1.1", "", { "dependencies": { "@radix-ui/react-compose-refs": "^1.1.1", "@radix-ui/react-dialog": "^1.1.6", "@radix-ui/react-id": "^1.1.0", "@radix-ui/react-primitive": "^2.0.2" }, "peerDependencies": { "react": "^18 || ^19 || ^19.0.0-rc", "react-dom": "^18 || ^19 || ^19.0.0-rc" } }, "sha512-Vsv7kFaXm+ptHDMZ7izaRsP70GgrW9NBNGswt9OZaVBLlE0SNpDq8eu/VGXyF9r7M0azK3Wy7OlYXsuyYLFzHg=="],
|
||||
|
||||
"color": ["color@4.2.3", "", { "dependencies": { "color-convert": "^2.0.1", "color-string": "^1.9.0" } }, "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A=="],
|
||||
@@ -480,6 +485,8 @@
|
||||
|
||||
"decimal.js-light": ["decimal.js-light@2.5.1", "", {}, "sha512-qIMFpTMZmny+MMIitAB6D7iVPEorVw6YQRWkvarTkT4tBeSLLiHzcwj6q0MmYSFCiVpiqPJTJEYIrpcPzVEIvg=="],
|
||||
|
||||
"denque": ["denque@2.1.0", "", {}, "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw=="],
|
||||
|
||||
"detect-libc": ["detect-libc@2.0.3", "", {}, "sha512-bwy0MGW55bG41VqxxypOsdSdGqLwXPI/focwgTYCFMbdUiBAxLg9CFzG08sz2aqzknwiX7Hkl0bQENjg8iLByw=="],
|
||||
|
||||
"detect-node-es": ["detect-node-es@1.1.0", "", {}, "sha512-ypdmJU/TbBby2Dxibuv7ZLW3Bs1QEmM7nHjEANfohJLvE0XVujisn1qPJcZxg+qDucsr+bP6fLD1rPS3AhJ7EQ=="],
|
||||
@@ -522,6 +529,8 @@
|
||||
|
||||
"intl-messageformat": ["intl-messageformat@10.7.16", "", { "dependencies": { "@formatjs/ecma402-abstract": "2.3.4", "@formatjs/fast-memoize": "2.2.7", "@formatjs/icu-messageformat-parser": "2.11.2", "tslib": "^2.8.0" } }, "sha512-UmdmHUmp5CIKKjSoE10la5yfU+AYJAaiYLsodbjL4lji83JNvgOQUjGaGhGrpFCb0Uh7sl7qfP1IyILa8Z40ug=="],
|
||||
|
||||
"ioredis": ["ioredis@5.6.0", "", { "dependencies": { "@ioredis/commands": "^1.1.1", "cluster-key-slot": "^1.1.0", "debug": "^4.3.4", "denque": "^2.1.0", "lodash.defaults": "^4.2.0", "lodash.isarguments": "^3.1.0", "redis-errors": "^1.2.0", "redis-parser": "^3.0.0", "standard-as-callback": "^2.1.0" } }, "sha512-tBZlIIWbndeWBWCXWZiqtOF/yxf6yZX3tAlTJ7nfo5jhd6dctNxF7QnYlZLZ1a0o0pDoen7CgZqO+zjNaFbJAg=="],
|
||||
|
||||
"is-arrayish": ["is-arrayish@0.3.2", "", {}, "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="],
|
||||
|
||||
"is-what": ["is-what@4.1.16", "", {}, "sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A=="],
|
||||
@@ -560,6 +569,10 @@
|
||||
|
||||
"lodash": ["lodash@4.17.21", "", {}, "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="],
|
||||
|
||||
"lodash.defaults": ["lodash.defaults@4.2.0", "", {}, "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ=="],
|
||||
|
||||
"lodash.isarguments": ["lodash.isarguments@3.1.0", "", {}, "sha512-chi4NHZlZqZD18a0imDHnZPrDeBbTtVN7GXMwuGdRH9qotxAjYs3aVLKc7zNOG9eddR5Ksd8rvFEBc9SsggPpg=="],
|
||||
|
||||
"loose-envify": ["loose-envify@1.4.0", "", { "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" }, "bin": { "loose-envify": "cli.js" } }, "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q=="],
|
||||
|
||||
"lucide-react": ["lucide-react@0.487.0", "", { "peerDependencies": { "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-aKqhOQ+YmFnwq8dWgGjOuLc8V1R9/c/yOd+zDY4+ohsR2Jo05lSGc3WsstYPIzcTpeosN7LoCkLReUUITvaIvw=="],
|
||||
@@ -622,6 +635,10 @@
|
||||
|
||||
"recharts-scale": ["recharts-scale@0.4.5", "", { "dependencies": { "decimal.js-light": "^2.4.1" } }, "sha512-kivNFO+0OcUNu7jQquLXAxz1FIwZj8nrj+YkOKc5694NbjCvcT6aSZiIzNzd2Kul4o4rTto8QVR9lMNtxD4G1w=="],
|
||||
|
||||
"redis-errors": ["redis-errors@1.2.0", "", {}, "sha512-1qny3OExCf0UvUV/5wpYKf2YwPcOqXzkwKKSmKHiE6ZMQs5heeE/c8eXK+PNllPvmjgAbfnsbpkGZWy8cBpn9w=="],
|
||||
|
||||
"redis-parser": ["redis-parser@3.0.0", "", { "dependencies": { "redis-errors": "^1.0.0" } }, "sha512-DJnGAeenTdpMEH6uAJRK/uiyEIH9WVsUmoLwzudwGJUwZPp80PDBWPHXSAGNPwNvIXAbe7MSUB1zQFugFml66A=="],
|
||||
|
||||
"regenerator-runtime": ["regenerator-runtime@0.14.1", "", {}, "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw=="],
|
||||
|
||||
"remeda": ["remeda@2.21.2", "", { "dependencies": { "type-fest": "^4.37.0" } }, "sha512-wdhkMDou8HRpD7RnxKJ/FHJWEGXRH7jV/pb0NsdLLSoBo+G9RjtxcY41hVhogLfEMkThk6aySKjs+Yd6PnpzBA=="],
|
||||
@@ -648,6 +665,8 @@
|
||||
|
||||
"source-map-support": ["source-map-support@0.5.21", "", { "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w=="],
|
||||
|
||||
"standard-as-callback": ["standard-as-callback@2.1.0", "", {}, "sha512-qoRRSyROncaz1z0mvYqIE4lCd9p2R90i6GxW3uZv5ucSu8tU7B5HXUP1gG8pVZsYNVaXjk8ClXHPttLyxAL48A=="],
|
||||
|
||||
"streamsearch": ["streamsearch@1.1.0", "", {}, "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg=="],
|
||||
|
||||
"styled-jsx": ["styled-jsx@5.1.6", "", { "dependencies": { "client-only": "0.0.1" }, "peerDependencies": { "react": ">= 16.8.0 || 17.x.x || ^18.0.0-0 || ^19.0.0-0" } }, "sha512-qSVyDTeMotdvQYoHWLNGwRFJHC+i+ZvdBRYosOFgC+Wg1vx4frN2/RG/NA7SYqqvKNLf39P2LSRA2pu6n0XYZA=="],
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
"drizzle-orm": "^0.41.0",
|
||||
"embla-carousel-react": "^8.5.2",
|
||||
"input-otp": "^1.4.2",
|
||||
"ioredis": "^5.6.0",
|
||||
"ky": "^1.8.0",
|
||||
"lucide-react": "^0.487.0",
|
||||
"next": "^15.2.3",
|
||||
|
||||
27
scripts/refresh-leaderboards.ts
Normal file
27
scripts/refresh-leaderboards.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { LeaderboardService } from '@/server/services/leaderboard'
|
||||
import { RANKED_CHANNEL, VANILLA_CHANNEL } from '@/shared/constants'
|
||||
|
||||
const CHANNEL_IDS = [RANKED_CHANNEL, VANILLA_CHANNEL]
|
||||
|
||||
async function refresh() {
|
||||
const service = new LeaderboardService()
|
||||
|
||||
for (const channelId of CHANNEL_IDS) {
|
||||
try {
|
||||
console.log(`refreshing leaderboard for ${channelId}...`)
|
||||
await service.refreshLeaderboard(channelId)
|
||||
} catch (err) {
|
||||
console.error(`failed to refresh ${channelId}:`, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run if called directly
|
||||
if (require.main === module) {
|
||||
refresh()
|
||||
.then(() => process.exit(0))
|
||||
.catch((err) => {
|
||||
console.error('refresh failed:', err)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { UserInfo } from '@/app/players/[id]/user'
|
||||
import { auth } from '@/server/auth'
|
||||
import { RANKED_CHANNEL, VANILLA_CHANNEL } from '@/shared/constants'
|
||||
import { HydrateClient, api } from '@/trpc/server'
|
||||
import { Suspense } from 'react'
|
||||
|
||||
@@ -11,12 +12,28 @@ export default async function PlayerPage({
|
||||
const session = await auth()
|
||||
const { id } = await params
|
||||
if (id) {
|
||||
await api.history.user_games.prefetch({
|
||||
await Promise.all([
|
||||
api.history.user_games.prefetch({
|
||||
user_id: id,
|
||||
})
|
||||
await api.discord.get_user_by_id.prefetch({
|
||||
}),
|
||||
api.discord.get_user_by_id.prefetch({
|
||||
user_id: id,
|
||||
})
|
||||
}),
|
||||
api.leaderboard.get_leaderboard.prefetch({
|
||||
channel_id: RANKED_CHANNEL,
|
||||
}),
|
||||
api.leaderboard.get_leaderboard.prefetch({
|
||||
channel_id: VANILLA_CHANNEL,
|
||||
}),
|
||||
api.leaderboard.get_user_rank.prefetch({
|
||||
channel_id: RANKED_CHANNEL,
|
||||
user_id: id,
|
||||
}),
|
||||
api.leaderboard.get_user_rank.prefetch({
|
||||
channel_id: VANILLA_CHANNEL,
|
||||
user_id: id,
|
||||
}),
|
||||
])
|
||||
}
|
||||
return (
|
||||
<Suspense>
|
||||
|
||||
@@ -23,7 +23,9 @@ import {
|
||||
} from '@/components/ui/table'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { RANKED_CHANNEL, VANILLA_CHANNEL } from '@/shared/constants'
|
||||
import { api } from '@/trpc/react'
|
||||
import { isNotNull } from 'drizzle-orm'
|
||||
import {
|
||||
ArrowDownCircle,
|
||||
ArrowUpCircle,
|
||||
@@ -33,12 +35,13 @@ import {
|
||||
ChevronUp,
|
||||
Clock,
|
||||
Filter,
|
||||
Medal,
|
||||
MinusCircle,
|
||||
Users,
|
||||
Star,
|
||||
Trophy,
|
||||
} from 'lucide-react'
|
||||
import { useFormatter } from 'next-intl'
|
||||
import { useParams } from 'next/navigation'
|
||||
import { isNonNullish } from 'remeda'
|
||||
|
||||
const numberFormatter = new Intl.NumberFormat('en-US', {
|
||||
signDisplay: 'exceptZero',
|
||||
@@ -46,17 +49,59 @@ const numberFormatter = new Intl.NumberFormat('en-US', {
|
||||
const dateFormatter = new Intl.DateTimeFormat('en-US', {
|
||||
dateStyle: 'long',
|
||||
})
|
||||
|
||||
export function UserInfo() {
|
||||
const format = useFormatter()
|
||||
|
||||
const [filter, setFilter] = useState('all')
|
||||
const [leaderboardFilter, setLeaderboardFilter] = useState('all')
|
||||
const { id } = useParams()
|
||||
if (!id || typeof id !== 'string') return null
|
||||
|
||||
const [games] = api.history.user_games.useSuspenseQuery({ user_id: id })
|
||||
// Fetch games data unconditionally
|
||||
const gamesQuery = api.history.user_games.useSuspenseQuery({ user_id: id })
|
||||
const games = gamesQuery[0] || [] // Ensure games is always an array
|
||||
|
||||
const [discord_user] = api.discord.get_user_by_id.useSuspenseQuery({
|
||||
user_id: id,
|
||||
})
|
||||
|
||||
// Mock data for the two leaderboards - replace with actual API calls
|
||||
const [rankedLeaderboard] = api.leaderboard.get_leaderboard.useSuspenseQuery({
|
||||
channel_id: RANKED_CHANNEL,
|
||||
})
|
||||
const [vanillaLeaderboard] = api.leaderboard.get_leaderboard.useSuspenseQuery(
|
||||
{
|
||||
channel_id: VANILLA_CHANNEL,
|
||||
}
|
||||
)
|
||||
const [vanillaUserRank] = api.leaderboard.get_user_rank.useSuspenseQuery({
|
||||
channel_id: VANILLA_CHANNEL,
|
||||
user_id: id,
|
||||
})
|
||||
const [rankedUserRank] = api.leaderboard.get_user_rank.useSuspenseQuery({
|
||||
channel_id: RANKED_CHANNEL,
|
||||
user_id: id,
|
||||
})
|
||||
|
||||
console.log(rankedLeaderboard, vanillaLeaderboard)
|
||||
|
||||
// Filter games by leaderboard if needed
|
||||
const filteredGamesByLeaderboard =
|
||||
leaderboardFilter === 'all'
|
||||
? games
|
||||
: games.filter((game) => game.gameType === leaderboardFilter)
|
||||
|
||||
// Filter by result
|
||||
const filteredGames =
|
||||
filter === 'all'
|
||||
? filteredGamesByLeaderboard
|
||||
: filter === 'wins'
|
||||
? filteredGamesByLeaderboard.filter((game) => game.result === 'win')
|
||||
: filter === 'losses'
|
||||
? filteredGamesByLeaderboard.filter((game) => game.result === 'loss')
|
||||
: filteredGamesByLeaderboard.filter((game) => game.result === 'tie')
|
||||
|
||||
const games_played = games.length
|
||||
let wins = 0
|
||||
let losses = 0
|
||||
@@ -70,6 +115,7 @@ export function UserInfo() {
|
||||
ties++
|
||||
}
|
||||
}
|
||||
|
||||
const profileData = {
|
||||
username: discord_user.username,
|
||||
avatar: discord_user.avatar_url,
|
||||
@@ -77,13 +123,20 @@ export function UserInfo() {
|
||||
wins,
|
||||
losses,
|
||||
ties,
|
||||
winRate: Math.round((wins / games_played) * 100),
|
||||
rank: 1,
|
||||
winRate: games_played > 0 ? Math.round((wins / games_played) * 100) : 0,
|
||||
}
|
||||
|
||||
const lastGame = games.at(0)
|
||||
const firstGame = games.at(-1)
|
||||
console.log(lastGame)
|
||||
|
||||
// Get last games for each leaderboard
|
||||
const lastGameLeaderboard1 = games
|
||||
.filter((game) => game.gameType === 'ranked')
|
||||
.at(0)
|
||||
const lastGameLeaderboard2 = games
|
||||
.filter((game) => game.gameType.toLowerCase() === 'vanilla')
|
||||
.at(0)
|
||||
|
||||
return (
|
||||
<div className='min-h-screen bg-gradient-to-b from-slate-50 to-slate-100 dark:from-slate-950 dark:to-slate-900'>
|
||||
<div className='container mx-auto px-4 py-8'>
|
||||
@@ -113,39 +166,53 @@ export function UserInfo() {
|
||||
<>No games played yet</>
|
||||
)}
|
||||
</p>
|
||||
<div className='mt-2 flex items-center justify-center gap-2 md:justify-start'>
|
||||
<div className='mt-2 flex flex-wrap items-center justify-center gap-2 md:justify-start'>
|
||||
{!!rankedLeaderboard && (
|
||||
<Badge
|
||||
variant='secondary'
|
||||
className='bg-white/20 text-white hover:bg-white/30'
|
||||
>
|
||||
<Users className='mr-1 h-3 w-3' />
|
||||
Rank #342
|
||||
<Trophy className='mr-1 h-3 w-3' />
|
||||
Ranked Queue:{' '}
|
||||
{isNonNullish(rankedUserRank?.rank)
|
||||
? `#${rankedUserRank.rank}`
|
||||
: 'N/A'}
|
||||
</Badge>
|
||||
)}
|
||||
{!!vanillaLeaderboard && (
|
||||
<Badge
|
||||
variant='secondary'
|
||||
className='bg-white/20 text-white hover:bg-white/30'
|
||||
>
|
||||
<Medal className='mr-1 h-3 w-3' />
|
||||
Gold
|
||||
<Star className='mr-1 h-3 w-3' />
|
||||
Vanilla Queue:{' '}
|
||||
{isNonNullish(vanillaLeaderboard?.rank)
|
||||
? `#${vanillaLeaderboard.rank}`
|
||||
: 'N/A'}
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex flex-1 justify-end'>
|
||||
<div className='flex gap-3'>
|
||||
{lastGameLeaderboard1 && (
|
||||
<div className='hidden rounded-lg bg-white/10 p-3 text-white backdrop-blur-sm md:block'>
|
||||
<div className='font-medium text-sm'>Current MMR</div>
|
||||
<div className='font-medium text-sm'>
|
||||
Ranked Queue MMR
|
||||
</div>
|
||||
<div className='font-bold text-2xl'>
|
||||
{Math.trunc(
|
||||
lastGame ? lastGame.playerMmr + lastGame.mmrChange : 200
|
||||
lastGameLeaderboard1.playerMmr +
|
||||
lastGameLeaderboard1.mmrChange
|
||||
)}
|
||||
</div>
|
||||
<div className='text-violet-200 text-xs'>
|
||||
{!!lastGame &&
|
||||
(lastGame.mmrChange > 0 ? (
|
||||
{lastGameLeaderboard1.mmrChange > 0 ? (
|
||||
<span className='flex items-center text-green-300'>
|
||||
<ChevronUp className='h-3 w-3' />
|
||||
{numberFormatter.format(
|
||||
Math.trunc(lastGame.mmrChange)
|
||||
Math.trunc(lastGameLeaderboard1.mmrChange)
|
||||
)}{' '}
|
||||
last match
|
||||
</span>
|
||||
@@ -153,13 +220,48 @@ export function UserInfo() {
|
||||
<span className='flex items-center text-red-300'>
|
||||
<ChevronDown className='h-3 w-3' />
|
||||
{numberFormatter.format(
|
||||
Math.trunc(lastGame.mmrChange)
|
||||
Math.trunc(lastGameLeaderboard1.mmrChange)
|
||||
)}{' '}
|
||||
last match
|
||||
</span>
|
||||
))}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{lastGameLeaderboard2 && (
|
||||
<div className='hidden rounded-lg bg-white/10 p-3 text-white backdrop-blur-sm md:block'>
|
||||
<div className='font-medium text-sm'>
|
||||
Leaderboard 2 MMR
|
||||
</div>
|
||||
<div className='font-bold text-2xl'>
|
||||
{Math.trunc(
|
||||
lastGameLeaderboard2.playerMmr +
|
||||
lastGameLeaderboard2.mmrChange
|
||||
)}
|
||||
</div>
|
||||
<div className='text-violet-200 text-xs'>
|
||||
{lastGameLeaderboard2.mmrChange > 0 ? (
|
||||
<span className='flex items-center text-green-300'>
|
||||
<ChevronUp className='h-3 w-3' />
|
||||
{numberFormatter.format(
|
||||
Math.trunc(lastGameLeaderboard2.mmrChange)
|
||||
)}{' '}
|
||||
last match
|
||||
</span>
|
||||
) : (
|
||||
<span className='flex items-center text-red-300'>
|
||||
<ChevronDown className='h-3 w-3' />
|
||||
{numberFormatter.format(
|
||||
Math.trunc(lastGameLeaderboard2.mmrChange)
|
||||
)}{' '}
|
||||
last match
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
@@ -183,14 +285,14 @@ export function UserInfo() {
|
||||
title='Losses'
|
||||
value={profileData.losses}
|
||||
icon={<ArrowDownCircle className='h-5 w-5 text-rose-500' />}
|
||||
description={`${Math.round((profileData.losses / profileData.games) * 100)}% loss rate`}
|
||||
description={`${profileData.games > 0 ? Math.round((profileData.losses / profileData.games) * 100) : 0}% loss rate`}
|
||||
accentColor='text-rose-500'
|
||||
/>
|
||||
<StatsCard
|
||||
title='Ties'
|
||||
value={profileData.ties}
|
||||
icon={<MinusCircle className='h-5 w-5 text-amber-500' />}
|
||||
description={`${Math.round((profileData.ties / profileData.games) * 100)}% tie rate`}
|
||||
description={`${profileData.games > 0 ? Math.round((profileData.ties / profileData.games) * 100) : 0}% tie rate`}
|
||||
accentColor='text-amber-500'
|
||||
/>
|
||||
</div>
|
||||
@@ -204,6 +306,23 @@ export function UserInfo() {
|
||||
</TabsList>
|
||||
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='mr-2 flex items-center gap-2'>
|
||||
<Trophy className='h-4 w-4 text-slate-400' />
|
||||
<Select
|
||||
value={leaderboardFilter}
|
||||
onValueChange={setLeaderboardFilter}
|
||||
>
|
||||
<SelectTrigger className='h-9 w-[150px]'>
|
||||
<SelectValue placeholder='Leaderboard' />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value='all'>All Leaderboards</SelectItem>
|
||||
<SelectItem value='ranked'>Ranked</SelectItem>
|
||||
<SelectItem value='vanilla'>Vanilla</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<Filter className='h-4 w-4 text-slate-400' />
|
||||
<Select value={filter} onValueChange={setFilter}>
|
||||
<SelectTrigger className='h-9 w-[120px]'>
|
||||
@@ -230,8 +349,11 @@ export function UserInfo() {
|
||||
<TableHead className='text-right'>
|
||||
Opponent MMR
|
||||
</TableHead>
|
||||
<TableHead className='text-right'>Your MMR</TableHead>
|
||||
<TableHead className='text-right'>MMR</TableHead>
|
||||
<TableHead className='text-right'>Result</TableHead>
|
||||
<TableHead className='text-center'>
|
||||
Leaderboard
|
||||
</TableHead>
|
||||
<TableHead className='text-right'>
|
||||
<span className='flex items-center justify-end gap-1'>
|
||||
<Calendar className='h-4 w-4' /> Date
|
||||
@@ -245,7 +367,7 @@ export function UserInfo() {
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{games.map((game) => (
|
||||
{filteredGames.map((game) => (
|
||||
<TableRow
|
||||
key={game.gameId}
|
||||
className='transition-colors hover:bg-slate-50 dark:hover:bg-slate-800/70'
|
||||
@@ -261,13 +383,13 @@ export function UserInfo() {
|
||||
<TableCell className='font-medium'>
|
||||
{game.opponentName}
|
||||
</TableCell>
|
||||
<TableCell className='text-right'>
|
||||
<TableCell className='text-right font-mono'>
|
||||
{Math.trunc(game.opponentMmr)}
|
||||
</TableCell>
|
||||
<TableCell className='text-right'>
|
||||
<TableCell className='text-right font-mono'>
|
||||
{Math.trunc(game.playerMmr)}
|
||||
</TableCell>
|
||||
<TableCell className='text-right'>
|
||||
<TableCell className='text-right font-mono'>
|
||||
{game.mmrChange > 0 ? (
|
||||
<span className='flex items-center justify-end font-medium text-emerald-500'>
|
||||
<ArrowUpCircle className='mr-1 inline h-4 w-4' />
|
||||
@@ -284,14 +406,33 @@ export function UserInfo() {
|
||||
</span>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell className='text-right text-slate-500 dark:text-slate-400'>
|
||||
<TableCell className='text-center'>
|
||||
<Badge
|
||||
variant='outline'
|
||||
className={cn(
|
||||
'w-full font-normal',
|
||||
game.gameType === 'ranked'
|
||||
? 'border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-800 dark:bg-violet-950 dark:text-violet-300'
|
||||
: game.gameType.toLowerCase() === 'vanilla'
|
||||
? 'border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-800 dark:bg-amber-950 dark:text-amber-300'
|
||||
: 'border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-300'
|
||||
)}
|
||||
>
|
||||
{game.gameType === 'ranked'
|
||||
? 'Ranked Queue'
|
||||
: game.gameType.toLowerCase() === 'vanilla'
|
||||
? 'Vanilla Queue'
|
||||
: 'N/A'}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell className='text-right font-mono text-slate-500 dark:text-slate-400'>
|
||||
{format.dateTime(game.gameTime, {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
})}
|
||||
</TableCell>
|
||||
<TableCell className='text-right text-slate-500 dark:text-slate-400'>
|
||||
<TableCell className='text-right font-mono text-slate-500 dark:text-slate-400'>
|
||||
{format.dateTime(game.gameTime, {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
@@ -306,11 +447,52 @@ export function UserInfo() {
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='stats' className='m-0'>
|
||||
<div className='flex h-40 items-center justify-center rounded-lg border bg-slate-50 dark:bg-slate-800/50'>
|
||||
<div className='grid grid-cols-1 gap-6 md:grid-cols-2'>
|
||||
{(rankedLeaderboard || lastGameLeaderboard1) && (
|
||||
<LeaderboardStatsCard
|
||||
title='Leaderboard 1 Stats'
|
||||
rank={rankedLeaderboard?.rank}
|
||||
mmr={
|
||||
lastGameLeaderboard1
|
||||
? Math.trunc(
|
||||
lastGameLeaderboard1.playerMmr +
|
||||
lastGameLeaderboard1.mmrChange
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
icon={<Trophy className='h-5 w-5 text-violet-500' />}
|
||||
accentColor='text-violet-500'
|
||||
/>
|
||||
)}
|
||||
|
||||
{(vanillaLeaderboard || lastGameLeaderboard2) && (
|
||||
<LeaderboardStatsCard
|
||||
title='Leaderboard 2 Stats'
|
||||
rank={vanillaLeaderboard?.rank}
|
||||
mmr={
|
||||
lastGameLeaderboard2
|
||||
? Math.trunc(
|
||||
lastGameLeaderboard2.playerMmr +
|
||||
lastGameLeaderboard2.mmrChange
|
||||
)
|
||||
: undefined
|
||||
}
|
||||
icon={<Star className='h-5 w-5 text-amber-500' />}
|
||||
accentColor='text-amber-500'
|
||||
/>
|
||||
)}
|
||||
|
||||
{!rankedLeaderboard &&
|
||||
!vanillaLeaderboard &&
|
||||
!lastGameLeaderboard1 &&
|
||||
!lastGameLeaderboard2 && (
|
||||
<div className='col-span-2 flex h-40 items-center justify-center rounded-lg border bg-slate-50 dark:bg-slate-800/50'>
|
||||
<p className='text-slate-500 dark:text-slate-400'>
|
||||
Statistics coming soon
|
||||
No leaderboard data available
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value='achievements' className='m-0'>
|
||||
@@ -356,3 +538,61 @@ function StatsCard({
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface LeaderboardStatsCardProps {
|
||||
title: string
|
||||
rank?: number
|
||||
mmr?: number
|
||||
icon: React.ReactNode
|
||||
accentColor?: string
|
||||
}
|
||||
|
||||
function LeaderboardStatsCard({
|
||||
title,
|
||||
rank,
|
||||
mmr,
|
||||
icon,
|
||||
accentColor = 'text-violet-500',
|
||||
}: LeaderboardStatsCardProps) {
|
||||
return (
|
||||
<div className='rounded-lg border bg-white p-6 dark:bg-slate-800/20'>
|
||||
<div className='mb-4 flex items-center gap-3'>
|
||||
<div
|
||||
className={cn(
|
||||
'rounded-full bg-slate-100 p-2 dark:bg-slate-800',
|
||||
accentColor
|
||||
)}
|
||||
>
|
||||
{icon}
|
||||
</div>
|
||||
<h3 className='font-semibold text-lg'>{title}</h3>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
{rank !== undefined && (
|
||||
<div className='rounded-lg bg-slate-50 p-4 dark:bg-slate-800/40'>
|
||||
<p className='text-slate-500 text-sm dark:text-slate-400'>Rank</p>
|
||||
<p className={cn('mt-1 font-bold text-2xl', accentColor)}>
|
||||
#{rank}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{mmr !== undefined && (
|
||||
<div className='rounded-lg bg-slate-50 p-4 dark:bg-slate-800/40'>
|
||||
<p className='text-slate-500 text-sm dark:text-slate-400'>MMR</p>
|
||||
<p className={cn('mt-1 font-bold text-2xl', accentColor)}>{mmr}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{rank === undefined && mmr === undefined && (
|
||||
<div className='col-span-2 flex h-20 items-center justify-center rounded-lg bg-slate-50 p-4 dark:bg-slate-800/40'>
|
||||
<p className='text-slate-500 dark:text-slate-400'>
|
||||
No data available
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
"use client"
|
||||
'use client'
|
||||
|
||||
import * as React from "react"
|
||||
import { Slot } from "@radix-ui/react-slot"
|
||||
import { VariantProps, cva } from "class-variance-authority"
|
||||
import { PanelLeftIcon } from "lucide-react"
|
||||
import { Slot } from '@radix-ui/react-slot'
|
||||
import { type VariantProps, cva } from 'class-variance-authority'
|
||||
import { PanelLeftIcon } from 'lucide-react'
|
||||
import * as React from 'react'
|
||||
|
||||
import { useIsMobile } from "@/hooks/use-mobile"
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Separator } from '@/components/ui/separator'
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
} from '@/components/ui/sheet'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip"
|
||||
} from '@/components/ui/tooltip'
|
||||
import { useIsMobile } from '@/hooks/use-mobile'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
||||
const SIDEBAR_COOKIE_NAME = 'sidebar_state'
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
||||
const SIDEBAR_WIDTH = "16rem"
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem"
|
||||
const SIDEBAR_WIDTH_ICON = "3rem"
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
||||
const SIDEBAR_WIDTH = '16rem'
|
||||
const SIDEBAR_WIDTH_MOBILE = '18rem'
|
||||
const SIDEBAR_WIDTH_ICON = '3rem'
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed"
|
||||
state: 'expanded' | 'collapsed'
|
||||
open: boolean
|
||||
setOpen: (open: boolean) => void
|
||||
openMobile: boolean
|
||||
@@ -47,7 +47,7 @@ const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext)
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.")
|
||||
throw new Error('useSidebar must be used within a SidebarProvider.')
|
||||
}
|
||||
|
||||
return context
|
||||
@@ -61,7 +61,7 @@ function SidebarProvider({
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
}: React.ComponentProps<'div'> & {
|
||||
defaultOpen?: boolean
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
@@ -75,7 +75,7 @@ function SidebarProvider({
|
||||
const open = openProp ?? _open
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value
|
||||
const openState = typeof value === 'function' ? value(open) : value
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState)
|
||||
} else {
|
||||
@@ -105,13 +105,13 @@ function SidebarProvider({
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown)
|
||||
return () => window.removeEventListener("keydown", handleKeyDown)
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [toggleSidebar])
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed"
|
||||
const state = open ? 'expanded' : 'collapsed'
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
@@ -130,16 +130,16 @@ function SidebarProvider({
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<TooltipProvider delayDuration={0}>
|
||||
<div
|
||||
data-slot="sidebar-wrapper"
|
||||
data-slot='sidebar-wrapper'
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
'--sidebar-width': SIDEBAR_WIDTH,
|
||||
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-svh w-full",
|
||||
'group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -152,25 +152,25 @@ function SidebarProvider({
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
side = "left",
|
||||
variant = "sidebar",
|
||||
collapsible = "offcanvas",
|
||||
side = 'left',
|
||||
variant = 'sidebar',
|
||||
collapsible = 'offcanvas',
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right"
|
||||
variant?: "sidebar" | "floating" | "inset"
|
||||
collapsible?: "offcanvas" | "icon" | "none"
|
||||
}: React.ComponentProps<'div'> & {
|
||||
side?: 'left' | 'right'
|
||||
variant?: 'sidebar' | 'floating' | 'inset'
|
||||
collapsible?: 'offcanvas' | 'icon' | 'none'
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
||||
|
||||
if (collapsible === "none") {
|
||||
if (collapsible === 'none') {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar"
|
||||
data-slot='sidebar'
|
||||
className={cn(
|
||||
"bg-sidebar text-sidebar-foreground flex h-full w-(--sidebar-width) flex-col",
|
||||
'flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -184,22 +184,22 @@ function Sidebar({
|
||||
return (
|
||||
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||
<SheetContent
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar"
|
||||
data-mobile="true"
|
||||
className="bg-sidebar text-sidebar-foreground w-(--sidebar-width) p-0 [&>button]:hidden"
|
||||
data-sidebar='sidebar'
|
||||
data-slot='sidebar'
|
||||
data-mobile='true'
|
||||
className='w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden'
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
'--sidebar-width': SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
side={side}
|
||||
>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetHeader className='sr-only'>
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
<div className='flex h-full w-full flex-col'>{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
@@ -207,44 +207,44 @@ function Sidebar({
|
||||
|
||||
return (
|
||||
<div
|
||||
className="group peer text-sidebar-foreground hidden md:block"
|
||||
className='group peer hidden text-sidebar-foreground md:block'
|
||||
data-state={state}
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-collapsible={state === 'collapsed' ? collapsible : ''}
|
||||
data-variant={variant}
|
||||
data-side={side}
|
||||
data-slot="sidebar"
|
||||
data-slot='sidebar'
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
data-slot="sidebar-gap"
|
||||
data-slot='sidebar-gap'
|
||||
className={cn(
|
||||
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
||||
'relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear',
|
||||
'group-data-[collapsible=offcanvas]:w-0',
|
||||
'group-data-[side=right]:rotate-180',
|
||||
variant === 'floating' || variant === 'inset'
|
||||
? 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]'
|
||||
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon)'
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
data-slot="sidebar-container"
|
||||
data-slot='sidebar-container'
|
||||
className={cn(
|
||||
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex",
|
||||
side === "left"
|
||||
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
||||
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
||||
'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex',
|
||||
side === 'left'
|
||||
? 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]'
|
||||
: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]',
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
variant === 'floating' || variant === 'inset'
|
||||
? 'p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]'
|
||||
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
className="bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow-sm"
|
||||
data-sidebar='sidebar'
|
||||
data-slot='sidebar-inner'
|
||||
className='flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm'
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
@@ -262,11 +262,11 @@ function SidebarTrigger({
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-sidebar="trigger"
|
||||
data-slot="sidebar-trigger"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className={cn("size-7", className)}
|
||||
data-sidebar='trigger'
|
||||
data-slot='sidebar-trigger'
|
||||
variant='ghost'
|
||||
size='icon'
|
||||
className={cn('size-7', className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event)
|
||||
toggleSidebar()
|
||||
@@ -274,29 +274,29 @@ function SidebarTrigger({
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
<span className='sr-only'>Toggle Sidebar</span>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
|
||||
const { toggleSidebar } = useSidebar()
|
||||
|
||||
return (
|
||||
<button
|
||||
data-sidebar="rail"
|
||||
data-slot="sidebar-rail"
|
||||
aria-label="Toggle Sidebar"
|
||||
data-sidebar='rail'
|
||||
data-slot='sidebar-rail'
|
||||
aria-label='Toggle Sidebar'
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title="Toggle Sidebar"
|
||||
title='Toggle Sidebar'
|
||||
className={cn(
|
||||
"hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex",
|
||||
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
'-translate-x-1/2 group-data-[side=left]:-right-4 absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=right]:left-0 sm:flex',
|
||||
'in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',
|
||||
'[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
|
||||
'group-data-[collapsible=offcanvas]:translate-x-0 hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:after:left-full',
|
||||
'[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
|
||||
'[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -304,13 +304,13 @@ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<'main'>) {
|
||||
return (
|
||||
<main
|
||||
data-slot="sidebar-inset"
|
||||
data-slot='sidebar-inset'
|
||||
className={cn(
|
||||
"bg-background relative flex w-full flex-1 flex-col",
|
||||
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||
'relative flex w-full flex-1 flex-col bg-background',
|
||||
'md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2 md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -324,31 +324,31 @@ function SidebarInput({
|
||||
}: React.ComponentProps<typeof Input>) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="sidebar-input"
|
||||
data-sidebar="input"
|
||||
className={cn("bg-background h-8 w-full shadow-none", className)}
|
||||
data-slot='sidebar-input'
|
||||
data-sidebar='input'
|
||||
className={cn('h-8 w-full bg-background shadow-none', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-header"
|
||||
data-sidebar="header"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
data-slot='sidebar-header'
|
||||
data-sidebar='header'
|
||||
className={cn('flex flex-col gap-2 p-2', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-footer"
|
||||
data-sidebar="footer"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
data-slot='sidebar-footer'
|
||||
data-sidebar='footer'
|
||||
className={cn('flex flex-col gap-2 p-2', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
@@ -360,21 +360,21 @@ function SidebarSeparator({
|
||||
}: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="sidebar-separator"
|
||||
data-sidebar="separator"
|
||||
className={cn("bg-sidebar-border mx-2 w-auto", className)}
|
||||
data-slot='sidebar-separator'
|
||||
data-sidebar='separator'
|
||||
className={cn('mx-2 w-auto bg-sidebar-border', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-content"
|
||||
data-sidebar="content"
|
||||
data-slot='sidebar-content'
|
||||
data-sidebar='content'
|
||||
className={cn(
|
||||
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
'flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -382,12 +382,12 @@ function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group"
|
||||
data-sidebar="group"
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
data-slot='sidebar-group'
|
||||
data-sidebar='group'
|
||||
className={cn('relative flex w-full min-w-0 flex-col p-2', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
@@ -397,16 +397,16 @@ function SidebarGroupLabel({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "div"
|
||||
}: React.ComponentProps<'div'> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : 'div'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-label"
|
||||
data-sidebar="group-label"
|
||||
data-slot='sidebar-group-label'
|
||||
data-sidebar='group-label'
|
||||
className={cn(
|
||||
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
||||
'flex h-8 shrink-0 items-center rounded-md px-2 font-medium text-sidebar-foreground/70 text-xs outline-hidden ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
||||
'group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -418,18 +418,18 @@ function SidebarGroupAction({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
}: React.ComponentProps<'button'> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot : 'button'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-action"
|
||||
data-sidebar="group-action"
|
||||
data-slot='sidebar-group-action'
|
||||
data-sidebar='group-action'
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
'absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
'after:-inset-2 after:absolute md:after:hidden',
|
||||
'group-data-[collapsible=icon]:hidden',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -440,57 +440,57 @@ function SidebarGroupAction({
|
||||
function SidebarGroupContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
}: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group-content"
|
||||
data-sidebar="group-content"
|
||||
className={cn("w-full text-sm", className)}
|
||||
data-slot='sidebar-group-content'
|
||||
data-sidebar='group-content'
|
||||
className={cn('w-full text-sm', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<'ul'>) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu"
|
||||
data-sidebar="menu"
|
||||
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
||||
data-slot='sidebar-menu'
|
||||
data-sidebar='menu'
|
||||
className={cn('flex w-full min-w-0 flex-col gap-1', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<'li'>) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-item"
|
||||
data-sidebar="menu-item"
|
||||
className={cn("group/menu-item relative", className)}
|
||||
data-slot='sidebar-menu-item'
|
||||
data-sidebar='menu-item'
|
||||
className={cn('group/menu-item relative', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-data-[sidebar=menu-action]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
default: 'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
||||
outline:
|
||||
"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]",
|
||||
'bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]',
|
||||
},
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
sm: "h-7 text-xs",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||
default: 'h-8 text-sm',
|
||||
sm: 'h-7 text-xs',
|
||||
lg: 'h-12 text-sm group-data-[collapsible=icon]:p-0!',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -498,23 +498,23 @@ const sidebarMenuButtonVariants = cva(
|
||||
function SidebarMenuButton({
|
||||
asChild = false,
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
variant = 'default',
|
||||
size = 'default',
|
||||
tooltip,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
}: React.ComponentProps<'button'> & {
|
||||
asChild?: boolean
|
||||
isActive?: boolean
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const Comp = asChild ? Slot : 'button'
|
||||
const { isMobile, state } = useSidebar()
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-button"
|
||||
data-sidebar="menu-button"
|
||||
data-slot='sidebar-menu-button'
|
||||
data-sidebar='menu-button'
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
@@ -526,7 +526,7 @@ function SidebarMenuButton({
|
||||
return button
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
if (typeof tooltip === 'string') {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
}
|
||||
@@ -536,9 +536,9 @@ function SidebarMenuButton({
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
side='right'
|
||||
align='center'
|
||||
hidden={state !== 'collapsed' || isMobile}
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
@@ -550,26 +550,26 @@ function SidebarMenuAction({
|
||||
asChild = false,
|
||||
showOnHover = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
}: React.ComponentProps<'button'> & {
|
||||
asChild?: boolean
|
||||
showOnHover?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "button"
|
||||
const Comp = asChild ? Slot : 'button'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-action"
|
||||
data-sidebar="menu-action"
|
||||
data-slot='sidebar-menu-action'
|
||||
data-sidebar='menu-action'
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 outline-hidden transition-transform focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
'absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0',
|
||||
// Increases the hit area of the button on mobile.
|
||||
"after:absolute after:-inset-2 md:after:hidden",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
'after:-inset-2 after:absolute md:after:hidden',
|
||||
'peer-data-[size=sm]/menu-button:top-1',
|
||||
'peer-data-[size=default]/menu-button:top-1.5',
|
||||
'peer-data-[size=lg]/menu-button:top-2.5',
|
||||
'group-data-[collapsible=icon]:hidden',
|
||||
showOnHover &&
|
||||
"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",
|
||||
'group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -580,18 +580,18 @@ function SidebarMenuAction({
|
||||
function SidebarMenuBadge({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div">) {
|
||||
}: React.ComponentProps<'div'>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-badge"
|
||||
data-sidebar="menu-badge"
|
||||
data-slot='sidebar-menu-badge'
|
||||
data-sidebar='menu-badge'
|
||||
className={cn(
|
||||
"text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none",
|
||||
"peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground",
|
||||
"peer-data-[size=sm]/menu-button:top-1",
|
||||
"peer-data-[size=default]/menu-button:top-1.5",
|
||||
"peer-data-[size=lg]/menu-button:top-2.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
'pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 font-medium text-sidebar-foreground text-xs tabular-nums',
|
||||
'peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground',
|
||||
'peer-data-[size=sm]/menu-button:top-1',
|
||||
'peer-data-[size=default]/menu-button:top-1.5',
|
||||
'peer-data-[size=lg]/menu-button:top-2.5',
|
||||
'group-data-[collapsible=icon]:hidden',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -603,7 +603,7 @@ function SidebarMenuSkeleton({
|
||||
className,
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
}: React.ComponentProps<'div'> & {
|
||||
showIcon?: boolean
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
@@ -613,23 +613,23 @@ function SidebarMenuSkeleton({
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-skeleton"
|
||||
data-sidebar="menu-skeleton"
|
||||
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||
data-slot='sidebar-menu-skeleton'
|
||||
data-sidebar='menu-skeleton'
|
||||
className={cn('flex h-8 items-center gap-2 rounded-md px-2', className)}
|
||||
{...props}
|
||||
>
|
||||
{showIcon && (
|
||||
<Skeleton
|
||||
className="size-4 rounded-md"
|
||||
data-sidebar="menu-skeleton-icon"
|
||||
className='size-4 rounded-md'
|
||||
data-sidebar='menu-skeleton-icon'
|
||||
/>
|
||||
)}
|
||||
<Skeleton
|
||||
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
className='h-4 max-w-(--skeleton-width) flex-1'
|
||||
data-sidebar='menu-skeleton-text'
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
'--skeleton-width': width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
@@ -637,14 +637,14 @@ function SidebarMenuSkeleton({
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<'ul'>) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu-sub"
|
||||
data-sidebar="menu-sub"
|
||||
data-slot='sidebar-menu-sub'
|
||||
data-sidebar='menu-sub'
|
||||
className={cn(
|
||||
"border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
'mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-sidebar-border border-l px-2.5 py-0.5',
|
||||
'group-data-[collapsible=icon]:hidden',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -655,12 +655,12 @@ function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
function SidebarMenuSubItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"li">) {
|
||||
}: React.ComponentProps<'li'>) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-sub-item"
|
||||
data-sidebar="menu-sub-item"
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
data-slot='sidebar-menu-sub-item'
|
||||
data-sidebar='menu-sub-item'
|
||||
className={cn('group/menu-sub-item relative', className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
@@ -668,29 +668,29 @@ function SidebarMenuSubItem({
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
asChild = false,
|
||||
size = "md",
|
||||
size = 'md',
|
||||
isActive = false,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
}: React.ComponentProps<'a'> & {
|
||||
asChild?: boolean
|
||||
size?: "sm" | "md"
|
||||
size?: 'sm' | 'md'
|
||||
isActive?: boolean
|
||||
}) {
|
||||
const Comp = asChild ? Slot : "a"
|
||||
const Comp = asChild ? Slot : 'a'
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-sub-button"
|
||||
data-sidebar="menu-sub-button"
|
||||
data-slot='sidebar-menu-sub-button'
|
||||
data-sidebar='menu-sub-button'
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-hidden focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",
|
||||
size === "sm" && "text-xs",
|
||||
size === "md" && "text-sm",
|
||||
"group-data-[collapsible=icon]:hidden",
|
||||
'-translate-x-px flex h-7 min-w-0 items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-hidden ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground',
|
||||
'data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground',
|
||||
size === 'sm' && 'text-xs',
|
||||
size === 'md' && 'text-sm',
|
||||
'group-data-[collapsible=icon]:hidden',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
"use client"
|
||||
'use client'
|
||||
|
||||
import { useTheme } from "next-themes"
|
||||
import { Toaster as Sonner, ToasterProps } from "sonner"
|
||||
import { useTheme } from 'next-themes'
|
||||
import { Toaster as Sonner, type ToasterProps } from 'sonner'
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = "system" } = useTheme()
|
||||
const { theme = 'system' } = useTheme()
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
theme={theme as ToasterProps['theme']}
|
||||
className='toaster group'
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
'--normal-bg': 'var(--popover)',
|
||||
'--normal-text': 'var(--popover-foreground)',
|
||||
'--normal-border': 'var(--border)',
|
||||
} as React.CSSProperties
|
||||
}
|
||||
{...props}
|
||||
|
||||
@@ -15,6 +15,7 @@ export const env = createEnv({
|
||||
AUTH_DISCORD_SECRET: z.string(),
|
||||
DISCORD_BOT_TOKEN: z.string(),
|
||||
DATABASE_URL: z.string().url(),
|
||||
REDIS_URL: z.string().url(),
|
||||
NODE_ENV: z
|
||||
.enum(['development', 'test', 'production'])
|
||||
.default('development'),
|
||||
@@ -39,6 +40,7 @@ export const env = createEnv({
|
||||
AUTH_DISCORD_SECRET: process.env.AUTH_DISCORD_SECRET,
|
||||
DATABASE_URL: process.env.DATABASE_URL,
|
||||
DISCORD_BOT_TOKEN: process.env.DISCORD_BOT_TOKEN,
|
||||
REDIS_URL: process.env.REDIS_URL,
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { createTRPCRouter, publicProcedure } from '@/server/api/trpc'
|
||||
import { LeaderboardService } from '@/server/services/leaderboard'
|
||||
import { neatqueue_service } from '@/server/services/neatqueue.service'
|
||||
import { z } from 'zod'
|
||||
const service = new LeaderboardService()
|
||||
|
||||
export const leaderboard_router = createTRPCRouter({
|
||||
get_leaderboard: publicProcedure
|
||||
@@ -10,6 +12,16 @@ export const leaderboard_router = createTRPCRouter({
|
||||
})
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
return await neatqueue_service.get_leaderboard(input.channel_id)
|
||||
return await service.getLeaderboard(input.channel_id)
|
||||
}),
|
||||
get_user_rank: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
channel_id: z.string(),
|
||||
user_id: z.string(),
|
||||
})
|
||||
)
|
||||
.query(async ({ input }) => {
|
||||
return await service.getUserRank(input.channel_id, input.user_id)
|
||||
}),
|
||||
})
|
||||
|
||||
4
src/server/redis.ts
Normal file
4
src/server/redis.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { env } from '@/env'
|
||||
import { Redis } from 'ioredis'
|
||||
|
||||
export const redis = new Redis(env.REDIS_URL)
|
||||
93
src/server/services/leaderboard.ts
Normal file
93
src/server/services/leaderboard.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { redis } from '../redis'
|
||||
import { neatqueue_service } from './neatqueue.service'
|
||||
export class LeaderboardService {
|
||||
private getZSetKey(channel_id: string) {
|
||||
return `zset:leaderboard:${channel_id}`
|
||||
}
|
||||
|
||||
private getRawKey(channel_id: string) {
|
||||
return `raw:leaderboard:${channel_id}`
|
||||
}
|
||||
|
||||
async refreshLeaderboard(channel_id: string) {
|
||||
const fresh = await neatqueue_service.get_leaderboard(channel_id)
|
||||
const zsetKey = this.getZSetKey(channel_id)
|
||||
const rawKey = this.getRawKey(channel_id)
|
||||
|
||||
// store raw data for full queries
|
||||
await redis.setex(rawKey, 180, JSON.stringify(fresh))
|
||||
|
||||
// store sorted set for rank queries
|
||||
const pipeline = redis.pipeline()
|
||||
pipeline.del(zsetKey) // clear existing
|
||||
|
||||
for (const entry of fresh.alltime) {
|
||||
// store by mmr for ranking
|
||||
pipeline.zadd(zsetKey, entry.data.mmr, entry.id)
|
||||
|
||||
// store user data separately for quick lookups
|
||||
pipeline.hset(`user:${entry.id}`, {
|
||||
name: entry.name,
|
||||
mmr: entry.data.mmr,
|
||||
wins: entry.data.wins,
|
||||
losses: entry.data.losses,
|
||||
// add other fields you need for quick lookup
|
||||
})
|
||||
}
|
||||
|
||||
pipeline.expire(zsetKey, 180)
|
||||
await pipeline.exec()
|
||||
}
|
||||
|
||||
async getLeaderboard(channel_id: string) {
|
||||
const cached = await redis.get(this.getRawKey(channel_id))
|
||||
if (cached) return JSON.parse(cached)
|
||||
|
||||
// if not cached, refresh and return
|
||||
await this.refreshLeaderboard(channel_id)
|
||||
// @ts-ignore
|
||||
return redis.get(this.getRawKey(channel_id)).then(JSON.parse)
|
||||
}
|
||||
|
||||
async getUserRank(channel_id: string, user_id: string) {
|
||||
const zsetKey = this.getZSetKey(channel_id)
|
||||
|
||||
// zrevrank because higher mmr = better rank
|
||||
const rank = await redis.zrevrank(zsetKey, user_id)
|
||||
if (rank === null) return null
|
||||
|
||||
// get user data
|
||||
const userData = await redis.hgetall(`user:${user_id}`)
|
||||
if (!userData) return null
|
||||
|
||||
return {
|
||||
rank: rank + 1, // zero-based -> one-based
|
||||
...userData,
|
||||
}
|
||||
}
|
||||
|
||||
// get users around a specific rank
|
||||
async getRankRange(channel_id: string, rank: number, range = 5) {
|
||||
const zsetKey = this.getZSetKey(channel_id)
|
||||
|
||||
// get ids
|
||||
const ids = await redis.zrevrange(
|
||||
zsetKey,
|
||||
Math.max(0, rank - range),
|
||||
rank + range
|
||||
)
|
||||
|
||||
// get data for each id
|
||||
const pipeline = redis.pipeline()
|
||||
// biome-ignore lint/complexity/noForEach: <explanation>
|
||||
ids.forEach((id) => pipeline.hgetall(`user:${id}`))
|
||||
|
||||
const results = await pipeline.exec()
|
||||
return ids.map((id, i) => ({
|
||||
id,
|
||||
rank: rank - range + i + 1,
|
||||
// @ts-ignore
|
||||
...results[i][1],
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ const NEATQUEUE_URL = 'https://api.neatqueue.com/api'
|
||||
|
||||
const instance = ky.create({
|
||||
prefixUrl: NEATQUEUE_URL,
|
||||
timeout: 10000,
|
||||
timeout: 60000,
|
||||
})
|
||||
|
||||
const BMM_SERVER_ID = '1352157545547960350'
|
||||
const BMM_SERVER_ID = '1226193436521267223'
|
||||
|
||||
export const neatqueue_service = {
|
||||
get_leaderboard: async (channel_id: string) => {
|
||||
@@ -15,7 +15,7 @@ export const neatqueue_service = {
|
||||
`leaderboard/${BMM_SERVER_ID}/${channel_id}`
|
||||
)
|
||||
|
||||
return response.json()
|
||||
return response.json<LeaderboardResponse>()
|
||||
},
|
||||
get_history: async (
|
||||
player_ids: string[],
|
||||
@@ -31,3 +31,25 @@ export const neatqueue_service = {
|
||||
return response
|
||||
},
|
||||
}
|
||||
export type Data = {
|
||||
mmr: number
|
||||
wins: number
|
||||
losses: number
|
||||
streak: number
|
||||
totalgames: number
|
||||
decay: number
|
||||
ign?: any
|
||||
peak_mmr: number
|
||||
peak_streak: number
|
||||
rank: number
|
||||
winrate: number
|
||||
}
|
||||
|
||||
export type LeaderboardEntry = {
|
||||
id: string
|
||||
data: Data
|
||||
name: string
|
||||
}
|
||||
export type LeaderboardResponse = {
|
||||
alltime: LeaderboardEntry[]
|
||||
}
|
||||
|
||||
2
src/shared/constants.ts
Normal file
2
src/shared/constants.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export const RANKED_CHANNEL = '1352157545547960350'
|
||||
export const VANILLA_CHANNEL = '1341599300022567014'
|
||||
Reference in New Issue
Block a user