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

Commit f58470c

Browse files
authored
chore(js-ts): Header unit (#1051)
1 parent 92373a7 commit f58470c

File tree

11 files changed

+98
-78
lines changed

11 files changed

+98
-78
lines changed
File renamed without changes.

src/containers/unit/Header/DesktopView/ArticleEditorView.js renamed to src/containers/unit/Header/DesktopView/ArticleEditorView.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
import React, { useEffect } from 'react'
88
import dynamic from 'next/dynamic'
9-
import T from 'prop-types'
109

1110
import { ICON } from '@/config'
1211
import { METRIC } from '@/constant'
1312
import { pluggedIn, buildLog } from '@/utils'
1413

1514
import Navigator from '@/components/Navigator'
1615

16+
import type { TStore } from '../store'
1717
import {
1818
Wrapper,
1919
InnerWrapper,
@@ -29,19 +29,15 @@ const log = buildLog('C:Header')
2929

3030
let MailBox
3131

32-
const HeaderContainer = ({ header: store }) => {
33-
useInit(store)
32+
type TProps = {
33+
header?: TStore
34+
metric?: string
35+
}
36+
37+
const ArticleEditorHeader: React.FC<TProps> = ({ header: store, metric }) => {
38+
useInit(store, metric)
3439

35-
const {
36-
isOnline,
37-
leftOffset,
38-
accountInfo,
39-
isLogin,
40-
curCommunity,
41-
accountInfo: {
42-
customization: { bannerLayout },
43-
},
44-
} = store
40+
const { isOnline, leftOffset, accountInfo, isLogin, curCommunity } = store
4541

4642
useEffect(() => {
4743
if (isLogin) {
@@ -60,7 +56,7 @@ const HeaderContainer = ({ header: store }) => {
6056
leftOffset={leftOffset}
6157
noBorder
6258
>
63-
<InnerWrapper layout={bannerLayout} metric={METRIC.ARTICLE_EDITOR}>
59+
<InnerWrapper>
6460
<RouterWrapper>
6561
<Navigator
6662
curCommunity={curCommunity}
@@ -78,10 +74,4 @@ const HeaderContainer = ({ header: store }) => {
7874
)
7975
}
8076

81-
HeaderContainer.propTypes = {
82-
header: T.any.isRequired,
83-
}
84-
85-
HeaderContainer.defaultProps = {}
86-
87-
export default pluggedIn(HeaderContainer)
77+
export default pluggedIn(ArticleEditorHeader, 'header') as React.FC<TProps>

src/containers/unit/Header/DesktopView/ArticleView.js renamed to src/containers/unit/Header/DesktopView/ArticleView.tsx

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

77
import React, { useEffect } from 'react'
88
import dynamic from 'next/dynamic'
9-
import T from 'prop-types'
109

1110
import { ICON } from '@/config'
1211
import { pluggedIn, buildLog } from '@/utils'
1312

1413
import UserLister from '@/containers/user/UserLister'
1514
import Navigator from '@/components/Navigator'
1615

16+
import type { TStore } from '../store'
1717
// import UserAccount from '../UserAccount'
1818
import {
1919
Wrapper,
@@ -30,13 +30,20 @@ const log = buildLog('C:Header')
3030

3131
let MailBox
3232

33-
const HeaderContainer = ({ header: store }) => {
34-
useInit(store)
33+
type TProps = {
34+
header?: TStore
35+
metric?: string
36+
}
37+
38+
const ArticleHeaderContainer: React.FC<TProps> = ({
39+
header: store,
40+
metric,
41+
}) => {
42+
useInit(store, metric)
3543

3644
const {
3745
isOnline,
3846
leftOffset,
39-
accountInfo,
4047
isLogin,
4148
curCommunity,
4249
accountInfo: {
@@ -61,11 +68,11 @@ const HeaderContainer = ({ header: store }) => {
6168
leftOffset={leftOffset}
6269
noBorder
6370
>
64-
<InnerWrapper layout={bannerLayout}>
71+
<InnerWrapper>
6572
<RouterWrapper>
6673
<Navigator
6774
curCommunity={curCommunity}
68-
layout={accountInfo.customization.bannerLayout}
75+
layout={bannerLayout}
6976
isOnline={isOnline}
7077
// showLogoText
7178
/>
@@ -76,18 +83,11 @@ const HeaderContainer = ({ header: store }) => {
7683
{/* <Cashier /> */}
7784
<UserInfoWrapper>
7885
<MoreIcon src={`${ICON}/shape/more-box.svg`} />
79-
{/* <UserAccount isLogin={isLogin} accountInfo={accountInfo} /> */}
8086
</UserInfoWrapper>
8187
</Operations>
8288
</InnerWrapper>
8389
</Wrapper>
8490
)
8591
}
8692

87-
HeaderContainer.propTypes = {
88-
header: T.any.isRequired,
89-
}
90-
91-
HeaderContainer.defaultProps = {}
92-
93-
export default pluggedIn(HeaderContainer)
93+
export default pluggedIn(ArticleHeaderContainer, 'header') as React.FC<TProps>

src/containers/unit/Header/DesktopView/CommunityVIew.js renamed to src/containers/unit/Header/DesktopView/CommunityVIew.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66

77
import React, { useEffect } from 'react'
88
import dynamic from 'next/dynamic'
9-
import T from 'prop-types'
10-
import { values } from 'ramda'
119

1210
import { METRIC } from '@/constant'
1311
import { pluggedIn, buildLog } from '@/utils'
1412

1513
import UserLister from '@/containers/user/UserLister'
1614
import Navigator from '@/components/Navigator'
1715

16+
import type { TStore } from '../store'
1817
import UserAccount from '../UserAccount'
1918
import AddOns from '../AddOns'
2019

@@ -33,7 +32,16 @@ const log = buildLog('C:Header')
3332

3433
let MailBox
3534

36-
const HeaderContainer = ({ header: store, metric }) => {
35+
type TProps = {
36+
// T.oneOf(values(METRIC)) TODO
37+
metric?: string
38+
header?: TStore
39+
}
40+
41+
const CommunityHeaderContainer: React.FC<TProps> = ({
42+
header: store,
43+
metric = METRIC.COMMUNITY,
44+
}) => {
3745
log('header metric: ', metric)
3846
useInit(store, metric)
3947

@@ -66,11 +74,11 @@ const HeaderContainer = ({ header: store, metric }) => {
6674
leftOffset={leftOffset}
6775
noBorder={hasNoBottomBorder}
6876
>
69-
<InnerWrapper metric={metric} layout={bannerLayout}>
77+
<InnerWrapper metric={metric}>
7078
<RouterWrapper>
7179
<Navigator
7280
curCommunity={curCommunity}
73-
layout={accountInfo.customization.bannerLayout}
81+
layout={bannerLayout}
7482
isOnline={isOnline}
7583
metric={metric}
7684
/>
@@ -91,13 +99,4 @@ const HeaderContainer = ({ header: store, metric }) => {
9199
)
92100
}
93101

94-
HeaderContainer.propTypes = {
95-
metric: T.oneOf(values(METRIC)),
96-
header: T.any.isRequired,
97-
}
98-
99-
HeaderContainer.defaultProps = {
100-
metric: METRIC.COMMUNITY,
101-
}
102-
103-
export default pluggedIn(HeaderContainer)
102+
export default pluggedIn(CommunityHeaderContainer, 'header') as React.FC<TProps>

src/containers/unit/Header/DesktopView/index.js renamed to src/containers/unit/Header/DesktopView/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@ import CommunityView from './CommunityVIew'
66
import ArticleView from './ArticleView'
77
import ArticleEditorView from './ArticleEditorView'
88

9-
const renderHeader = (metric) => {
9+
const renderHeader = (metric: string): React.ReactNode => {
1010
switch (metric) {
1111
case METRIC.ARTICLE: {
12-
return <ArticleView />
12+
return <ArticleView metric={metric} />
1313
}
1414
case METRIC.ARTICLE_EDITOR: {
15-
return <ArticleEditorView />
15+
return <ArticleEditorView metric={metric} />
1616
}
1717
default: {
1818
return <CommunityView metric={metric} />
1919
}
2020
}
2121
}
2222

23-
const DesktopView = ({ metric }) => {
23+
type TProps = {
24+
metric: string
25+
}
26+
27+
const DesktopView: React.FC<TProps> = ({ metric }) => {
2428
return <React.Fragment>{renderHeader(metric)}</React.Fragment>
2529
}
2630

src/containers/unit/Header/ThreadsNav.js renamed to src/containers/unit/Header/ThreadsNav.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react'
22

3+
import type { TCommunity, TThread } from '@/spec'
34
import { Trans } from '@/utils'
4-
import { SIZE } from '@/constant'
5+
// import { SIZE } from '@/constant'
56

6-
import { Tabs } from '@/components/Switcher'
7+
// import { Tabs } from '@/components/Switcher'
78
import DotDivider from '@/components/DotDivider'
89

910
import {
@@ -13,9 +14,18 @@ import {
1314
MiniTab,
1415
} from './styles/threads_nav'
1516

16-
import { onThreadChange } from './logic'
17+
// import { onThreadChange } from './logic'
1718

18-
const ThreadsNav = ({ activeInfo: { community, activeThread } }) => {
19+
type TProps = {
20+
activeInfo: {
21+
community: TCommunity
22+
activeThread: TThread
23+
}
24+
}
25+
26+
const ThreadsNav: React.FC<TProps> = ({
27+
activeInfo: { community, activeThread },
28+
}) => {
1929
return (
2030
<Wrapper>
2131
<CommunityLogo src={community.logo || ''} raw={community.raw} />
@@ -24,12 +34,13 @@ const ThreadsNav = ({ activeInfo: { community, activeThread } }) => {
2434
{Trans(activeThread)}
2535
</MobileHint>
2636
<MiniTab>
27-
<Tabs
28-
items={community.threads}
37+
todo
38+
{/* <Tabs
2939
size={SIZE.SMALL}
40+
items={community.threads}
3041
onChange={onThreadChange}
3142
activeKey={activeThread}
32-
/>
43+
/> */}
3344
</MiniTab>
3445
</Wrapper>
3546
)

src/containers/unit/Header/UserAccount.js renamed to src/containers/unit/Header/UserAccount.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import { useRouter } from 'next/router'
33

4+
import type { TAccount } from '@/spec'
45
import { ICON } from '@/config'
56
import { ROUTE } from '@/constant'
67
import Tooltip from '@/components/Tooltip'
@@ -23,7 +24,12 @@ import {
2324
MembershipHint,
2425
} from './styles/user_account'
2526

26-
const UserAccount = ({ isLogin, accountInfo }) => {
27+
type TProps = {
28+
isLogin: boolean
29+
accountInfo: TAccount
30+
}
31+
32+
const UserAccount: React.FC<TProps> = ({ isLogin, accountInfo }) => {
2733
const router = useRouter()
2834

2935
return (
@@ -40,9 +46,7 @@ const UserAccount = ({ isLogin, accountInfo }) => {
4046
<LoginName>{accountInfo.login}</LoginName>
4147
</LoginBadge>
4248
<MenuDivider />
43-
<MenuItem onClick={() => previewAccount('account')}>
44-
主页面板
45-
</MenuItem>
49+
<MenuItem onClick={() => previewAccount()}>主页面板</MenuItem>
4650
<MenuLink
4751
href={`/user/${accountInfo.login}`}
4852
rel="noopener noreferrer"
@@ -87,7 +91,7 @@ const UserAccount = ({ isLogin, accountInfo }) => {
8791
</Wrapper>
8892
)}
8993

90-
<MembershipHint href={ROUTE.MEMBERSHIP}>
94+
<MembershipHint>
9195
{/* 升&nbsp;级- */}
9296
<Button
9397
size="tiny"

src/containers/unit/Header/index.js renamed to src/containers/unit/Header/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const HeaderContainer = ({ metric }) => {
1717
const { isMobile } = useDevice()
1818

1919
return (
20-
<Wrapper id={ANCHOR.GLOBAL_HEADER_ID}>
20+
<Wrapper id={ANCHOR.GLOBAL_HEADER_ID} testid="">
2121
{!isMobile ? <DesktopView metric={metric} /> : <MobileWrapper />}
2222
</Wrapper>
2323
)

0 commit comments

Comments
 (0)