From 57bd6b60bb98947db30d922340206ace0f91ff27 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 1 May 2021 11:40:39 +0800 Subject: [PATCH 1/2] chore(user): cover user & tabs to ts --- .../Tabs/{CardView.js => CardView.tsx} | 46 +++++------- .../Tabs/{DesktopView.js => DesktopView.tsx} | 59 +++++++-------- .../Tabs/{DrawerView.js => DrawerView.tsx} | 45 +++++------- src/components/Switcher/Tabs/LocalIcon.js | 6 ++ .../{ExpandView.js => ExpandView.tsx} | 48 +++++-------- .../{NormalView.js => NormalView.tsx} | 72 +++++++++---------- .../Tabs/MobileView/{index.js => index.tsx} | 0 .../{ModelineView.js => ModelineView.tsx} | 65 ++++++++--------- src/components/Switcher/Tabs/TabIcon.js | 36 ---------- src/components/Switcher/Tabs/TabIcon.tsx | 37 ++++++++++ .../Switcher/Tabs/{TabItem.js => TabItem.tsx} | 50 ++++++------- .../Switcher/Tabs/{index.js => index.tsx} | 8 --- src/components/Switcher/styles/tabs/index.ts | 2 +- .../Switcher/styles/tabs/local_icon.ts | 13 ++-- .../{BriefView.js => BriefView.tsx} | 13 +++- .../{NormalView.js => NormalView.tsx} | 0 src/components/TabBar/DesktopView/index.js | 70 ------------------ src/components/TabBar/DesktopView/index.tsx | 56 +++++++++++++++ .../TabBar/{MobileView.js => MobileView.tsx} | 0 src/components/TabBar/{alias.js => alias.tsx} | 7 +- src/components/TabBar/{index.js => index.tsx} | 9 --- src/components/TabBar/spec.ts | 9 +++ ...yEditorInfo.js => CommunityEditorInfo.tsx} | 9 ++- .../Sidebar/{index.js => index.tsx} | 10 ++- .../UserContent/{index.js => index.tsx} | 10 ++- .../UserContent/{logic.js => logic.ts} | 19 ++--- src/containers/content/UserContent/store.js | 54 -------------- src/containers/content/UserContent/store.ts | 60 ++++++++++++++++ src/containers/unit/Footer/styles/index.ts | 2 +- src/spec/account.ts | 4 ++ src/spec/community.ts | 24 +++++++ src/spec/index.ts | 29 ++------ src/spec/utils.ts | 12 ++++ utils/helper.ts | 2 +- 34 files changed, 433 insertions(+), 453 deletions(-) rename src/components/Switcher/Tabs/{CardView.js => CardView.tsx} (69%) rename src/components/Switcher/Tabs/{DesktopView.js => DesktopView.tsx} (76%) rename src/components/Switcher/Tabs/{DrawerView.js => DrawerView.tsx} (58%) rename src/components/Switcher/Tabs/MobileView/{ExpandView.js => ExpandView.tsx} (72%) rename src/components/Switcher/Tabs/MobileView/{NormalView.js => NormalView.tsx} (79%) rename src/components/Switcher/Tabs/MobileView/{index.js => index.tsx} (100%) rename src/components/Switcher/Tabs/{ModelineView.js => ModelineView.tsx} (77%) delete mode 100644 src/components/Switcher/Tabs/TabIcon.js create mode 100644 src/components/Switcher/Tabs/TabIcon.tsx rename src/components/Switcher/Tabs/{TabItem.js => TabItem.tsx} (78%) rename src/components/Switcher/Tabs/{index.js => index.tsx} (88%) rename src/components/TabBar/DesktopView/{BriefView.js => BriefView.tsx} (69%) rename src/components/TabBar/DesktopView/{NormalView.js => NormalView.tsx} (100%) delete mode 100644 src/components/TabBar/DesktopView/index.js create mode 100644 src/components/TabBar/DesktopView/index.tsx rename src/components/TabBar/{MobileView.js => MobileView.tsx} (100%) rename src/components/TabBar/{alias.js => alias.tsx} (83%) rename src/components/TabBar/{index.js => index.tsx} (82%) create mode 100644 src/components/TabBar/spec.ts rename src/containers/content/UserContent/Sidebar/{CommunityEditorInfo.js => CommunityEditorInfo.tsx} (78%) rename src/containers/content/UserContent/Sidebar/{index.js => index.tsx} (56%) rename src/containers/content/UserContent/{index.js => index.tsx} (93%) rename src/containers/content/UserContent/{logic.js => logic.ts} (83%) delete mode 100755 src/containers/content/UserContent/store.js create mode 100755 src/containers/content/UserContent/store.ts create mode 100644 src/spec/community.ts diff --git a/src/components/Switcher/Tabs/CardView.js b/src/components/Switcher/Tabs/CardView.tsx similarity index 69% rename from src/components/Switcher/Tabs/CardView.js rename to src/components/Switcher/Tabs/CardView.tsx index 817221e3e..713e69e9b 100644 --- a/src/components/Switcher/Tabs/CardView.js +++ b/src/components/Switcher/Tabs/CardView.tsx @@ -4,9 +4,9 @@ * */ -import React, { useRef, useState, useCallback } from 'react' -import T from 'prop-types' +import React, { FC, useRef, useState, useCallback } from 'react' +import type { TSIZE_SM, TTabItem } from '@/spec' import { buildLog, isString } from '@/utils' import { SIZE } from '@/constant' @@ -20,12 +20,25 @@ const log = buildLog('c:Tabs:index') const temItems = [ { title: '帖子', - // icon: `${ICON_CMD}/navi/fire.svg`, + raw: 'posts', localIcon: 'settings', }, ] -const Tabs = ({ size, onChange, items, activeKey }) => { +type TProps = { + items?: TTabItem[] + onChange: () => void + activeKey?: string + size: TSIZE_SM + slipHeight: '1px' | '2px' +} + +const Tabs: FC = ({ + size = SIZE.MEDIUM, + onChange = log, + items = temItems, + activeKey = '', +}) => { const [tabWidthList, setTabWidthList] = useState([]) const navRef = useRef(null) @@ -69,29 +82,4 @@ const Tabs = ({ size, onChange, items, activeKey }) => { ) } -Tabs.propTypes = { - items: T.oneOfType([ - T.arrayOf(T.string), - T.arrayOf( - T.shape({ - title: T.string, - raw: T.string, - alias: T.string, - icon: T.oneOfType([T.string, T.node]), - localIcon: T.string, - }), - ), - ]), - onChange: T.func, - activeKey: T.string, - size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]), -} - -Tabs.defaultProps = { - items: temItems, - onChange: log, - activeKey: '', - size: SIZE.MEDIUM, -} - export default React.memo(Tabs) diff --git a/src/components/Switcher/Tabs/DesktopView.js b/src/components/Switcher/Tabs/DesktopView.tsx similarity index 76% rename from src/components/Switcher/Tabs/DesktopView.js rename to src/components/Switcher/Tabs/DesktopView.tsx index aa592aaa3..49bba8f05 100644 --- a/src/components/Switcher/Tabs/DesktopView.js +++ b/src/components/Switcher/Tabs/DesktopView.tsx @@ -4,10 +4,10 @@ * */ -import React, { useEffect, useRef, useState, useCallback } from 'react' -import T from 'prop-types' +import React, { FC, useEffect, useRef, useState, useCallback } from 'react' import { isEmpty, findIndex } from 'ramda' +import type { TSIZE_SM, TTabItem } from '@/spec' import { useDevice } from '@/hooks' import { SIZE } from '@/constant' import { buildLog, isString } from '@/utils' @@ -23,6 +23,7 @@ const log = buildLog('c:Tabs:index') const temItems = [ { title: '帖子', + raw: 'posts', // icon: `${ICON_CMD}/navi/fire.svg`, localIcon: 'settings', }, @@ -36,18 +37,33 @@ const temItems = [ * @param {string} activeKey * @returns number */ -const getDefaultActiveTabIndex = (items, activeKey) => { +const getDefaultActiveTabIndex = ( + items: TTabItem[], + activeKey: string, +): number => { if (isEmpty(activeKey)) return 0 const index = findIndex((item) => { - return isString(item) - ? activeKey === item - : activeKey === (item.raw || item.title) + return activeKey === (item.raw || item.title) }, items) return index >= 0 ? index : 0 } -const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => { +type TProps = { + items?: TTabItem[] + onChange: () => void + activeKey?: string + size: TSIZE_SM + slipHeight: '1px' | '2px' +} + +const Tabs: FC = ({ + size = SIZE.MEDIUM, + onChange = log, + items = temItems, + activeKey = '', + slipHeight = '2px', +}) => { const { isMobile } = useDevice() const defaultActiveTabIndex = getDefaultActiveTabIndex(items, activeKey) @@ -118,7 +134,7 @@ const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => { slipHeight={slipHeight} > @@ -126,31 +142,4 @@ const Tabs = ({ size, onChange, items, activeKey, slipHeight }) => { ) } -Tabs.propTypes = { - items: T.oneOfType([ - T.arrayOf(T.string), - T.arrayOf( - T.shape({ - title: T.string, - raw: T.string, - alias: T.string, - icon: T.oneOfType([T.string, T.node]), - localIcon: T.string, - }), - ), - ]), - onChange: T.func, - activeKey: T.string, - size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]), - slipHeight: T.oneOf(['1px', '2px']), -} - -Tabs.defaultProps = { - items: temItems, - onChange: log, - activeKey: '', - size: SIZE.MEDIUM, - slipHeight: '2px', -} - export default React.memo(Tabs) diff --git a/src/components/Switcher/Tabs/DrawerView.js b/src/components/Switcher/Tabs/DrawerView.tsx similarity index 58% rename from src/components/Switcher/Tabs/DrawerView.js rename to src/components/Switcher/Tabs/DrawerView.tsx index 1769a677a..ba24a4d47 100644 --- a/src/components/Switcher/Tabs/DrawerView.js +++ b/src/components/Switcher/Tabs/DrawerView.tsx @@ -4,9 +4,9 @@ * */ -import React, { useCallback } from 'react' -import T from 'prop-types' +import React, { FC, useCallback } from 'react' +import type { TSIZE_SM, TTabItem } from '@/spec' import { buildLog, isString } from '@/utils' import { SIZE } from '@/constant' @@ -23,7 +23,20 @@ const temItems = [ }, ] -const Tabs = ({ size, onChange, items, activeKey }) => { +type TProps = { + items?: TTabItem[] + onChange: () => void + activeKey?: string + size: TSIZE_SM + slipHeight: '1px' | '2px' +} + +const Tabs: FC = ({ + size = SIZE.MEDIUM, + onChange = log, + items = temItems, + activeKey = '', +}) => { const handleItemClick = useCallback( (item) => { onChange(isString(item) ? item : item.raw || item.title) @@ -37,7 +50,6 @@ const Tabs = ({ size, onChange, items, activeKey }) => { handleItemClick(item)} > {item.title} @@ -47,29 +59,4 @@ const Tabs = ({ size, onChange, items, activeKey }) => { ) } -Tabs.propTypes = { - items: T.oneOfType([ - T.arrayOf(T.string), - T.arrayOf( - T.shape({ - title: T.string, - raw: T.string, - alias: T.string, - icon: T.oneOfType([T.string, T.node]), - localIcon: T.string, - }), - ), - ]), - onChange: T.func, - activeKey: T.string, - size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]), -} - -Tabs.defaultProps = { - items: temItems, - onChange: log, - activeKey: '', - size: SIZE.MEDIUM, -} - export default React.memo(Tabs) diff --git a/src/components/Switcher/Tabs/LocalIcon.js b/src/components/Switcher/Tabs/LocalIcon.js index 417cba87b..d58df3b3c 100644 --- a/src/components/Switcher/Tabs/LocalIcon.js +++ b/src/components/Switcher/Tabs/LocalIcon.js @@ -19,6 +19,12 @@ import { TabFavoritesIcon, } from '../styles/tabs/local_icon' +// type TProps = { +// raw: string +// active: boolean +// small?: boolean +// } + const TabIcon = ({ raw, active, small }) => { switch (raw) { case 'tech': diff --git a/src/components/Switcher/Tabs/MobileView/ExpandView.js b/src/components/Switcher/Tabs/MobileView/ExpandView.tsx similarity index 72% rename from src/components/Switcher/Tabs/MobileView/ExpandView.js rename to src/components/Switcher/Tabs/MobileView/ExpandView.tsx index 49a56ee64..0688cb792 100644 --- a/src/components/Switcher/Tabs/MobileView/ExpandView.js +++ b/src/components/Switcher/Tabs/MobileView/ExpandView.tsx @@ -4,9 +4,9 @@ * */ -import React, { useEffect, useRef, useState, useCallback } from 'react' -import T from 'prop-types' +import React, { FC, useEffect, useRef, useState, useCallback } from 'react' +import type { TSIZE_SM, TTabItem } from '@/spec' import { ICON } from '@/config' import { SIZE } from '@/constant' import { useDevice } from '@/hooks' @@ -23,7 +23,21 @@ import { /* eslint-disable-next-line */ const log = buildLog('c:Tabs:index') -const MobileView = ({ size, onChange, items, activeKey, toggleExpand }) => { +type TProps = { + items: TTabItem[] + activeKey: string + size: TSIZE_SM + toggleExpand: () => void + onChange: () => void +} + +const MobileView: FC = ({ + size = SIZE.MEDIUM, + onChange = log, + items, + activeKey = '', + toggleExpand, +}) => { const { isMobile } = useDevice() const [tabWidthList, setTabWidthList] = useState([]) @@ -69,7 +83,7 @@ const MobileView = ({ size, onChange, items, activeKey, toggleExpand }) => {