import { SnCheckInRecord } from '@/services/checkIn' import { getAttachmentUrl, sni } from '@/services/network' import { SnAccount, SnAccountBadgeMapping } from '@/services/user' import { Avatar, Box, Card, CardContent, Container, Grid2 as Grid, Typography } from '@mui/material' import { LineChart } from '@mui/x-charts' import type { InferGetServerSidePropsType, GetServerSideProps } from 'next' import Image from 'next/image' export const getServerSideProps = (async (context) => { const name = context.params!.name as string try { const { data: user } = await sni.get('/cgi/id/users/' + name) const { data: checkIn } = await sni.get<{ data: SnCheckInRecord[] }>('/cgi/id/users/' + name + '/check-in', { params: { take: 14 }, }) return { props: { user, checkIn: checkIn.data } } } catch (err) { return { notFound: true, } } }) satisfies GetServerSideProps<{ user: SnAccount; checkIn: SnCheckInRecord[] }> export default function UserProfile({ user, checkIn }: InferGetServerSidePropsType) { return ( <> {user.banner && ( account banner )} {user && } {user.nick} @{user.name} Fortune History { const og = new Date(c.createdAt) og.setHours(0, 0, 0, 0) return og }), valueFormatter(value, _) { return new Date(value).toLocaleDateString('en-US', { month: '2-digit', day: '2-digit', }) }, }, ]} series={[ { data: checkIn.map((c) => c.resultTier), valueFormatter(value, _) { const resultTierList = ['大凶', '凶', '中平', '吉', '大吉'] return resultTierList[value ?? 0] }, }, ]} height={300} margin={{ top: 16, bottom: 24 }} /> {user.badges && ( Badges {user.badges.map((b) => ( {SnAccountBadgeMapping[b.type].icon} {SnAccountBadgeMapping[b.type].name} {b.metadata.title && {b.metadata.title}} ))} )} Information {user.description && ( {user.description} )} Born on {new Date(user.profile!.birthday!).toLocaleDateString()} Joined at {new Date(user.createdAt).toLocaleDateString()} #{user.id.toString().padStart(8, '0')} ) }