Skip to content

Commit 3a55939

Browse files
committed
feat: 重构ArchivedPage和MainPage,添加NavBar以增强用户体验
1 parent a7b404b commit 3a55939

2 files changed

Lines changed: 86 additions & 54 deletions

File tree

web/src/pages/archived/index.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getRotesV2 } from '@/utils/roteApi';
1010
import { Archive, ChartAreaIcon, RefreshCw } from 'lucide-react';
1111
import { useTranslation } from 'react-i18next';
1212

13-
function ArchivedPage() {
13+
function MainPage() {
1414
const { t } = useTranslation('translation', { keyPrefix: 'pages.archived' });
1515

1616
const getPropsMineArchived = (
@@ -41,6 +41,21 @@ function ArchivedPage() {
4141

4242
mutate();
4343
};
44+
return (
45+
<>
46+
<NavBar title={t('title')} icon={<Archive className="size-6" />} onNavClick={refreshData}>
47+
{isLoading ||
48+
(isValidating && (
49+
<RefreshCw className="text-primary ml-auto size-4 animate-spin duration-300" />
50+
))}
51+
</NavBar>
52+
<RoteList data={data} loadMore={loadMore} mutate={mutate} />
53+
</>
54+
);
55+
}
56+
57+
function ArchivedPage() {
58+
const { t } = useTranslation('translation', { keyPrefix: 'pages.archived' });
4459

4560
const SideBar = () => (
4661
<>
@@ -62,14 +77,7 @@ function ArchivedPage() {
6277
</div>
6378
}
6479
>
65-
<NavBar title={t('title')} icon={<Archive className="size-6" />} onNavClick={refreshData}>
66-
{isLoading ||
67-
(isValidating && (
68-
<RefreshCw className="text-primary ml-auto size-4 animate-spin duration-300" />
69-
))}
70-
</NavBar>
71-
72-
<RoteList data={data} loadMore={loadMore} mutate={mutate} />
80+
<MainPage />
7381
</ContainerWithSideBar>
7482
);
7583
}

web/src/pages/home/index.tsx

Lines changed: 69 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,36 @@ import { ChartAreaIcon, RefreshCw, User } from 'lucide-react';
1717
import { useTranslation } from 'react-i18next';
1818
import { useNavigate } from 'react-router-dom';
1919

20-
const SideBar = () => {
21-
const navigate = useNavigate();
22-
20+
function MainPageHeader({
21+
refreshData,
22+
isLoading,
23+
isValidating,
24+
}: {
25+
refreshData: () => void;
26+
isLoading?: boolean;
27+
isValidating?: boolean;
28+
}) {
2329
return (
24-
<>
25-
<SearchBar
26-
onSearch={(keyword) => {
27-
navigate('/filter', {
28-
state: {
29-
initialKeyword: keyword.trim(),
30-
},
31-
});
32-
}}
30+
<div
31+
className="group bg-background sticky top-0 z-10 flex cursor-pointer items-center gap-2 p-4 py-4.5 font-light text-gray-600"
32+
onClick={refreshData}
33+
>
34+
<Logo className="h-6 w-fit" color="#07C160" />
35+
<img
36+
className="text-theme mb-[2px] ml-2 h-4 opacity-0 duration-300 group-hover:opacity-100"
37+
src={slogenImg}
38+
alt="slogen"
3339
/>
34-
<Heatmap />
35-
<TagMap />
36-
<RandomRote />
37-
</>
40+
41+
{isLoading ||
42+
(isValidating && (
43+
<RefreshCw className="text-primary ml-auto size-4 animate-spin duration-300" />
44+
))}
45+
</div>
3846
);
39-
};
47+
}
4048

41-
function HomePage() {
42-
const { t } = useTranslation('translation', { keyPrefix: 'pages.home' });
49+
function MainPage() {
4350
const { data: profile } = useAPIGet<Profile>('profile', () =>
4451
get('/users/me/profile').then((res) => res.data)
4552
);
@@ -74,32 +81,8 @@ function HomePage() {
7481
};
7582

7683
return (
77-
<ContainerWithSideBar
78-
sidebar={<SideBar />}
79-
sidebarHeader={
80-
<div className="flex items-center gap-2 p-4 text-lg font-semibold">
81-
<div className="flex h-8 items-center gap-2">
82-
<ChartAreaIcon className="size-5" />
83-
{t('statistics')}
84-
</div>
85-
</div>
86-
}
87-
>
88-
<div
89-
className="group bg-background sticky top-0 z-10 flex cursor-pointer items-center gap-2 p-4 py-3 font-light text-gray-600"
90-
onClick={refreshData}
91-
>
92-
<Logo className="w-24" color="#07C160" />
93-
<img
94-
className="text-theme mb-[2px] ml-2 h-4 opacity-0 duration-300 group-hover:opacity-100"
95-
src={slogenImg}
96-
alt="slogen"
97-
/>
98-
{isLoading ||
99-
(isValidating && (
100-
<RefreshCw className="text-primary ml-auto size-4 animate-spin duration-300" />
101-
))}
102-
</div>
84+
<>
85+
<MainPageHeader refreshData={refreshData} isLoading={isLoading} isValidating={isValidating} />
10386
<div className="flex gap-4 p-4">
10487
<Avatar className="hidden size-10 shrink-0 overflow-hidden rounded-full xl:block">
10588
{profile?.avatar ? (
@@ -118,6 +101,47 @@ function HomePage() {
118101
/>
119102
</div>
120103
<RoteList data={data} loadMore={loadMore} mutate={mutate} />
104+
</>
105+
);
106+
}
107+
108+
function HomePage() {
109+
const { t } = useTranslation('translation', { keyPrefix: 'pages.home' });
110+
111+
const SideBar = () => {
112+
const navigate = useNavigate();
113+
114+
return (
115+
<>
116+
<SearchBar
117+
onSearch={(keyword) => {
118+
navigate('/filter', {
119+
state: {
120+
initialKeyword: keyword.trim(),
121+
},
122+
});
123+
}}
124+
/>
125+
<Heatmap />
126+
<TagMap />
127+
<RandomRote />
128+
</>
129+
);
130+
};
131+
132+
return (
133+
<ContainerWithSideBar
134+
sidebar={<SideBar />}
135+
sidebarHeader={
136+
<div className="flex items-center gap-2 p-4 text-lg font-semibold">
137+
<div className="flex items-center gap-2">
138+
<ChartAreaIcon className="size-5" />
139+
{t('statistics')}
140+
</div>
141+
</div>
142+
}
143+
>
144+
<MainPage />
121145
</ContainerWithSideBar>
122146
);
123147
}

0 commit comments

Comments
 (0)