Skip to content

Commit 07b5cb1

Browse files
committed
chore: refactor to functional components
1 parent f6c1990 commit 07b5cb1

3 files changed

Lines changed: 282 additions & 807 deletions

File tree

app/main/components/ResultsList/Row/index.js

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,24 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import PropTypes from 'prop-types'
33
import { SmartIcon } from '@cerebroapp/cerebro-ui'
44
import styles from './styles.module.css'
55

6-
class Row extends Component {
7-
classNames() {
8-
return [
9-
styles.row,
10-
this.props.selected ? styles.selected : null
11-
].join(' ')
12-
}
6+
function Row({
7+
selected, icon, title, onSelect, onMouseMove, subtitle
8+
}) {
9+
const classNames = [styles.row, selected ? styles.selected : null].join(' ')
1310

14-
renderIcon() {
15-
const { icon } = this.props
16-
if (!icon) return null
17-
return <SmartIcon path={icon} className={styles.icon} />
18-
}
11+
return (
12+
<div className={classNames} onClick={onSelect} onMouseMove={onMouseMove}>
13+
{icon && <SmartIcon path={icon} className={styles.icon} />}
1914

20-
render() {
21-
const {
22-
title,
23-
onSelect,
24-
onMouseMove,
25-
subtitle
26-
} = this.props
15+
<div className={styles.details}>
16+
{title && <div className={styles.title}>{title}</div>}
2717

28-
return (
29-
<div className={this.classNames()} onClick={onSelect} onMouseMove={onMouseMove}>
30-
{this.renderIcon()}
31-
<div className={styles.details}>
32-
{title && (
33-
<div className={styles.title}>
34-
{` ${title} `}
35-
</div>
36-
)}
37-
{subtitle && (
38-
<div className={styles.subtitle}>
39-
{` ${subtitle} `}
40-
</div>
41-
)}
42-
</div>
18+
{subtitle && <div className={styles.subtitle}>{subtitle}</div>}
4319
</div>
44-
)
45-
}
20+
</div>
21+
)
4622
}
4723

4824
Row.propTypes = {

app/plugins/core/settings/Settings/Hotkey.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react'
1+
import React from 'react'
22
import PropTypes from 'prop-types'
33
import styles from './styles.module.css'
44

@@ -102,42 +102,38 @@ const charCodeToSign = ({ keyCode, shiftKey }) => {
102102
return String.fromCharCode(code)
103103
}
104104

105-
class Hotkey extends Component {
106-
onKeyDown(event) {
105+
function Hotkey({ hotkey, onChange }) {
106+
const onKeyDown = (event) => {
107107
if (!event.ctrlKey && !event.altKey && !event.metaKey) {
108108
// Do not allow to set global shorcut without modifier keys
109109
// At least one of alt, cmd or ctrl is required
110110
return
111111
}
112112
event.preventDefault()
113113
event.stopPropagation()
114+
114115
const key = charCodeToSign(event)
115-
if (!key) {
116-
return
117-
}
116+
if (!key) return
118117
const keys = []
118+
119119
if (event.ctrlKey) keys.push('Control')
120120
if (event.altKey) keys.push('Alt')
121121
if (event.shiftKey) keys.push('Shift')
122122
if (event.metaKey) keys.push('Command')
123123
keys.push(key)
124-
this.props.onChange(keys.join('+'))
125-
}
126-
127-
render() {
128-
const { hotkey } = this.props
129-
const keys = hotkey.split('+').map(keyToSign).join(osKeyDelimiter)
130-
return (
131-
<div>
132-
<input
133-
className={styles.input}
134-
type="text"
135-
value={keys}
136-
onKeyDown={this.onKeyDown.bind(this)}
137-
/>
138-
</div>
139-
)
124+
onChange(keys.join('+'))
140125
}
126+
const keys = hotkey.split('+').map(keyToSign).join(osKeyDelimiter)
127+
return (
128+
<div>
129+
<input
130+
className={styles.input}
131+
type="text"
132+
value={keys}
133+
onKeyDown={onKeyDown}
134+
/>
135+
</div>
136+
)
141137
}
142138

143139
Hotkey.propTypes = {

0 commit comments

Comments
 (0)