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

Commit a4c50ef

Browse files
authored
refactor(articles-thread): extract articles thread (#1108)
* refactor(articlesFilter): adjust props * feat: add useMST hooks, awesome * chore: missing inline doc * chore(articles-thread): basic setup * chore(articles-thread): drop PostsThread * refactor(articlesFilter): wip * fix(preview): edge case * chore(types): add common used useMST store type * refactor(useMST): split it into useAccount * refactor(useAccount): improve type * refactor(useAccount): imporve substore hooks * chore(articles-thread): filter naming * refactor: wip * refactor(loadingEffect): rename to loading & ts * refactor: wip * refactor: wip * refactor(articlesThread): adjust props * refactor(articlesThread): make onPreview eventify * chore(articlesThread): fmt * chore(articlesThread): mv holygrail tabs to common layout * refactor(community-content): re-org * refactor(articlesThread): tab change wip
1 parent 162c729 commit a4c50ef

File tree

126 files changed

+1109
-2372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1109
-2372
lines changed

server/routes.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ router.route('/:community/help-center').get((req, res) => {
124124
return renderAndCache({ req, res, path: '/help-center' })
125125
})
126126

127-
// NOTE: TMP: 博客
128-
router.route('/:community/blogs').get((req, res) => {
129-
return renderAndCache({ req, res, path: '/home/blogs' })
130-
})
131-
132127
// 社区主页
133128
router.route('/:community/:thread').get((req, res) => {
134129
if (

src/components/ArticleItemPrefixLabel/ReadLabel.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { FC, memo } from 'react'
2+
import { useAccount } from '@/hooks'
23

34
import { ReadedLabel } from './styles'
4-
55
import type { TProps } from './index'
66

7-
const ReadLabel: FC<TProps> = ({ entry, accountInfo, topOffset = '20px' }) => {
7+
const ReadLabel: FC<TProps> = ({ entry, topOffset = '20px' }) => {
8+
const { c11n } = useAccount()
9+
const { isLogin, markViewed } = c11n
10+
811
const { viewerHasViewed } = entry
9-
const {
10-
isLogin,
11-
customization: { markViewed },
12-
} = accountInfo
1312

1413
if (!isLogin) return null
1514
if (markViewed && viewerHasViewed) {

src/components/ArticleItemPrefixLabel/index.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { FC, memo } from 'react'
88

9-
import type { TAccount } from '@/spec'
109
import { buildLog } from '@/utils'
1110
import { PinIcon } from './styles'
1211
import ReadLabel from './ReadLabel'
@@ -15,23 +14,16 @@ import ReadLabel from './ReadLabel'
1514
const log = buildLog('c:ArticleItemPrefixLabel:index')
1615

1716
export type TProps = {
18-
accountInfo: TAccount
1917
topOffset?: string
2018
entry: {
2119
viewerHasViewed?: boolean
2220
pin?: boolean
2321
}
2422
}
25-
const ArticleItemPrefixLabel: FC<TProps> = ({
26-
entry,
27-
accountInfo,
28-
topOffset = '22px',
29-
}) => {
23+
const ArticleItemPrefixLabel: FC<TProps> = ({ entry, topOffset = '22px' }) => {
3024
if (entry.pin) return <PinIcon top={topOffset} />
3125

32-
return (
33-
<ReadLabel entry={entry} accountInfo={accountInfo} topOffset={topOffset} />
34-
)
26+
return <ReadLabel entry={entry} topOffset={topOffset} />
3527
}
3628

3729
export default memo(ArticleItemPrefixLabel)

src/components/ArticlesFilter/DesktopView.tsx

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,66 @@
55
*/
66

77
import { FC, memo } from 'react'
8+
import dynamic from 'next/dynamic'
89

9-
import type { TThread, TAccount, TArticleFilter } from '@/spec'
10-
import { THREAD } from '@/constant'
10+
import type { TArticleFilter, TResState } from '@/spec'
11+
12+
import { TYPE } from '@/constant'
1113
import { buildLog } from '@/utils'
14+
import { useViewing } from '@/hooks'
1215

1316
import FilterButton from './FilterButton'
14-
import SelectedTags from './SelectedTags'
17+
import SelectedFilters from './SelectedFilters'
1518
import FilterResult from './FilterResult'
1619

1720
import { Wrapper, MainFilterWrapper } from './styles'
1821

1922
/* eslint-disable-next-line */
2023
const log = buildLog('c:ArticlesFilter:index')
2124

25+
const LavaLampLoading = dynamic(
26+
() => import('@/components/Loading/LavaLampLoading'),
27+
{
28+
/* eslint-disable react/display-name */
29+
loading: () => <div />,
30+
ssr: false,
31+
},
32+
)
33+
2234
type TProps = {
2335
activeFilter: TArticleFilter
2436
onSelect: (filter: TArticleFilter) => void
25-
thread: TThread
26-
accountInfo: TAccount
37+
pageNumber?: number
2738
totalCount?: number
39+
resState?: TResState
2840
}
2941

3042
const ArticlesFilter: FC<TProps> = ({
31-
thread = THREAD.POST,
3243
activeFilter = {},
3344
onSelect,
34-
accountInfo: { isLogin },
45+
pageNumber = 1,
3546
totalCount = 0,
36-
}) => (
37-
<Wrapper>
38-
<MainFilterWrapper>
39-
<FilterButton
40-
thread={thread}
41-
onSelect={onSelect}
42-
isLogin={isLogin}
43-
activeFilter={activeFilter}
44-
/>
45-
46-
<SelectedTags onSelect={onSelect} activeFilter={activeFilter} />
47-
</MainFilterWrapper>
48-
<FilterResult totalCount={totalCount} />
49-
</Wrapper>
50-
)
47+
resState = TYPE.RES_STATE.DONE,
48+
}) => {
49+
const { activeThread } = useViewing()
50+
51+
return (
52+
<Wrapper>
53+
<MainFilterWrapper>
54+
<FilterButton
55+
thread={activeThread}
56+
onSelect={onSelect}
57+
activeFilter={activeFilter}
58+
/>
59+
<SelectedFilters onSelect={onSelect} activeFilter={activeFilter} />
60+
</MainFilterWrapper>
61+
62+
{resState === TYPE.RES_STATE.LOADING && (
63+
<LavaLampLoading top={2} right={28} />
64+
)}
65+
<FilterResult pageNumber={pageNumber} totalCount={totalCount} />
66+
</Wrapper>
67+
)
68+
}
5169

5270
export default memo(ArticlesFilter)

src/components/ArticlesFilter/FilterButton.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import dynamic from 'next/dynamic'
33

44
import type { TThread, TArticleFilter } from '@/spec'
55
import { ICON_CMD } from '@/config'
6+
import { useAccount } from '@/hooks'
67

78
import Tooltip from '@/components/Tooltip'
89

@@ -21,17 +22,13 @@ const FilterPanel = dynamic(() => import('./FilterPanel/index'), {
2122

2223
type TProps = {
2324
thread: TThread
24-
isLogin: boolean
2525
activeFilter: TArticleFilter
2626
onSelect: (filter: TArticleFilter) => void
2727
}
2828

29-
const FilterButton: FC<TProps> = ({
30-
thread,
31-
onSelect,
32-
isLogin,
33-
activeFilter,
34-
}) => {
29+
const FilterButton: FC<TProps> = ({ thread, onSelect, activeFilter }) => {
30+
const { isLogin } = useAccount()
31+
3532
return (
3633
<Wrapper>
3734
<Tooltip

src/components/ArticlesFilter/FilterResult.tsx

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

3+
import DotDivider from '@/components/DotDivider'
4+
35
import { Wrapper, ResultText } from './styles/filter_result'
46

57
type TProps = {
68
totalCount: number
9+
pageNumber: number
710
}
811

9-
const FilterResult: FC<TProps> = ({ totalCount }) => {
12+
const FilterResult: FC<TProps> = ({ pageNumber, totalCount }) => {
1013
return (
1114
<Wrapper>
15+
<ResultText>{pageNumber}</ResultText>
16+
<DotDivider space={8} />
1217
<ResultText>{totalCount}</ResultText>
1318
</Wrapper>
1419
)

src/components/ArticlesFilter/SelectedTags.tsx renamed to src/components/ArticlesFilter/SelectedFilters.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { TArticleFilter } from '@/spec'
55
import { isEmptyValue } from '@/utils'
66

77
import Tag from '@/components/Tag'
8-
import { Wrapper, TagWrapper } from './styles/selected_tags'
8+
import { Wrapper, TagWrapper } from './styles/selected_filters'
99

1010
const filterDict = {
1111
TODAY: '今天',
@@ -51,7 +51,7 @@ type TProps = {
5151
activeFilter: TArticleFilter
5252
}
5353

54-
const SelectedTags: FC<TProps> = ({ activeFilter, onSelect }) => (
54+
const SelectedFilters: FC<TProps> = ({ activeFilter, onSelect }) => (
5555
<Wrapper>
5656
{keys(activeFilter).map((filterKey) => (
5757
<FilterTag
@@ -64,4 +64,4 @@ const SelectedTags: FC<TProps> = ({ activeFilter, onSelect }) => (
6464
</Wrapper>
6565
)
6666

67-
export default memo(SelectedTags)
67+
export default memo(SelectedFilters)

src/components/ArticlesFilter/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
*/
66

7-
import React from 'react'
7+
import { Fragment, memo } from 'react'
88

99
import { useDevice } from '@/hooks'
1010
import { buildLog } from '@/utils'
@@ -17,9 +17,7 @@ const log = buildLog('c:ArticlesFilter:index')
1717
const ArticlesFilter = (props) => {
1818
const { isMobile } = useDevice()
1919

20-
return (
21-
<React.Fragment>{!isMobile && <DesktopView {...props} />}</React.Fragment>
22-
)
20+
return <Fragment>{!isMobile && <DesktopView {...props} />}</Fragment>
2321
}
2422

25-
export default React.memo(ArticlesFilter)
23+
export default memo(ArticlesFilter)

src/components/ArticlesFilter/styles/filter_result.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ export const Wrapper = styled.div`
77
`
88
export const ResultText = styled.div`
99
color: ${theme('thread.filterResultHint')};
10-
margin-right: 3px;
1110
`

0 commit comments

Comments
 (0)