Skip to content

Commit bbbbb93

Browse files
authored
misc thrash (keybase#25357)
1 parent 296ee55 commit bbbbb93

11 files changed

Lines changed: 286 additions & 297 deletions

File tree

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
1-
import GlobalError from '.'
2-
import * as Container from '../../util/container'
31
import * as ConfigGen from '../../actions/config-gen'
4-
import {settingsTab} from '../../constants/tabs'
2+
import * as Container from '../../util/container'
53
import * as Platform from '../../constants/platform'
4+
import * as React from 'react'
65
import * as RouteTreeGen from '../../actions/route-tree-gen'
6+
import GlobalError from '.'
7+
import {settingsTab} from '../../constants/tabs'
78

8-
type OwnProps = {}
9+
const Connected = () => {
10+
const loggedIn = Container.useSelector(state => state.config.loggedIn)
11+
const daemonError = Container.useSelector(state => state.config.daemonError)
12+
const error = Container.useSelector(state => state.config.globalError)
13+
const dispatch = Container.useDispatch()
914

10-
const Connected = Container.connect(
11-
state => {
12-
const {loggedIn, daemonError, globalError} = state.config
13-
return {
14-
_loggedIn: loggedIn,
15-
daemonError,
16-
error: globalError,
17-
}
18-
},
19-
dispatch => ({
20-
_onFeedback: (loggedIn: boolean) => {
21-
dispatch(ConfigGen.createGlobalError({}))
22-
if (loggedIn) {
23-
dispatch(RouteTreeGen.createClearModals())
24-
if (Platform.isMobile) {
25-
dispatch(RouteTreeGen.createNavigateAppend({path: [settingsTab]}))
26-
dispatch(
27-
RouteTreeGen.createNavigateAppend({
28-
path: [
29-
{
30-
props: {heading: 'Oh no, a bug!'},
31-
selected: require('../../constants/settings').feedbackTab,
32-
},
33-
],
34-
})
35-
)
36-
} else {
37-
dispatch(RouteTreeGen.createNavigateAppend({path: ['modalFeedback']}))
38-
}
15+
const onFeedback = React.useCallback(() => {
16+
dispatch(ConfigGen.createGlobalError({}))
17+
if (loggedIn) {
18+
dispatch(RouteTreeGen.createClearModals())
19+
if (Platform.isMobile) {
20+
dispatch(RouteTreeGen.createNavigateAppend({path: [settingsTab]}))
21+
dispatch(
22+
RouteTreeGen.createNavigateAppend({
23+
path: [
24+
{
25+
props: {heading: 'Oh no, a bug!'},
26+
selected: require('../../constants/settings').feedbackTab,
27+
},
28+
],
29+
})
30+
)
3931
} else {
40-
dispatch(RouteTreeGen.createNavigateAppend({path: ['feedback']}))
32+
dispatch(RouteTreeGen.createNavigateAppend({path: ['modalFeedback']}))
4133
}
42-
},
43-
copyToClipboard: (text: string) => dispatch(ConfigGen.createCopyToClipboard({text})),
44-
onDismiss: () => {
45-
dispatch(ConfigGen.createGlobalError({}))
46-
},
47-
}),
48-
(stateProps, dispatchProps, _: OwnProps) => {
49-
const {daemonError, error, _loggedIn} = stateProps
50-
const {copyToClipboard, onDismiss, _onFeedback} = dispatchProps
51-
return {
52-
copyToClipboard,
53-
daemonError,
54-
error,
55-
onDismiss,
56-
onFeedback: () => _onFeedback(_loggedIn),
34+
} else {
35+
dispatch(RouteTreeGen.createNavigateAppend({path: ['feedback']}))
5736
}
37+
}, [loggedIn, dispatch])
38+
const copyToClipboard = React.useCallback(
39+
(text: string) => dispatch(ConfigGen.createCopyToClipboard({text})),
40+
[dispatch]
41+
)
42+
const onDismiss = React.useCallback(() => {
43+
dispatch(ConfigGen.createGlobalError({}))
44+
}, [dispatch])
45+
46+
if (daemonError || error) {
47+
return (
48+
<GlobalError
49+
copyToClipboard={copyToClipboard}
50+
daemonError={daemonError}
51+
error={error}
52+
onDismiss={onDismiss}
53+
onFeedback={onFeedback}
54+
/>
55+
)
5856
}
59-
)(GlobalError)
57+
return null
58+
}
6059
export default Connected

‎shared/common-adapters/badge.tsx‎

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,35 @@ import {Box, Box2} from './box'
33
import Text from './text'
44
import * as Styles from '../styles'
55

6+
const Kb = {
7+
Box,
8+
Box2,
9+
Text,
10+
}
11+
612
export type Badge2Props = {
713
badgeNumber?: number
814
className?: string
9-
fontSize: number
10-
height: number
11-
leftRightPadding: number
15+
fontSize?: number
16+
height?: number
17+
leftRightPadding?: number
1218
containerStyle?: Styles.StylesCrossPlatform
1319
badgeStyle?: Styles.StylesCrossPlatform
1420
badgeNumberStyle?: Styles.StylesCrossPlatform
1521
border?: boolean
1622
}
1723

18-
export default class Badge extends React.Component<Badge2Props> {
19-
static defaultProps = {
20-
fontSize: Styles.isMobile ? 12 : 10,
21-
height: Styles.isMobile ? 20 : 16,
22-
leftRightPadding: Styles.isPhone ? 5 : 4,
23-
}
24-
25-
render() {
26-
return this.props.border ? this.renderWithBorder() : this.renderNoBorder()
27-
}
24+
const Badge = React.memo(function Badge(p: Badge2Props) {
25+
const {border, containerStyle, className, badgeNumberStyle, badgeNumber, badgeStyle} = p
26+
const fontSize = p.fontSize ?? (Styles.isMobile ? 12 : 10)
27+
const height = p.height ?? (Styles.isMobile ? 20 : 16)
28+
const leftRightPadding = p.leftRightPadding ?? (Styles.isPhone ? 5 : 4)
2829

29-
renderWithBorder() {
30-
const outerSize = this.props.height
31-
const innerSize = this.props.border ? this.props.height - 3 : this.props.height
30+
if (border) {
31+
const outerSize = height
32+
const innerSize = border ? height - 3 : height
3233
return (
33-
<Box2
34+
<Kb.Box2
3435
direction="vertical"
3536
centerChildren={true}
3637
style={Styles.collapseStyles([
@@ -40,93 +41,88 @@ export default class Badge extends React.Component<Badge2Props> {
4041
height: outerSize,
4142
minWidth: outerSize,
4243
},
43-
this.props.containerStyle,
44+
containerStyle,
4445
])}
4546
>
46-
<Box
47-
className={this.props.className}
47+
<Kb.Box
48+
className={className}
4849
style={Styles.collapseStyles([
4950
styles.badge,
5051
{
5152
borderRadius: innerSize,
5253
height: innerSize,
5354
minWidth: innerSize,
54-
paddingLeft: this.props.leftRightPadding,
55-
paddingRight: this.props.leftRightPadding,
55+
paddingLeft: leftRightPadding,
56+
paddingRight: leftRightPadding,
5657
},
57-
this.props.badgeStyle,
58+
badgeStyle,
5859
])}
5960
>
60-
{!!this.props.badgeNumber && (
61-
<Text
61+
{!!badgeNumber && (
62+
<Kb.Text
6263
center={true}
6364
type="BodyTinyBold"
6465
style={Styles.collapseStyles([
6566
styles.text,
6667
{
67-
fontSize: this.props.fontSize,
68-
height: this.props.height,
69-
lineHeight: Styles.isMobile ? this.props.height : `${this.props.height}px`, // likely unneeded
68+
fontSize: fontSize,
69+
height: height,
70+
lineHeight: Styles.isMobile ? height : `${height}px`, // likely unneeded
7071
},
71-
this.props.badgeNumberStyle,
72+
badgeNumberStyle,
7273
] as any)}
7374
>
74-
{this.props.badgeNumber}
75-
</Text>
75+
{badgeNumber}
76+
</Kb.Text>
7677
)}
77-
</Box>
78-
</Box2>
78+
</Kb.Box>
79+
</Kb.Box2>
7980
)
80-
}
81-
82-
renderNoBorder() {
81+
} else {
8382
return (
84-
<Box
85-
className={this.props.className}
83+
<Kb.Box
84+
className={className}
8685
style={Styles.collapseStyles([
8786
styles.badge,
8887
{
89-
borderRadius: this.props.height,
90-
height: this.props.height,
91-
minWidth: this.props.height,
92-
paddingLeft: this.props.leftRightPadding,
93-
paddingRight: this.props.leftRightPadding,
88+
borderRadius: height,
89+
height: height,
90+
minWidth: height,
91+
paddingLeft: leftRightPadding,
92+
paddingRight: leftRightPadding,
9493
},
95-
this.props.badgeStyle,
94+
badgeStyle,
9695
])}
9796
>
98-
{!!this.props.badgeNumber && (
99-
<Text
97+
{!!badgeNumber && (
98+
<Kb.Text
10099
center={true}
101100
type="BodyTinyBold"
102101
style={Styles.collapseStyles([
103102
styles.text,
104103
{
105-
fontSize: this.props.fontSize,
106-
height: this.props.height,
107-
lineHeight: Styles.isMobile ? this.props.height : `${this.props.height}px`,
104+
fontSize: fontSize,
105+
height: height,
106+
lineHeight: Styles.isMobile ? height : `${height}px`,
108107
},
109-
this.props.badgeNumberStyle,
108+
badgeNumberStyle,
110109
] as any)}
111110
>
112-
{this.props.badgeNumber}
113-
</Text>
111+
{badgeNumber}
112+
</Kb.Text>
114113
)}
115-
</Box>
114+
</Kb.Box>
116115
)
117116
}
118-
}
117+
})
118+
export default Badge
119119

120120
const styles = Styles.styleSheetCreate(() => ({
121121
badge: {
122122
...Styles.globalStyles.flexBoxRow,
123123
...Styles.globalStyles.flexBoxCenter,
124124
backgroundColor: Styles.globalColors.orange,
125125
},
126-
container: {
127-
backgroundColor: Styles.globalColors.white,
128-
},
129-
text: {
130-
color: Styles.globalColors.white,
131-
},
126+
container: {backgroundColor: Styles.globalColors.white},
127+
text: {color: Styles.globalColors.white},
132128
}))

0 commit comments

Comments
 (0)