rsvp-reader/src/components/Options.js

35 lines
863 B
JavaScript
Raw Normal View History

2019-12-14 19:22:18 +01:00
import React, { useCallback } 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-13 02:05:04 +01:00
import { setMaxLength, setWpm } from '../store/actions'
2019-12-14 18:29:17 +01:00
import { Slider } from './Slider'
2019-12-13 00:16:53 +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-13 00:16:53 +01:00
return (
<div>
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 19:22:18 +01:00
onChange={useCallback(
debounce(val => dispatch(setMaxLength(val)), 100, true),
[dispatch]
)}
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-13 00:16:53 +01:00
</div>
)
}