-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
392 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Card, Text } from '@mantine/core'; | ||
|
||
interface StatCardProps { | ||
label: string; | ||
value: string | number; | ||
icon: React.ReactNode; | ||
} | ||
|
||
export function StatCard({ label, value, icon }: StatCardProps) { | ||
return ( | ||
<Card withBorder={true} className="!bg-white p-4 shadow-none"> | ||
<div className="flex items-center gap-4"> | ||
<div className="bg-primary-50 text-prrimary-500 flex h-12 w-12 items-center justify-center rounded-lg"> | ||
{icon} | ||
</div> | ||
<div> | ||
<Text size="sm" c="dimmed"> | ||
{label} | ||
</Text> | ||
<Text size="xl" fw={500}> | ||
{value} | ||
</Text> | ||
</div> | ||
</div> | ||
</Card> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { BarChart, LineChart } from '@mantine/charts'; | ||
import { Card, Text } from '@mantine/core'; | ||
import { LoaderFunctionArgs } from '@remix-run/node'; | ||
import { useLoaderData } from '@remix-run/react'; | ||
import { | ||
ChartBarLineIcon, | ||
CheckmarkCircle01Icon, | ||
Clock01Icon, | ||
Medal01Icon, | ||
} from 'hugeicons-react'; | ||
|
||
import { AppBreadcrumbs } from '~/components/app-breadcrumbs'; | ||
import { PageHeader } from '~/components/page-header'; | ||
import { StatCard } from '~/components/stat-card'; | ||
import { authenticator } from '~/services/auth.server'; | ||
import { getUserStatistics } from '~/services/statistics.server'; | ||
|
||
export const meta = () => { | ||
return [{ title: 'Overview' }]; | ||
}; | ||
|
||
export const loader = async ({ request }: LoaderFunctionArgs) => { | ||
const user = await authenticator.isAuthenticated(request); | ||
|
||
const stats = await getUserStatistics({ | ||
userId: user!.sub, | ||
type: 'allTime', | ||
}); | ||
|
||
return { stats }; | ||
}; | ||
|
||
export default function Dashboard() { | ||
const { stats } = useLoaderData<typeof loader>(); | ||
return ( | ||
<div className="space-y-4"> | ||
<PageHeader title="Overview" description={<AppBreadcrumbs />} /> | ||
|
||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4"> | ||
<StatCard | ||
label="Total Points" | ||
value={stats.totalPoints.toLocaleString()} | ||
icon={ | ||
<Medal01Icon className="text-primary-500 h-6 w-6" strokeWidth={2} /> | ||
} | ||
/> | ||
<StatCard | ||
label="Problems Solved" | ||
value={stats.totalProblemsSolved.toLocaleString()} | ||
icon={ | ||
<CheckmarkCircle01Icon | ||
className="text-primary-500 h-6 w-6" | ||
strokeWidth={2} | ||
/> | ||
} | ||
/> | ||
<StatCard | ||
label="Average Difficulty" | ||
value={Number(stats.averageDifficulty).toFixed(2)} | ||
icon={ | ||
<ChartBarLineIcon | ||
className="text-primary-500 h-6 w-6" | ||
strokeWidth={2} | ||
/> | ||
} | ||
/> | ||
<StatCard | ||
label="Total Solve Time" | ||
value={ | ||
stats.totalSolveTime | ||
? `${Math.round(Number(stats.totalSolveTime) / 60)}h ${Math.round(Number(stats.totalSolveTime) % 60)}m` | ||
: '-' | ||
} | ||
icon={ | ||
<Clock01Icon className="text-primary-500 h-6 w-6" strokeWidth={2} /> | ||
} | ||
/> | ||
<Card className="col-span-2 !bg-white shadow-none"> | ||
<Text fw={500}>Submissions Status</Text> | ||
<LineChart | ||
h={300} | ||
strokeWidth={2.5} | ||
data={stats.dailySubmissions} | ||
dataKey="date" | ||
series={[ | ||
{ name: 'AC', color: 'primary.5' }, | ||
{ name: 'WA', color: 'red.4' }, | ||
{ name: 'TLE', color: 'orange.3' }, | ||
]} | ||
withDots={false} | ||
tooltipAnimationDuration={200} | ||
valueFormatter={(value) => value.toLocaleString()} | ||
withLegend | ||
legendProps={{ verticalAlign: 'top', height: 50 }} | ||
/> | ||
</Card> | ||
|
||
<Card className="col-span-2 !bg-white shadow-none"> | ||
<Text fw={500}>Top Solved Tags</Text> | ||
<BarChart | ||
h={300} | ||
data={stats.tagStats | ||
.sort((a, b) => b.solveTime - a.solveTime) | ||
.slice(0, 10)} | ||
dataKey="tag" | ||
series={[ | ||
{ | ||
name: 'solveCount', | ||
label: 'Total Solved', | ||
color: 'gray.3', | ||
}, | ||
]} | ||
tooltipAnimationDuration={200} | ||
withLegend | ||
legendProps={{ verticalAlign: 'top', height: 50 }} | ||
barProps={{ radius: 6, barSize: 40 }} | ||
/> | ||
</Card> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.