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

Commit e0c62f0

Browse files
authored
chore(user): cover user & tabs to ts (#1086)
* chore(user): cover user & tabs to ts * fix(server-schame): pin -> isPinned change
1 parent 78edd2b commit e0c62f0

Some content is hidden

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

44 files changed

+481
-504
lines changed

src/components/ArticleItemPrefixLabel/ReadLabel.js renamed to src/components/ArticleItemPrefixLabel/ReadLabel.tsx

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

33
import { ReadedLabel } from './styles'
44

5-
const ReadLabel = ({ entry, accountInfo, topOffset }) => {
5+
import type { TProps } from './index'
6+
7+
const ReadLabel: FC<TProps> = ({ entry, accountInfo, topOffset = '20px' }) => {
68
const { viewerHasViewed } = entry
79
const {
810
isLogin,

src/components/ArticleItemPrefixLabel/index.js

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
*
3+
* ArticleItemPrefixLabel
4+
*
5+
*/
6+
7+
import React, { FC } from 'react'
8+
9+
import type { TAccount } from '@/spec'
10+
import { buildLog } from '@/utils'
11+
import { PinIcon } from './styles'
12+
import ReadLabel from './ReadLabel'
13+
14+
/* eslint-disable-next-line */
15+
const log = buildLog('c:ArticleItemPrefixLabel:index')
16+
17+
export type TProps = {
18+
accountInfo: TAccount
19+
topOffset?: string
20+
entry: {
21+
viewerHasViewed?: boolean
22+
isPinned?: boolean
23+
}
24+
}
25+
const ArticleItemPrefixLabel: FC<TProps> = ({
26+
entry,
27+
accountInfo,
28+
topOffset = '22px',
29+
}) => {
30+
if (entry.isPinned) return <PinIcon top={topOffset} />
31+
32+
return (
33+
<ReadLabel entry={entry} accountInfo={accountInfo} topOffset={topOffset} />
34+
)
35+
}
36+
37+
export default React.memo(ArticleItemPrefixLabel)

src/components/Switcher/Tabs/CardView.js renamed to src/components/Switcher/Tabs/CardView.tsx

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

7-
import React, { useRef, useState, useCallback } from 'react'
8-
import T from 'prop-types'
7+
import React, { FC, useRef, useState, useCallback } from 'react'
98

9+
import type { TSIZE_SM, TTabItem } from '@/spec'
1010
import { buildLog, isString } from '@/utils'
1111
import { SIZE } from '@/constant'
1212

@@ -20,12 +20,25 @@ const log = buildLog('c:Tabs:index')
2020
const temItems = [
2121
{
2222
title: '帖子',
23-
// icon: `${ICON_CMD}/navi/fire.svg`,
23+
raw: 'posts',
2424
localIcon: 'settings',
2525
},
2626
]
2727

28-
const Tabs = ({ size, onChange, items, activeKey }) => {
28+
type TProps = {
29+
items?: TTabItem[]
30+
onChange: () => void
31+
activeKey?: string
32+
size: TSIZE_SM
33+
slipHeight: '1px' | '2px'
34+
}
35+
36+
const Tabs: FC<TProps> = ({
37+
size = SIZE.MEDIUM,
38+
onChange = log,
39+
items = temItems,
40+
activeKey = '',
41+
}) => {
2942
const [tabWidthList, setTabWidthList] = useState([])
3043

3144
const navRef = useRef(null)
@@ -69,29 +82,4 @@ const Tabs = ({ size, onChange, items, activeKey }) => {
6982
)
7083
}
7184

72-
Tabs.propTypes = {
73-
items: T.oneOfType([
74-
T.arrayOf(T.string),
75-
T.arrayOf(
76-
T.shape({
77-
title: T.string,
78-
raw: T.string,
79-
alias: T.string,
80-
icon: T.oneOfType([T.string, T.node]),
81-
localIcon: T.string,
82-
}),
83-
),
84-
]),
85-
onChange: T.func,
86-
activeKey: T.string,
87-
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
88-
}
89-
90-
Tabs.defaultProps = {
91-
items: temItems,
92-
onChange: log,
93-
activeKey: '',
94-
size: SIZE.MEDIUM,
95-
}
96-
9785
export default React.memo(Tabs)

src/components/Switcher/Tabs/DesktopView.js renamed to src/components/Switcher/Tabs/DesktopView.tsx

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*
55
*/
66

7-
import React, { useEffect, useRef, useState, useCallback } from 'react'
8-
import T from 'prop-types'
7+
import React, { FC, useEffect, useRef, useState, useCallback } from 'react'
98
import { isEmpty, findIndex } from 'ramda'
109

10+
import type { TSIZE_SM, TTabItem } from '@/spec'
1111
import { useDevice } from '@/hooks'
1212
import { SIZE } from '@/constant'
1313
import { buildLog, isString } from '@/utils'
@@ -23,6 +23,7 @@ const log = buildLog('c:Tabs:index')
2323
const temItems = [
2424
{
2525
title: '帖子',
26+
raw: 'posts',
2627
// icon: `${ICON_CMD}/navi/fire.svg`,
2728
localIcon: 'settings',
2829
},
@@ -36,18 +37,33 @@ const temItems = [
3637
* @param {string} activeKey
3738
* @returns number
3839
*/
39-
const getDefaultActiveTabIndex = (items, activeKey) => {
40+
const getDefaultActiveTabIndex = (
41+
items: TTabItem[],
42+
activeKey: string,
43+
): number => {
4044
if (isEmpty(activeKey)) return 0
4145
const index = findIndex((item) => {
42-
return isString(item)
43-
? activeKey === item
44-
: activeKey === (item.raw || item.title)
46+
return activeKey === (item.raw || item.title)
4547
}, items)
4648

4749
return index >= 0 ? index : 0
4850
}
4951

50-
const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => {
52+
type TProps = {
53+
items?: TTabItem[]
54+
onChange: () => void
55+
activeKey?: string
56+
size: TSIZE_SM
57+
slipHeight: '1px' | '2px'
58+
}
59+
60+
const Tabs: FC<TProps> = ({
61+
size = SIZE.MEDIUM,
62+
onChange = log,
63+
items = temItems,
64+
activeKey = '',
65+
slipHeight = '2px',
66+
}) => {
5167
const { isMobile } = useDevice()
5268

5369
const defaultActiveTabIndex = getDefaultActiveTabIndex(items, activeKey)
@@ -118,39 +134,12 @@ const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => {
118134
slipHeight={slipHeight}
119135
>
120136
<RealBar
121-
width={`${size === 'default' ? slipWidth : slipWidth - 6}px`}
137+
width={`${size === SIZE.MEDIUM ? slipWidth : slipWidth - 6}px`}
122138
/>
123139
</SlipBar>
124140
</Nav>
125141
</Wrapper>
126142
)
127143
}
128144

129-
Tabs.propTypes = {
130-
items: T.oneOfType([
131-
T.arrayOf(T.string),
132-
T.arrayOf(
133-
T.shape({
134-
title: T.string,
135-
raw: T.string,
136-
alias: T.string,
137-
icon: T.oneOfType([T.string, T.node]),
138-
localIcon: T.string,
139-
}),
140-
),
141-
]),
142-
onChange: T.func,
143-
activeKey: T.string,
144-
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
145-
slipHeight: T.oneOf(['1px', '2px']),
146-
}
147-
148-
Tabs.defaultProps = {
149-
items: temItems,
150-
onChange: log,
151-
activeKey: '',
152-
size: SIZE.MEDIUM,
153-
slipHeight: '2px',
154-
}
155-
156145
export default React.memo(Tabs)

src/components/Switcher/Tabs/DrawerView.js renamed to src/components/Switcher/Tabs/DrawerView.tsx

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

7-
import React, { useCallback } from 'react'
8-
import T from 'prop-types'
7+
import React, { FC, useCallback } from 'react'
98

9+
import type { TSIZE_SM, TTabItem } from '@/spec'
1010
import { buildLog, isString } from '@/utils'
1111
import { SIZE } from '@/constant'
1212

@@ -23,7 +23,20 @@ const temItems = [
2323
},
2424
]
2525

26-
const Tabs = ({ size, onChange, items, activeKey }) => {
26+
type TProps = {
27+
items?: TTabItem[]
28+
onChange: () => void
29+
activeKey?: string
30+
size: TSIZE_SM
31+
slipHeight: '1px' | '2px'
32+
}
33+
34+
const Tabs: FC<TProps> = ({
35+
size = SIZE.MEDIUM,
36+
onChange = log,
37+
items = temItems,
38+
activeKey = '',
39+
}) => {
2740
const handleItemClick = useCallback(
2841
(item) => {
2942
onChange(isString(item) ? item : item.raw || item.title)
@@ -37,7 +50,6 @@ const Tabs = ({ size, onChange, items, activeKey }) => {
3750
<TabItem
3851
key={isString(item) ? item : item.raw || item.title}
3952
active={activeKey === item.raw}
40-
size={size}
4153
onClick={() => handleItemClick(item)}
4254
>
4355
{item.title}
@@ -47,29 +59,4 @@ const Tabs = ({ size, onChange, items, activeKey }) => {
4759
)
4860
}
4961

50-
Tabs.propTypes = {
51-
items: T.oneOfType([
52-
T.arrayOf(T.string),
53-
T.arrayOf(
54-
T.shape({
55-
title: T.string,
56-
raw: T.string,
57-
alias: T.string,
58-
icon: T.oneOfType([T.string, T.node]),
59-
localIcon: T.string,
60-
}),
61-
),
62-
]),
63-
onChange: T.func,
64-
activeKey: T.string,
65-
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
66-
}
67-
68-
Tabs.defaultProps = {
69-
items: temItems,
70-
onChange: log,
71-
activeKey: '',
72-
size: SIZE.MEDIUM,
73-
}
74-
7562
export default React.memo(Tabs)

src/components/Switcher/Tabs/LocalIcon.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import {
1919
TabFavoritesIcon,
2020
} from '../styles/tabs/local_icon'
2121

22+
// type TProps = {
23+
// raw: string
24+
// active: boolean
25+
// small?: boolean
26+
// }
27+
2228
const TabIcon = ({ raw, active, small }) => {
2329
switch (raw) {
2430
case 'tech':

0 commit comments

Comments
 (0)