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

Commit a993d9c

Browse files
authored
chore(js-ts): comments & related-comps (#1044)
* chore(js-ts): comments wip * chore(js-ts): convert to ts && fix warnings
1 parent c555b2b commit a993d9c

37 files changed

+462
-277
lines changed

src/components/DotDivider/index.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
*
3+
* DotDivider
4+
*
5+
*/
6+
7+
import React from 'react'
8+
9+
import { buildLog } from '@/utils'
10+
import { Wrapper } from './styles'
11+
12+
/* eslint-disable-next-line */
13+
const log = buildLog('c:DotDivider:index')
14+
15+
export type TProps = {
16+
className?: string
17+
radius?: number
18+
space?: number
19+
}
20+
const DotDivider: React.FC<TProps> = ({
21+
radius = 3,
22+
space = 3,
23+
className = 'dot-divider-class',
24+
}) => {
25+
return <Wrapper radius={radius} space={space} className={className} />
26+
}
27+
28+
export default React.memo(DotDivider)

src/components/DotDivider/styles/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import styled from 'styled-components'
22
import { theme } from '@/utils'
33

4-
type TDot = { radius: string; space: string }
5-
export const Wrapper = styled.div<TDot>`
4+
import type { TProps } from '../index'
5+
6+
export const Wrapper = styled.div<TProps>`
67
width: ${({ radius }) => `${radius}px`};
78
height: ${({ radius }) => `${radius}px`};
89
border-radius: 100%;

src/components/ImgFallback/Avatar.js renamed to src/components/ImgFallback/Avatar.tsx

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
*/
66

77
import React from 'react'
8-
import T from 'prop-types'
98

109
import { buildLog } from '@/utils'
1110

11+
import type { TAvatarProps as TProps } from './index'
1212
import { Wrapper, Name } from './styles/avatar'
1313

1414
/* eslint-disable-next-line */
1515
const log = buildLog('c:ImgFallback:Avatar')
1616

17-
const Avatar = ({
18-
testid,
19-
className,
20-
size,
21-
user,
22-
left,
23-
right,
24-
top,
25-
bottom,
26-
quote,
17+
const Avatar: React.FC<TProps> = ({
18+
testid = 'avatar-fallback',
19+
className = '',
20+
size = 15,
21+
user = {
22+
nickname: '?',
23+
},
24+
left = 0,
25+
right = 0,
26+
top = 0,
27+
bottom = 0,
28+
quote = false,
2729
}) => {
2830
const name = user?.nickname
2931
const sliceCount = size > 32 ? 2 : 1
@@ -44,32 +46,4 @@ const Avatar = ({
4446
)
4547
}
4648

47-
Avatar.propTypes = {
48-
testid: T.string,
49-
className: T.string,
50-
user: T.shape({
51-
nickname: T.string,
52-
}),
53-
size: T.number,
54-
left: T.number,
55-
right: T.number,
56-
top: T.number,
57-
bottom: T.number,
58-
quote: T.bool,
59-
}
60-
61-
Avatar.defaultProps = {
62-
testid: 'avatar-fallback',
63-
className: '',
64-
size: 15,
65-
user: {
66-
nickname: '?',
67-
},
68-
left: 0,
69-
right: 0,
70-
top: 0,
71-
bottom: 0,
72-
quote: false,
73-
}
74-
7549
export default React.memo(Avatar)

src/components/ImgFallback/Work.js renamed to src/components/ImgFallback/Work.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,12 @@ const rollTheDice = () => {
127127
}
128128
}
129129

130-
const Work = () => {
131-
return <Wrapper>{rollTheDice()}</Wrapper>
130+
type TProps = {
131+
testid?: string
132+
}
133+
134+
const Work: React.FC<TProps> = ({ testid = 'image-fallbak-work' }) => {
135+
return <Wrapper testid={testid}>{rollTheDice()}</Wrapper>
132136
}
133137

134138
export default React.memo(Work)

src/components/ImgFallback/index.js

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* ImgFallback
4+
*
5+
*/
6+
7+
import React from 'react'
8+
9+
import type { TUser } from '@/spec'
10+
import { buildLog } from '@/utils'
11+
12+
import Work from './Work'
13+
import Avatar from './Avatar'
14+
15+
/* eslint-disable-next-line */
16+
const log = buildLog('c:ImgFallback:index')
17+
18+
export type TAvatarProps = {
19+
testid?: string
20+
className?: string
21+
user?: TUser
22+
size?: number
23+
left?: number
24+
right?: number
25+
top?: number
26+
bottom?: number
27+
quote?: boolean
28+
}
29+
30+
type TProps = {
31+
type?: 'avatar' | 'work'
32+
} & TAvatarProps
33+
34+
const ImgFallback: React.FC<TProps> = ({ type = 'avatar', ...restProps }) => {
35+
switch (type) {
36+
case 'work': {
37+
return <Work />
38+
}
39+
40+
default:
41+
return <Avatar {...restProps} />
42+
}
43+
}
44+
45+
export default React.memo(ImgFallback)

src/components/ImgFallback/styles/avatar.ts

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

3-
import type { TTestable, TSpace } from '@/spec'
3+
import type { TTestable } from '@/spec'
44
import { css, theme } from '@/utils'
5+
6+
import type { TAvatarProps } from '../index'
57
import { getFontSize } from './metric/avatar'
68

7-
type IWrapper = TSpace & {
8-
size: string
9-
quote: string
10-
}
9+
type TWrapper = TTestable & TAvatarProps
1110

12-
export const Wrapper = styled.div.attrs(({ testid }: TTestable) => ({
11+
export const Wrapper = styled.div.attrs(({ testid }: TWrapper) => ({
1312
'data-test-id': testid,
14-
}))<TTestable & IWrapper>`
13+
}))<TWrapper>`
1514
${css.flex('align-both')};
1615
color: ${theme('thread.articleTitle')};
1716
width: ${({ size }) => `${size}px`};

src/containers/unit/Comments/Comment/Actions.js renamed to src/containers/unit/Comments/Comment/Actions.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import React from 'react'
22

3+
import type { TAccount, TComment } from '@/spec'
4+
35
import { Wrapper, ReplyAction } from '../styles/comment/actions'
46
import { openUpdateEditor, openReplyEditor, onDelete } from '../logic'
57

6-
const Actions = ({ data, accountInfo }) => {
8+
type TProps = {
9+
data: TComment
10+
accountInfo: TAccount
11+
}
12+
13+
const Actions: React.FC<TProps> = ({ data, accountInfo }) => {
714
if (String(data.author.id) === accountInfo.id) {
815
return (
916
<Wrapper>

src/containers/unit/Comments/Comment/DeleteMask.js

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

0 commit comments

Comments
 (0)