Skip to content

Commit

Permalink
chore: refactor to functional components
Browse files Browse the repository at this point in the history
  • Loading branch information
dubisdev committed Sep 17, 2022
1 parent f6c1990 commit 07b5cb1
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 807 deletions.
50 changes: 13 additions & 37 deletions app/main/components/ResultsList/Row/index.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,24 @@
import React, { Component } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import { SmartIcon } from '@cerebroapp/cerebro-ui'
import styles from './styles.module.css'

class Row extends Component {
classNames() {
return [
styles.row,
this.props.selected ? styles.selected : null
].join(' ')
}
function Row({
selected, icon, title, onSelect, onMouseMove, subtitle
}) {
const classNames = [styles.row, selected ? styles.selected : null].join(' ')

renderIcon() {
const { icon } = this.props
if (!icon) return null
return <SmartIcon path={icon} className={styles.icon} />
}
return (
<div className={classNames} onClick={onSelect} onMouseMove={onMouseMove}>
{icon && <SmartIcon path={icon} className={styles.icon} />}

render() {
const {
title,
onSelect,
onMouseMove,
subtitle
} = this.props
<div className={styles.details}>
{title && <div className={styles.title}>{title}</div>}

return (
<div className={this.classNames()} onClick={onSelect} onMouseMove={onMouseMove}>
{this.renderIcon()}
<div className={styles.details}>
{title && (
<div className={styles.title}>
{` ${title} `}
</div>
)}
{subtitle && (
<div className={styles.subtitle}>
{` ${subtitle} `}
</div>
)}
</div>
{subtitle && <div className={styles.subtitle}>{subtitle}</div>}
</div>
)
}
</div>
)
}

Row.propTypes = {
Expand Down
40 changes: 18 additions & 22 deletions app/plugins/core/settings/Settings/Hotkey.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import styles from './styles.module.css'

Expand Down Expand Up @@ -102,42 +102,38 @@ const charCodeToSign = ({ keyCode, shiftKey }) => {
return String.fromCharCode(code)
}

class Hotkey extends Component {
onKeyDown(event) {
function Hotkey({ hotkey, onChange }) {
const onKeyDown = (event) => {
if (!event.ctrlKey && !event.altKey && !event.metaKey) {
// Do not allow to set global shorcut without modifier keys
// At least one of alt, cmd or ctrl is required
return
}
event.preventDefault()
event.stopPropagation()

const key = charCodeToSign(event)
if (!key) {
return
}
if (!key) return
const keys = []

if (event.ctrlKey) keys.push('Control')
if (event.altKey) keys.push('Alt')
if (event.shiftKey) keys.push('Shift')
if (event.metaKey) keys.push('Command')
keys.push(key)
this.props.onChange(keys.join('+'))
}

render() {
const { hotkey } = this.props
const keys = hotkey.split('+').map(keyToSign).join(osKeyDelimiter)
return (
<div>
<input
className={styles.input}
type="text"
value={keys}
onKeyDown={this.onKeyDown.bind(this)}
/>
</div>
)
onChange(keys.join('+'))
}
const keys = hotkey.split('+').map(keyToSign).join(osKeyDelimiter)
return (
<div>
<input
className={styles.input}
type="text"
value={keys}
onKeyDown={onKeyDown}
/>
</div>
)
}

Hotkey.propTypes = {
Expand Down
Loading

0 comments on commit 07b5cb1

Please sign in to comment.