diff --git a/bun.lockb b/bun.lockb index aa841f4..efe9f35 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/next.config.ts b/next.config.ts index 3915163..b441baf 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,8 +1,11 @@ -import type { NextConfig } from "next"; +import type { NextConfig } from 'next' const nextConfig: NextConfig = { /* config options here */ reactStrictMode: true, -}; + images: { + domains: ['raw.sn.solsynth.dev', 'api.sn.solsynth.dev'], + }, +} -export default nextConfig; +export default nextConfig diff --git a/package.json b/package.json index e3a10be..8777ac7 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@emotion/styled": "^11.14.0", "@mui/icons-material": "^6.3.0", "@mui/material": "^6.3.0", + "@mui/x-charts": "^7.23.2", "axios": "^1.7.9", "axios-case-converter": "^1.1.1", "cookies-next": "^5.0.2", diff --git a/src/pages/users/[name].tsx b/src/pages/users/[name].tsx new file mode 100644 index 0000000..604b531 --- /dev/null +++ b/src/pages/users/[name].tsx @@ -0,0 +1,114 @@ +import { SnCheckInRecord } from '@/services/checkIn' +import { getAttachmentUrl, sni } from '@/services/network' +import { SnAccount } 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 }} + /> + + + + + + + + Information + + + + Born on {new Date(user.profile!.birthday!).toLocaleDateString()} + + Joined at {new Date(user.createdAt).toLocaleDateString()} + + + + + + + ) +} diff --git a/src/pages/users/me.tsx b/src/pages/users/me.tsx index c4f59dc..286ced3 100644 --- a/src/pages/users/me.tsx +++ b/src/pages/users/me.tsx @@ -1,12 +1,40 @@ import { checkAuthenticatedClient, redirectToLogin } from '@/services/auth' -import { Container } from '@mui/material' -import { useRouter } from 'next/router' +import { useUserStore } from '@/services/user' +import { Avatar, Box, Container, Typography } from '@mui/material' +import { getAttachmentUrl } from '@/services/network' import { useEffect } from 'react' +import Image from 'next/image' export default function UserItself() { useEffect(() => { if (!checkAuthenticatedClient()) redirectToLogin() }, []) - return + const userStore = useUserStore() + + return ( + <> + {userStore.account && ( + + account banner + + )} + + + + + {userStore.account && } + + {userStore.account?.nick} + + @{userStore.account?.name} + + + + + + + + + ) } diff --git a/src/services/checkIn.ts b/src/services/checkIn.ts new file mode 100644 index 0000000..aa7b8a5 --- /dev/null +++ b/src/services/checkIn.ts @@ -0,0 +1,10 @@ +export interface SnCheckInRecord { + id: number + createdAt: Date + updatedAt: Date + deletedAt?: Date | null + resultTier: number + resultExperience: number + resultModifiers: number[] + accountId: number +} diff --git a/src/services/user.ts b/src/services/user.ts index 1802329..62a7677 100644 --- a/src/services/user.ts +++ b/src/services/user.ts @@ -2,7 +2,7 @@ import { create } from 'zustand' import { sni } from './network' import { hasCookie } from 'cookies-next/client' -interface SnAccount { +export interface SnAccount { id: number createdAt: Date updatedAt: Date @@ -24,7 +24,7 @@ interface SnAccount { automatedId?: number | null } -interface SnAccountContact { +export interface SnAccountContact { accountId: number content: string createdAt: Date @@ -37,7 +37,7 @@ interface SnAccountContact { verifiedAt?: Date | null } -interface SnAccountProfile { +export interface SnAccountProfile { id: number accountId: number birthday?: Date | null @@ -50,7 +50,7 @@ interface SnAccountProfile { updatedAt: Date } -interface SnAccountBadge { +export interface SnAccountBadge { id: number createdAt: Date updatedAt: Date