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

Commit 559301c

Browse files
authored
refactor: tending page demo (#1194)
* refactor(trending): adjust style & re-org * refactor(trending): add notice bar
1 parent ebe8f72 commit 559301c

File tree

20 files changed

+295
-328
lines changed

20 files changed

+295
-328
lines changed

src/containers/content/TrendingContent/Footer/index.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/containers/content/TrendingContent/NewsBoard.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { FC, memo } from 'react'
2+
3+
import CustomScroller from '@/widgets/CustomScroller'
4+
import FeedsBar from '@/widgets/FeedsBar'
5+
import NoticeBar from '@/widgets/NoticeBar'
6+
7+
import { Wrapper, ShadowBarHolder } from './styles/news_board'
8+
9+
const NewsBoard: FC = () => {
10+
return (
11+
<Wrapper>
12+
<CustomScroller
13+
direction="horizontal"
14+
height="90vh"
15+
innerHeight="90vh"
16+
shadowSize="large"
17+
barSize="medium"
18+
withBorder
19+
>
20+
<FeedsBar title="国外科技动态" />
21+
<FeedsBar title="国内科技动态" />
22+
<FeedsBar title="Github Trending" />
23+
<FeedsBar title="象牙塔" />
24+
<FeedsBar title="播客" />
25+
<FeedsBar title="奇奇怪怪" />
26+
<ShadowBarHolder />
27+
</CustomScroller>
28+
29+
<NoticeBar
30+
type="info"
31+
content="UI 部分 inspired by TwitterDeck,当前内容仅为展示。自动化采集分类系统仍在开发调试中,欢迎任何形式的参与。"
32+
top={15}
33+
right={10}
34+
noBg
35+
/>
36+
</Wrapper>
37+
)
38+
}
39+
40+
export default memo(NewsBoard)

src/containers/content/TrendingContent/index.js renamed to src/containers/content/TrendingContent/index.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,33 @@
44
*
55
*/
66

7-
import React from 'react'
7+
import { FC } from 'react'
8+
9+
import type { TMetric } from '@/spec'
10+
import { METRIC } from '@/constant'
811

912
import { buildLog } from '@/utils/logger'
1013
import { pluggedIn } from '@/utils/mobx'
1114

1215
import OrButton from '@/widgets/Buttons/OrButton'
1316
import NewsBoard from './NewsBoard'
1417

18+
import type { TStore } from './store'
1519
import { Wrapper, InnerWrapper, SwitchBtn, ContentWrapper } from './styles'
1620
import { useInit } from './logic'
1721

1822
/* eslint-disable-next-line */
1923
const log = buildLog('C:TrendingContent')
2024

21-
const TrendingContentContainer = ({ trendingContent: store, metric }) => {
25+
type TProps = {
26+
trendingContent?: TStore
27+
metric?: TMetric
28+
}
29+
30+
const TrendingContentContainer: FC<TProps> = ({
31+
trendingContent: store,
32+
metric = METRIC.TRENDING,
33+
}) => {
2234
useInit(store)
2335

2436
return (
@@ -27,17 +39,16 @@ const TrendingContentContainer = ({ trendingContent: store, metric }) => {
2739
<SwitchBtn>
2840
<OrButton
2941
direction="column"
30-
type="primary"
31-
activeKey="inside"
42+
activeKey="outside"
3243
group={[
33-
{
34-
key: 'inside',
35-
title: '站内',
36-
},
3744
{
3845
key: 'outside',
3946
title: '站外',
4047
},
48+
{
49+
key: 'inside',
50+
title: '站内',
51+
},
4152
]}
4253
/>
4354
</SwitchBtn>
@@ -49,4 +60,4 @@ const TrendingContentContainer = ({ trendingContent: store, metric }) => {
4960
)
5061
}
5162

52-
export default pluggedIn(TrendingContentContainer)
63+
export default pluggedIn(TrendingContentContainer) as FC<TProps>

src/containers/content/TrendingContent/logic.js renamed to src/containers/content/TrendingContent/logic.ts

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

33
import { buildLog } from '@/utils/logger'
4+
5+
import type { TStore } from './store'
46
// import S from './service'
57

68
let store = null
@@ -16,7 +18,7 @@ export const someMethod = () => {
1618
// init & uninit handlers
1719
// ###############################
1820

19-
export const useInit = (_store) => {
21+
export const useInit = (_store: TStore): void => {
2022
useEffect(() => {
2123
store = _store
2224
log('useInit: ', store)

src/containers/content/TrendingContent/store.js renamed to src/containers/content/TrendingContent/store.tsx

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

6-
import { types as T, getParent } from 'mobx-state-tree'
6+
import { types as T, Instance } from 'mobx-state-tree'
77

88
import { markStates } from '@/utils/mobx'
99

1010
const TrendingContent = T.model('TrendingContent', {})
1111
.views((self) => ({
12-
get root() {
13-
return getParent(self)
14-
},
12+
// get root() {
13+
// return getParent(self)
14+
// },
1515
}))
1616
.actions((self) => ({
1717
mark(sobj) {
1818
markStates(sobj, self)
1919
},
2020
}))
2121

22+
export type TStore = Instance<typeof TrendingContent>
2223
export default TrendingContent

src/containers/content/TrendingContent/styles/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import styled from 'styled-components'
22

33
// import Img from '@/Img'
4-
import type { TMetric } from '@/spec'
4+
import type { TTestable, TMetric } from '@/spec'
55
import css from '@/utils/css'
66

7-
export const Wrapper = styled.div`
7+
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
8+
'data-test-id': testid,
9+
}))<TTestable>`
810
${css.flexColumn('align-both')}
911
width: 100%;
1012
`
13+
1114
export const InnerWrapper = styled.div<{ metric: TMetric }>`
1215
${css.flex()};
1316
padding: 10px 0;
1417
margin-top: 12px;
1518
width: 100%;
1619
${({ metric }) => css.fitContentWidth(metric)};
17-
margin-left: -80px;
20+
margin-left: -85px;
1821
`
1922
export const SwitchBtn = styled.div`
2023
margin-right: 15px;

src/pages/trending.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
1+
import { GetServerSideProps } from 'next'
12
import { Provider } from 'mobx-react'
23

34
import { METRIC } from '@/constant'
45
import { P } from '@/schemas'
56

6-
import { ssrBaseStates, ssrFetchPrepare, ssrRescue, trendingSEO } from '@/utils'
7+
import {
8+
ssrBaseStates,
9+
ssrFetchPrepare,
10+
refreshIfneed,
11+
trendingSEO,
12+
ssrError,
13+
} from '@/utils'
714
import GlobalLayout from '@/containers/layout/GlobalLayout'
815
import TrendingContent from '@/containers/content/TrendingContent'
916

1017
import { useStore } from '@/stores/init'
1118

1219
const fetchData = async (context, opt = {}) => {
1320
const { gqClient } = ssrFetchPrepare(context, opt)
14-
1521
const sessionState = gqClient.request(P.sessionState)
16-
const subscribedCommunities = gqClient.request(P.subscribedCommunities, {
17-
filter: {
18-
page: 1,
19-
size: 30,
20-
},
21-
})
2222

2323
return {
2424
...(await sessionState),
25-
...(await subscribedCommunities),
2625
}
2726
}
2827

29-
export const getServerSideProps = async (context) => {
28+
export const getServerSideProps: GetServerSideProps = async (context) => {
3029
let resp
3130
try {
3231
resp = await fetchData(context)
33-
} catch ({ response: { errors } }) {
34-
if (ssrRescue.hasLoginError(errors)) {
35-
resp = await fetchData(context, { tokenExpired: true })
36-
}
37-
}
32+
const { sessionState } = resp
3833

39-
const initProps = { ...ssrBaseStates(resp) }
34+
refreshIfneed(sessionState, '/trending', context)
35+
} catch (e) {
36+
console.log('#### error from server: ', e)
37+
return ssrError(context, 'fetch', 500)
38+
}
4039

41-
return {
42-
props: { errorCode: null, namespacesRequired: ['general'], ...initProps },
40+
const initProps = {
41+
...ssrBaseStates(resp),
4342
}
43+
44+
return { props: { errorCode: null, ...initProps } }
4445
}
4546

4647
const TrendingPage = (props) => {

src/widgets/Buttons/OrButton/HorizontalButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type TProps = Omit<TButtonProps, 'direction'>
1414

1515
const HorizontalButton: FC<TProps> = ({
16-
onClick,
16+
onClick = console.log,
1717
size = SIZE.SMALL,
1818
activeKey,
1919
group = [

src/widgets/Buttons/OrButton/VerticalButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type TProps = Omit<TButtonProps, 'direction'>
1414

1515
const VerticalButton: FC<TProps> = ({
16-
onClick,
16+
onClick = console.log,
1717
size = SIZE.SMALL,
1818
activeKey,
1919
group = [

0 commit comments

Comments
 (0)