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

Commit f9e089e

Browse files
authored
chore: (js->ts): covert more (#1024)
* chore(ts-workflow): more ts * chore(ts-workflow): more ts
1 parent e776422 commit f9e089e

File tree

7 files changed

+74
-45
lines changed

7 files changed

+74
-45
lines changed

src/components/Checker/index.js renamed to src/components/Checker/index.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66

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

9+
import type { TSIZE_SM } from '@/spec'
1010
import { ICON } from '@/config'
1111
import { SIZE } from '@/constant'
1212
import { buildLog } from '@/utils'
@@ -16,7 +16,21 @@ import { Wrapper, IconWrapper, Icon, ChildWrapper } from './styles'
1616
/* eslint-disable-next-line */
1717
const log = buildLog('c:Checker:index')
1818

19-
const Checker = ({ checked, onChange, hiddenMode, size, children }) => {
19+
type TProps = {
20+
children: React.ReactNode
21+
checked?: boolean
22+
hiddenMode: boolean
23+
size?: TSIZE_SM
24+
onChange: (checked: boolean) => void
25+
}
26+
27+
const Checker: React.FC<TProps> = ({
28+
checked = false,
29+
onChange = log,
30+
hiddenMode = false,
31+
size = SIZE.MEDIUM,
32+
children,
33+
}) => {
2034
const show = checked || !hiddenMode
2135

2236
return (
@@ -31,20 +45,4 @@ const Checker = ({ checked, onChange, hiddenMode, size, children }) => {
3145
)
3246
}
3347

34-
Checker.propTypes = {
35-
checked: T.bool,
36-
hiddenMode: T.bool,
37-
size: T.oneOf([SIZE.MEDIUM, SIZE.SMALL]),
38-
children: T.oneOfType([T.string, T.node]),
39-
onChange: T.func,
40-
}
41-
42-
Checker.defaultProps = {
43-
checked: false,
44-
hiddenMode: false,
45-
children: '',
46-
size: SIZE.MEDIUM,
47-
onChange: log,
48-
}
49-
5048
export default React.memo(Checker)

src/spec/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TRootStore as RootStoreType } from '@/stores/RootStore'
22

3-
export type { TSIZE, TSIZE_TS, TSIZE_TSM, TSIZE_SML } from './size'
3+
export type { TSIZE, TSIZE_TS, TSIZE_TSM, TSIZE_SML, TSIZE_SM } from './size'
44
export type { TButton } from './comp'
55

66
export type TThemeName =
@@ -84,6 +84,15 @@ export type TViewing = {
8484
export type TTheme = any
8585
// export type TTheme = string
8686

87+
export type TThemeMap = {
88+
toast: {
89+
successBar: string
90+
errorBar: string
91+
warnBar: string
92+
infoBar: string
93+
}
94+
}
95+
8796
// google analytis format
8897
export type GA_EVENT = {
8998
action: string

src/spec/size.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export type TSIZE = 'TINY' | 'SMALL' | 'MEDIUM' | 'LARGE'
44
export type TSIZE_TS = 'TINY' | 'SMALL'
55
export type TSIZE_TSM = 'TINY' | 'SMALL' | 'MEDIUM'
66
export type TSIZE_SML = 'SMALL' | 'MEDIUM' | 'LARGE'
7+
export type TSIZE_SM = 'SMALL' | 'MEDIUM'

utils/graphql.js renamed to utils/graphql.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { GRAPHQL_ENDPOINT, PAGE_SIZE } from '@/config'
55
import { nilOrEmpty, isString } from './validator'
66

77
export const asyncRes = curry((key, obj) => and(obj[key], has(key, obj)))
8-
export const asyncErr = (key) => pathEq(['error'], key)
8+
export const asyncErr = (key: string): any => pathEq(['error'], key)
99

1010
// NOTE the client with jwt info is used for getInitialProps for SSR
1111
// to load user related data
12-
export const makeGQClient = (token) => {
12+
export const makeGQClient = (token: string): any => {
1313
if (!nilOrEmpty(token)) {
1414
const client = new GraphQLClient(GRAPHQL_ENDPOINT, {
1515
headers: {
@@ -23,7 +23,10 @@ export const makeGQClient = (token) => {
2323
}
2424
}
2525

26-
export const makeGithubExplore = (GRAPHQL_ENDPOINT, token) => {
26+
export const makeGithubExplore = (
27+
GRAPHQL_ENDPOINT: string,
28+
token: string,
29+
): any => {
2730
const client = new GraphQLClient(GRAPHQL_ENDPOINT, {
2831
headers: {
2932
authorization: `bearer ${token}`,
@@ -32,14 +35,16 @@ export const makeGithubExplore = (GRAPHQL_ENDPOINT, token) => {
3235
return client
3336
}
3437

35-
export const pagedFilter = (page, options = {}) =>
38+
export const pagedFilter = (page, options = {}): Record<string, any> =>
3639
merge({ page, size: PAGE_SIZE.D }, options)
3740

3841
/*
3942
* map value(string) to UPPER case for server absinthe-atom format
4043
* e.p: is server required :post, front-end should pass "POST"
4144
*/
42-
export const atomizeValues = (_obj) => {
45+
export const atomizeValues = (
46+
_obj: Record<string, any>,
47+
): Record<string, string> => {
4348
const obj = clone(_obj)
4449

4550
Object.keys(obj).forEach((k) => {
@@ -55,4 +60,6 @@ export const atomizeValues = (_obj) => {
5560
// in rxjs, if you want to send parallel request you should use complex method
5661
// like forkJoin .. which need to refactor whole sr71 part
5762
// currently the simple later is fine
58-
export const later = (func, time = 200) => setTimeout(func, time)
63+
export const later = (func, time = 200): ReturnType<typeof setTimeout> => {
64+
return setTimeout(func, time)
65+
}

utils/helper.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ type TSORTABLE_ITEMS = {
1313
index?: number
1414
}[]
1515

16-
/* eslint-disable */
17-
// TODO: document ?
18-
export const Global = typeof window !== 'undefined' ? window : global
19-
/* eslint-enable */
16+
export const Global: any = typeof window !== 'undefined' ? window : {}
2017

2118
// those two function used to encode/decode the value in element dataset
2219
export const o2s = JSON.stringify

utils/logger.js renamed to utils/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if (
4040
* debug('Some message')
4141
* @returns {Function}
4242
*/
43-
export const buildLog = (namespace) => _debug(`${namespace}`)
43+
export const buildLog = (namespace: string) => _debug(`${namespace}`)
4444

4545
/**
4646
* Default debugger, simple log.

utils/toast.js renamed to utils/toast.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44

55
import { merge, reject } from 'ramda'
66

7+
import { TThemeMap } from '@/spec'
78
import { Global } from './helper'
89
import { nilOrEmpty } from './validator'
910

10-
const checkValid = () => Global.iziToast || false
11+
type TToastType = 'success' | 'error' | 'warn'
12+
13+
type TToastOption = {
14+
title: string
15+
msg: string
16+
progressBarColor: string
17+
position: 'bottom' | 'top'
18+
}
19+
20+
const checkValid = () => (Global as any).iziToast || false
1121

1222
const defaultOptions = {
1323
title: 'coderplanets',
@@ -20,26 +30,33 @@ const defaultOptions = {
2030
transitionIn: 'fadeInDown',
2131
}
2232

23-
const doNotify = (options = {}) => {
24-
if (!checkValid()) return false
25-
26-
/* eslint-disable no-undef */
33+
const doNotify = (options = {}): void => {
34+
if (!checkValid()) {
35+
return
36+
}
37+
const { iziToast } = Global as any
2738
iziToast.show(merge(defaultOptions, reject(nilOrEmpty, options)))
28-
return false
2939
}
3040

3141
export const toast = {
32-
info: ({ title, msg, progressBarColor, position }) =>
33-
doNotify({ title, message: msg, progressBarColor, position }),
34-
error: ({ title, msg, progressBarColor, position }) =>
35-
doNotify({ title, message: msg, progressBarColor, position }),
36-
success: ({ title, msg, progressBarColor, position }) =>
37-
doNotify({ title, message: msg, progressBarColor, position }),
38-
warn: ({ title, msg, progressBarColor, position }) =>
39-
doNotify({ title, message: msg, progressBarColor, position }),
42+
info: ({ title, msg, progressBarColor, position }: TToastOption): void => {
43+
doNotify({ title, message: msg, progressBarColor, position })
44+
},
45+
error: ({ title, msg, progressBarColor, position }: TToastOption): void => {
46+
doNotify({ title, message: msg, progressBarColor, position })
47+
},
48+
success: ({ title, msg, progressBarColor, position }: TToastOption): void => {
49+
doNotify({ title, message: msg, progressBarColor, position })
50+
},
51+
warn: ({ title, msg, progressBarColor, position }: TToastOption): void => {
52+
doNotify({ title, message: msg, progressBarColor, position })
53+
},
4054
}
4155

42-
export const toastBarColor = (type, themeData) => {
56+
export const toastBarColor = (
57+
type: TToastType,
58+
themeData: TThemeMap,
59+
): string => {
4360
switch (type) {
4461
case 'success':
4562
return themeData.toast.successBar

0 commit comments

Comments
 (0)