Skip to content

Commit f932791

Browse files
committed
Setup helemt and fix small bugs in reading list
1 parent 8927d90 commit f932791

File tree

8 files changed

+92
-13
lines changed

8 files changed

+92
-13
lines changed

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Route, Switch } from 'react-router-dom';
2+
import { Route, Switch, Redirect } from 'react-router-dom';
33
// import PostPage from './pages/PostPage';
44

55
import loadable from '@loadable/component';
@@ -80,6 +80,7 @@ const App: React.FC<AppProps> = props => {
8080
<Route path="/setting" component={SettingPage} />
8181
<Route path="/success" component={SuccessPage} />
8282
<Route path="/lists/:type(liked|read)" component={ReadingListPage} />
83+
<Route path="/lists" render={() => <Redirect to="/lists/liked" />} />
8384
<Route component={NotFoundPage} />
8485
</Switch>
8586
</ErrorBoundary>

src/components/base/HeaderUserMenu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const HeaderUserMenu: React.FC<HeaderUserMenuProps> = ({
3939
내 벨로그
4040
</HeaderUserMenuItem>
4141
<HeaderUserMenuItem to="/saves">임시 글</HeaderUserMenuItem>
42+
<HeaderUserMenuItem to="/lists/liked">읽기 목록</HeaderUserMenuItem>
4243
<HeaderUserMenuItem to="/setting">설정</HeaderUserMenuItem>
4344
<HeaderUserMenuItem onClick={onLogout}>로그아웃</HeaderUserMenuItem>
4445
</div>

src/components/base/HeaderUserMenuItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const HeaderUserMenuItemBlock = styled.div`
1414
padding: 0.75rem 1rem;
1515
line-height: 1.5;
1616
font-weight: 500;
17+
cursor: pointer;
1718
&:hover {
1819
background: ${palette.gray0};
1920
}

src/pages/SearchPage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import LargeSearchInput from '../containers/search/LargeSearchInput';
44
import SearchResult from '../containers/search/SearchResult';
55
import { RouteComponentProps } from 'react-router';
66
import qs from 'qs';
7+
import { Helmet } from 'react-helmet-async';
78

89
export interface SearchPageProps extends RouteComponentProps {}
910

@@ -17,6 +18,11 @@ function SearchPage({ location }: SearchPageProps) {
1718

1819
return (
1920
<SearchTemplate>
21+
<Helmet>
22+
{(query.q || query.username) && (
23+
<meta name="robots" content="noindex" />
24+
)}
25+
</Helmet>
2026
<LargeSearchInput initialKeyword={query.q} />
2127
<SearchResult keyword={query.q} username={query.username} />
2228
</SearchTemplate>

src/pages/home/RecentPostsPage.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import useRecentPosts from './hooks/useRecentPosts';
33
import PostCardGrid, {
44
PostCardGridSkeleton,
55
} from '../../components/common/PostCardGrid';
6+
import { Helmet } from 'react-helmet-async';
67

78
export type RecentPostsPageProps = {};
89

910
function RecentPostsPage(props: RecentPostsPageProps) {
1011
const { data, loading } = useRecentPosts();
1112

1213
return (
13-
<PostCardGrid
14-
posts={data?.posts || []}
15-
forHome
16-
loading={!data || loading}
17-
/>
14+
<>
15+
<Helmet>
16+
<title>최신 포스트 - velog</title>
17+
<meta
18+
name="description"
19+
content="벨로그에서 다양한 개발자들이 작성한 따끈따끈한 최신 포스트들을 읽어보세요."
20+
/>
21+
</Helmet>
22+
<PostCardGrid
23+
posts={data?.posts || []}
24+
forHome
25+
loading={!data || loading}
26+
/>
27+
</>
1828
);
1929
}
2030

src/pages/home/TrendingPostsPage.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,24 @@ import PostCardGrid, {
33
PostCardGridSkeleton,
44
} from '../../components/common/PostCardGrid';
55
import useTrendingPosts from './hooks/useTrendingPosts';
6+
import { Helmet } from 'react-helmet-async';
67

78
export type TrendingPageProps = {};
89

910
function TrendingPage(props: TrendingPageProps) {
1011
const { data, loading } = useTrendingPosts();
1112

1213
return (
13-
<PostCardGrid
14-
posts={data?.trendingPosts || []}
15-
forHome
16-
loading={!data || loading}
17-
/>
14+
<>
15+
<Helmet>
16+
<link rel="canonical" href="https://velog.io/" />
17+
</Helmet>
18+
<PostCardGrid
19+
posts={data?.trendingPosts || []}
20+
forHome
21+
loading={!data || loading}
22+
/>
23+
</>
1824
);
1925
}
2026

src/pages/readingList/ReadingListPage.tsx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import MainPageTemplate from '../../components/main/MainPageTemplate';
33
import MainResponsive from '../../components/main/MainResponsive';
44
import ReadingListTab from '../../components/readingList/ReadingListTab';
@@ -8,22 +8,36 @@ import useReadingList from './hooks/useReadingList';
88
import PostCardGrid, {
99
PostCardGridSkeleton,
1010
} from '../../components/common/PostCardGrid';
11+
import { undrawEmpty } from '../../static/images';
12+
import palette from '../../lib/styles/palette';
13+
import media from '../../lib/styles/media';
14+
import { Helmet } from 'react-helmet-async';
1115

1216
export type ReadingListPageProps = {} & RouteComponentProps<{
1317
type: 'liked' | 'read';
1418
}>;
1519

16-
function ReadingListPage({ match }: ReadingListPageProps) {
20+
function ReadingListPage({ match, history }: ReadingListPageProps) {
1721
const { type } = match.params;
1822

1923
const { data, loading, isFinished } = useReadingList(type);
2024

2125
return (
2226
<MainPageTemplate>
27+
<Helmet>
28+
{<meta name="robots" content="noindex" />}
29+
<title>읽기 목록 - velog</title>
30+
</Helmet>
2331
<StyledResponsive>
2432
<ReadingListTab type={type} />
2533
<Wrapper>
2634
<PostCardGrid posts={data?.readingList || []} loading={!isFinished} />
35+
{data && data.readingList.length === 0 && (
36+
<EmptyWrapper>
37+
<img src={undrawEmpty} alt="list is empty" />
38+
<div className="description">리스트가 비어있습니다.</div>
39+
</EmptyWrapper>
40+
)}
2741
</Wrapper>
2842
</StyledResponsive>
2943
</MainPageTemplate>
@@ -38,4 +52,35 @@ const Wrapper = styled.div`
3852
margin-top: 2rem;
3953
`;
4054

55+
const EmptyWrapper = styled.div`
56+
margin-top: 6rem;
57+
align-items: center;
58+
justify-content: center;
59+
display: flex;
60+
flex-direction: column;
61+
img {
62+
width: 25rem;
63+
height: auto;
64+
display: block;
65+
margin-bottom: 2rem;
66+
}
67+
68+
.description {
69+
color: ${palette.gray7};
70+
font-size: 1.5rem;
71+
}
72+
73+
${media.small} {
74+
margin-top: 3rem;
75+
img {
76+
max-width: 300px;
77+
width: calc(100% - 2rem);
78+
margin-bottom: 1rem;
79+
}
80+
.description {
81+
font-size: 1.25rem;
82+
}
83+
}
84+
`;
85+
4186
export default ReadingListPage;

src/pages/readingList/hooks/useReadingList.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@ export default function useReadingList(type: 'liked' | 'read') {
1414
type: type.toUpperCase(),
1515
limit: 20,
1616
},
17+
fetchPolicy: 'cache-and-network',
1718
},
1819
);
1920
const [isFinished, setIsFinished] = useState(false);
21+
2022
useEffect(() => {
2123
setIsFinished(false);
2224
}, [type]);
2325

26+
useEffect(() => {
27+
if (!data) return;
28+
if (data.readingList.length < 20) {
29+
setIsFinished(true);
30+
}
31+
}, [data]);
32+
2433
const onLoadMore = useCallback(
2534
(cursor: string) => {
2635
fetchMore({

0 commit comments

Comments
 (0)