2019-12-14 20:02:56 +01:00
|
|
|
import React from 'react'
|
2019-12-13 00:16:53 +01:00
|
|
|
import { useSelector, useDispatch } from 'react-redux'
|
2019-12-14 18:29:17 +01:00
|
|
|
import { debounce } from 'debounce'
|
2019-12-13 00:16:53 +01:00
|
|
|
|
2019-12-22 18:07:01 +01:00
|
|
|
import { setMaxLength, setWpm, setOffset, setLang } from '../store/actions'
|
2019-12-14 18:29:17 +01:00
|
|
|
import { Slider } from './Slider'
|
2019-12-22 18:07:01 +01:00
|
|
|
import { selectOffset, selectLang } from '../store/selectors'
|
|
|
|
|
|
|
|
const availableLanguages = ['en', 'de']
|
2019-12-13 00:16:53 +01:00
|
|
|
|
2019-12-14 14:08:19 +01:00
|
|
|
export const Options = () => {
|
2019-12-13 00:16:53 +01:00
|
|
|
const dispatch = useDispatch()
|
2019-12-13 02:05:04 +01:00
|
|
|
const maxLength = useSelector(state => state.maxLength)
|
|
|
|
const wpm = useSelector(state => state.wpm)
|
2019-12-15 01:09:42 +01:00
|
|
|
const offset = useSelector(selectOffset)
|
2019-12-22 18:07:01 +01:00
|
|
|
const lang = useSelector(selectLang)
|
2019-12-13 02:05:04 +01:00
|
|
|
|
2019-12-13 00:16:53 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2019-12-14 20:02:56 +01:00
|
|
|
<h2>Options</h2>
|
2019-12-14 18:29:17 +01:00
|
|
|
<Slider
|
|
|
|
title={'Maximum segment length'}
|
|
|
|
min={3}
|
2019-12-14 19:22:18 +01:00
|
|
|
max={15}
|
2019-12-13 00:16:53 +01:00
|
|
|
value={maxLength}
|
2019-12-14 20:02:56 +01:00
|
|
|
onChange={debounce(val => dispatch(setMaxLength(val)), 100)}
|
2019-12-13 00:16:53 +01:00
|
|
|
/>
|
2019-12-14 18:29:17 +01:00
|
|
|
<Slider
|
|
|
|
title={'Words per minute'}
|
|
|
|
min={100}
|
|
|
|
max={1000}
|
2019-12-13 02:05:04 +01:00
|
|
|
value={wpm}
|
2019-12-14 19:22:18 +01:00
|
|
|
onChange={debounce(val => dispatch(setWpm(val)), 50)}
|
2019-12-13 02:05:04 +01:00
|
|
|
/>
|
2019-12-15 01:09:42 +01:00
|
|
|
<Slider
|
|
|
|
title={'Offset from center'}
|
|
|
|
min={-50}
|
|
|
|
max={50}
|
|
|
|
value={offset}
|
|
|
|
onChange={val => dispatch(setOffset(val))}
|
|
|
|
/>
|
2019-12-22 18:07:01 +01:00
|
|
|
<label>
|
|
|
|
Language:
|
|
|
|
<select value={lang} onChange={e => dispatch(setLang(e.target.value))}>
|
|
|
|
{availableLanguages.map(l => (
|
|
|
|
<option key={l}>{l}</option>
|
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
</label>
|
2019-12-13 00:16:53 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|