Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 5446431

Browse files
authored
refactor: blog viewer debug (#1181)
* refactor(blog-workflow): viewer & detail page re-org * refactor(constant): extract WORKS/BLOG_TAB constant * refactor(constant): extract tab items
1 parent 6a9a92c commit 5446431

File tree

33 files changed

+386
-219
lines changed

33 files changed

+386
-219
lines changed

src/containers/content/ArticleContent/DesktopView/BlogLayout/ArticleTab.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { buildLog } from '@/utils/logger'
55

66
import { ArticleFooter, Comments } from '@/containers/dynamic'
77
import ArtimentBody from '@/widgets/ArtimentBody'
8-
8+
import Linker from '@/widgets/Linker'
99
import ViewportTracker from '@/widgets/ViewportTracker'
1010

1111
import {
@@ -35,6 +35,7 @@ const ArticleTab: FC<TProps> = ({ metric, article }) => {
3535
/>
3636
<MainWrapper metric={metric}>
3737
<ArticleWrapper ref={ref}>
38+
<Linker src={article.linkAddr} right={10} bottom={25} hint="原文:" />
3839
<ArtimentBody document={article.document} />
3940
<ArticleFooter metric={metric} />
4041
</ArticleWrapper>

src/containers/content/ArticleContent/DesktopView/BlogLayout/AuthorTab.tsx

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,9 @@ import { FC } from 'react'
33
import type { TMetric, TRSSAuthor } from '@/spec'
44
import { buildLog } from '@/utils/logger'
55

6-
import NoticeBar from '@/widgets/NoticeBar'
7-
import DotDivider from '@/widgets/DotDivider'
6+
import BlogAuthorInfo from '@/widgets/BlogAuthorInfo'
87

9-
import {
10-
MainWrapper,
11-
ArticleWrapper,
12-
UserName,
13-
Intro,
14-
GithubIcon,
15-
TwitterIcon,
16-
} from '../../styles/desktop_view/blog_layout/author_tab'
8+
import { MainWrapper, ArticleWrapper } from '../../styles/desktop_view'
179

1810
/* eslint-disable-next-line */
1911
const log = buildLog('C:BlogContent:AuthorTab')
@@ -24,45 +16,10 @@ type TProps = {
2416
}
2517

2618
const AuthorTab: FC<TProps> = ({ metric, author }) => {
27-
if (!author) {
28-
return (
29-
<MainWrapper metric={metric}>
30-
<ArticleWrapper>
31-
<NoticeBar
32-
type="notice"
33-
content=" 暂无作者信息,志愿者将尽快搜集公开资料完善博客作者的信息。如果你有这方面的资料,欢迎在博文讨论区补充/纠正。 "
34-
top={-5}
35-
bottom={20}
36-
left={-2}
37-
/>
38-
</ArticleWrapper>
39-
</MainWrapper>
40-
)
41-
}
42-
43-
const { name, intro, twitter, github } = author
44-
4519
return (
4620
<MainWrapper metric={metric}>
4721
<ArticleWrapper>
48-
<div>
49-
<UserName>
50-
{name}
51-
{(twitter || github) && <DotDivider space={12} />}
52-
{github && (
53-
<a href={github} target="_blank" rel="noreferrer">
54-
<GithubIcon />
55-
</a>
56-
)}
57-
58-
{twitter && (
59-
<a href={twitter} target="_blank" rel="noreferrer">
60-
<TwitterIcon />
61-
</a>
62-
)}
63-
</UserName>
64-
<Intro>{intro}</Intro>
65-
</div>
22+
<BlogAuthorInfo author={author} />
6623
</ArticleWrapper>
6724
</MainWrapper>
6825
)

src/containers/content/ArticleContent/DesktopView/BlogLayout/FeedsTab.tsx

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
import { FC } from 'react'
2-
import TimeAgo from 'timeago-react'
32

43
import type { TMetric, TBlog } from '@/spec'
54
import { buildLog } from '@/utils/logger'
65

7-
import NoticeBar from '@/widgets/NoticeBar'
6+
import BlogFeedsList from '@/widgets/BlogFeedsList'
7+
88
import { MainWrapper, ArticleWrapper } from '../../styles/desktop_view'
9-
import {
10-
Wrapper,
11-
Header,
12-
PubDate,
13-
Title,
14-
Digest,
15-
} from '../../styles/desktop_view/blog_layout/feeds_tab'
169

1710
/* eslint-disable-next-line */
1811
const log = buildLog('C:BlogContent:FeedTab')
@@ -26,28 +19,7 @@ const FeedsTab: FC<TProps> = ({ items, metric }) => {
2619
return (
2720
<MainWrapper metric={metric}>
2821
<ArticleWrapper>
29-
<NoticeBar
30-
type="notice"
31-
content="数据来自该博客提供的 RSS 订阅源,可能会有滞后。 "
32-
top={-5}
33-
bottom={20}
34-
left={-2}
35-
/>
36-
37-
{items.map((item) => (
38-
<Wrapper key={item.id}>
39-
<Header>
40-
<Title href={item.linkAddr} target="_blank">
41-
{item.title}
42-
</Title>
43-
<PubDate>
44-
<TimeAgo datetime={item.published} locale="zh_CN" />
45-
</PubDate>
46-
</Header>
47-
48-
<Digest>{item.digest}</Digest>
49-
</Wrapper>
50-
))}
22+
<BlogFeedsList items={items} />
5123
</ArticleWrapper>
5224
</MainWrapper>
5325
)

src/containers/content/ArticleContent/DesktopView/BlogLayout/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { FC } from 'react'
22

33
import type { TMetric } from '@/spec'
4+
import { BLOG_TAB } from '@/constant'
5+
46
import { buildLog } from '@/utils/logger'
57
import { pluggedIn } from '@/utils/mobx'
68

@@ -38,7 +40,7 @@ const ArticleContentContainer: FC<TProps> = ({
3840

3941
const { viewingArticle, articleTab, blogRssInfoData } = store
4042
if (!viewingArticle.id) return null
41-
if (articleTab === 'feeds') {
43+
if (articleTab === BLOG_TAB.FEEDS) {
4244
return (
4345
<Wrapper testid={testid}>
4446
<InnerWrapper>
@@ -51,7 +53,7 @@ const ArticleContentContainer: FC<TProps> = ({
5153
)
5254
}
5355

54-
if (articleTab === 'author') {
56+
if (articleTab === BLOG_TAB.AUTHOR) {
5557
return (
5658
<Wrapper testid={testid}>
5759
<InnerWrapper>

src/containers/content/ArticleContent/DesktopView/WorksLayout/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { FC } from 'react'
22

33
import type { TMetric } from '@/spec'
4+
import { WORKS_TAB } from '@/constant'
5+
46
import { buildLog } from '@/utils/logger'
57
import { pluggedIn } from '@/utils/mobx'
68

@@ -38,7 +40,7 @@ const ArticleContentContainer: FC<TProps> = ({
3840
const { viewingArticle, articleTab } = store
3941
if (!viewingArticle.id) return null
4042

41-
if (articleTab === 'techstack') {
43+
if (articleTab === WORKS_TAB.TECHSTACKS) {
4244
return (
4345
<Wrapper testid={testid}>
4446
<InnerWrapper>

src/containers/digest/ArticleDigest/DesktopView/BlogLayout.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { FC, Fragment, memo } from 'react'
66

77
import type { TBlog, TMetric } from '@/spec'
8-
import { METRIC } from '@/constant'
8+
import { METRIC, BLOG_TAB_ITEMS } from '@/constant'
99
import { buildLog } from '@/utils/logger'
1010
import { cutRest } from '@/utils/helper'
1111

@@ -37,21 +37,6 @@ type TProps = {
3737
tab: string
3838
}
3939

40-
const tabItems = [
41-
{
42-
title: '摘要',
43-
raw: 'digest',
44-
},
45-
{
46-
title: '历史文章',
47-
raw: 'feeds',
48-
},
49-
{
50-
title: '博客作者',
51-
raw: 'author',
52-
},
53-
]
54-
5540
const BlogLayout: FC<TProps> = ({ metric = METRIC.ARTICLE, article, tab }) => {
5641
return (
5742
<Fragment>
@@ -70,7 +55,7 @@ const BlogLayout: FC<TProps> = ({ metric = METRIC.ARTICLE, article, tab }) => {
7055
<AuthorName>by: {article.author.nickname}</AuthorName>
7156
<TabWrapper>
7257
<Tabs
73-
items={tabItems}
58+
items={BLOG_TAB_ITEMS}
7459
size="small"
7560
activeKey={tab}
7661
bottomSpace={10}

src/containers/digest/ArticleDigest/DesktopView/WorksLayout.tsx

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*/
44

55
import { FC, Fragment, memo } from 'react'
6+
import { reject } from 'ramda'
67

78
import type { TWorks, TMetric } from '@/spec'
8-
import { METRIC, UPVOTE_LAYOUT } from '@/constant'
9+
import { METRIC, UPVOTE_LAYOUT, WORKS_TAB_ITEMS, WORKS_TAB } from '@/constant'
910
import { buildLog } from '@/utils/logger'
1011

1112
import ArticleBaseStats from '@/widgets/ArticleBaseStats'
@@ -40,33 +41,12 @@ type TProps = {
4041
tab: string
4142
}
4243

43-
const tabItems = [
44-
{
45-
title: '简介',
46-
raw: 'story',
47-
},
48-
{
49-
title: '技术栈',
50-
raw: 'techstack',
51-
},
52-
{
53-
title: '更新',
54-
raw: 'update',
55-
},
56-
{
57-
title: '作者访谈',
58-
raw: 'interview',
59-
},
60-
{
61-
title: '社区',
62-
raw: 'community',
63-
},
64-
]
65-
6644
const WorksLayout: FC<TProps> = ({ metric = METRIC.ARTICLE, article, tab }) => {
6745
const { meta, title, desc, upvotesCount } = article
6846

6947
const activeTab = !!tab ? tab : 'story'
48+
const tabItems = reject((t) => t.raw === WORKS_TAB.BASIC, WORKS_TAB_ITEMS)
49+
7050
return (
7151
<Fragment>
7252
<Main metric={metric}>

src/containers/digest/ArticleDigest/logic.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react'
22

33
import type { TScrollDirection, TWorksTab, TBlog } from '@/spec'
4-
import { EVENT, ERR } from '@/constant'
4+
import { EVENT, ERR, BLOG_TAB } from '@/constant'
55
import asyncSuit from '@/utils/async'
66
import { send, errRescue } from '@/utils/helper'
77
import { buildLog } from '@/utils/logger'
@@ -34,7 +34,10 @@ export const onBlogTabChange = (tab: string): void => {
3434
store.mark({ tab })
3535
const blog = store.viewingArticle as TBlog
3636

37-
if ((tab === 'feeds' || tab === 'author') && !store.blogRssInfo.title) {
37+
if (
38+
(tab === BLOG_TAB.FEEDS || tab === BLOG_TAB.AUTHOR) &&
39+
!store.blogRssInfo.title
40+
) {
3841
const args = { rss: blog.rss }
3942
sr71$.query(S.blogRssInfo, args)
4043
}
@@ -53,10 +56,7 @@ export const onListReactionUsers = (type, data): void =>
5356
const DataSolver = [
5457
{
5558
match: asyncRes('blogRssInfo'),
56-
action: ({ blogRssInfo }) => {
57-
log('blogRssInfo: ', blogRssInfo)
58-
store.mark({ blogRssInfo })
59-
},
59+
action: ({ blogRssInfo }) => store.mark({ blogRssInfo }),
6060
},
6161
]
6262
const ErrSolver = [

src/containers/digest/ArticleDigest/schema.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { gql } from '@urql/core'
2+
import { P } from '@/schemas'
23

34
const post = gql`
45
query ($id: ID!) {
@@ -32,28 +33,7 @@ const repo = gql`
3233
`
3334

3435
const blogRssInfo = gql`
35-
query ($rss: String!) {
36-
blogRssInfo(rss: $rss) {
37-
title
38-
subtitle
39-
link
40-
updated
41-
author {
42-
name
43-
intro
44-
github
45-
twitter
46-
}
47-
historyFeed {
48-
title
49-
digest
50-
linkAddr
51-
content
52-
published
53-
updated
54-
}
55-
}
56-
}
36+
${P.blogRssInfo}
5737
`
5838

5939
const schema = {

src/containers/viewer/ArticleViewer/BlogViewer/ArticleInfo.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { memo, FC } from 'react'
22

33
import type { TArticle } from '@/spec'
4+
import { BLOG_TAB, BLOG_TAB_ITEMS } from '@/constant'
45
import { ICON } from '@/config'
56

67
import DotDivider from '@/widgets/DotDivider'
@@ -19,28 +20,16 @@ import {
1920
BaseWrapper,
2021
UpvoteWrapper,
2122
} from '../styles/blog_viewer/article_info'
23+
import { blogTabOnChange } from '../logic'
2224

2325
type TProps = {
2426
article: TArticle
27+
tab: string
2528
}
2629

27-
const tabItems = [
28-
{
29-
title: '摘要',
30-
raw: 'digest',
31-
},
32-
{
33-
title: '关于作者',
34-
raw: 'author',
35-
},
36-
{
37-
title: '历史文章',
38-
raw: 'history',
39-
},
40-
]
41-
42-
const ArticleInfo: FC<TProps> = ({ article }) => {
30+
const ArticleInfo: FC<TProps> = ({ article, tab }) => {
4331
const { upvotesCount, meta } = article
32+
const activeTab = !!tab ? tab : BLOG_TAB.DIGEST
4433

4534
return (
4635
<Wrapper>
@@ -58,10 +47,11 @@ const ArticleInfo: FC<TProps> = ({ article }) => {
5847
<BottomWrapper>
5948
<TabsWrapper>
6049
<Tabs
61-
items={tabItems}
50+
items={BLOG_TAB_ITEMS}
6251
size="small"
63-
activeKey="digest"
52+
activeKey={activeTab}
6453
bottomSpace={10}
54+
onChange={blogTabOnChange}
6555
/>
6656
</TabsWrapper>
6757
<UpvoteWrapper>

0 commit comments

Comments
 (0)