Skip to content

Commit a07d6d3

Browse files
committed
feat: add profile page
1 parent e8ac487 commit a07d6d3

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

src/components/AccountManager.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,11 @@ const AccountMenu: FC = () => {
7373
/>
7474
)}
7575

76-
{isSM && (
77-
<MenuItem
78-
shouldDismissPopover={false}
79-
icon="user"
80-
text={authState.username}
81-
/>
82-
)}
83-
76+
<MenuItem
77+
icon="person"
78+
text={(isSM ? authState.username + ' - ' : '') + '个人主页'}
79+
href={`/profile/${authState.userId}`}
80+
/>
8481
<MenuItem
8582
shouldDismissPopover={false}
8683
icon="edit"

src/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ const CreatePageLazy = withSuspensable(
5757
const AboutPageLazy = withSuspensable(
5858
lazy(() => import('./pages/about').then((m) => ({ default: m.AboutPage }))),
5959
)
60+
const ProfilePageLazy = withSuspensable(
61+
lazy(() =>
62+
import('./pages/profile').then((m) => ({ default: m.ProfilePage })),
63+
),
64+
)
6065

6166
ReactDOM.createRoot(document.getElementById('root')!).render(
6267
<React.StrictMode>
@@ -67,6 +72,7 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
6772
<Route path="/create/:id" element={<CreatePageLazy />} />
6873
<Route path="/create" element={<CreatePageLazy />} />
6974
<Route path="/about" element={<AboutPageLazy />} />
75+
<Route path="/profile/:id" element={<ProfilePageLazy />} />
7076
<Route path="/operation/:id" element={<ViewPage />} />
7177
<Route path="*" element={<NotFoundPage />} />
7278
</Routes>

src/pages/profile.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Button, ButtonGroup, Card } from '@blueprintjs/core'
2+
3+
import { ComponentType, useState } from 'react'
4+
import { useParams } from 'react-router-dom'
5+
6+
import { withGlobalErrorBoundary } from 'components/GlobalErrorBoundary'
7+
import { OperationList } from 'components/OperationList'
8+
import { OperationSetList } from 'components/OperationSetList'
9+
import { OperationDrawer } from 'components/drawer/OperationDrawer'
10+
11+
import { CardTitle } from '../components/CardTitle'
12+
import { withSuspensable } from '../components/Suspensable'
13+
14+
export const _ProfilePage: ComponentType = () => {
15+
const { id } = useParams()
16+
17+
// edge case?
18+
if (!id) {
19+
throw new Error('ID 无效')
20+
}
21+
22+
const [listMode, setListMode] = useState<'operation' | 'operationSet'>(
23+
'operation',
24+
)
25+
26+
return (
27+
<div className="flex flex-col md:flex-row px-8 mt-8 max-w-[96rem] mx-auto">
28+
<div className="md:w-2/3 order-2 md:order-1 mr-0 md:mr-8">
29+
<div className="mb-4 flex flex-wrap">
30+
<ButtonGroup className="mr-2">
31+
<Button
32+
icon="document"
33+
active={listMode === 'operation'}
34+
onClick={() => setListMode('operation')}
35+
>
36+
作业
37+
</Button>
38+
<Button
39+
icon="folder-close"
40+
active={listMode === 'operationSet'}
41+
onClick={() => setListMode('operationSet')}
42+
>
43+
作业集
44+
</Button>
45+
</ButtonGroup>
46+
</div>
47+
48+
<div className="tabular-nums">
49+
{listMode === 'operation' && (
50+
<OperationList limit={10} orderBy="id" uploaderId={id} />
51+
)}
52+
{listMode === 'operationSet' && <OperationSetList creatorId={id} />}
53+
</div>
54+
</div>
55+
<div className="md:w-1/3 order-1 md:order-2">
56+
<div className="sticky top-20">
57+
<Card className="flex flex-col mb-4 space-y-2">
58+
<CardTitle icon="user">用户名</CardTitle>
59+
</Card>
60+
</div>
61+
</div>
62+
63+
<OperationDrawer />
64+
</div>
65+
)
66+
}
67+
_ProfilePage.displayName = 'ProfilePage'
68+
69+
export const ProfilePage = withGlobalErrorBoundary(
70+
withSuspensable(_ProfilePage),
71+
)

0 commit comments

Comments
 (0)