Add offset options

This commit is contained in:
Alfred Melch 2019-12-15 01:09:42 +01:00
parent 1f8b04c056
commit 081aafa0e5
8 changed files with 51 additions and 16 deletions

View File

@ -2,13 +2,15 @@ import React from 'react'
import { useSelector, useDispatch } from 'react-redux' import { useSelector, useDispatch } from 'react-redux'
import { debounce } from 'debounce' import { debounce } from 'debounce'
import { setMaxLength, setWpm } from '../store/actions' import { setMaxLength, setWpm, setOffset } from '../store/actions'
import { Slider } from './Slider' import { Slider } from './Slider'
import { selectOffset } from '../store/selectors'
export const Options = () => { export const Options = () => {
const dispatch = useDispatch() const dispatch = useDispatch()
const maxLength = useSelector(state => state.maxLength) const maxLength = useSelector(state => state.maxLength)
const wpm = useSelector(state => state.wpm) const wpm = useSelector(state => state.wpm)
const offset = useSelector(selectOffset)
return ( return (
<div> <div>
@ -27,6 +29,13 @@ export const Options = () => {
value={wpm} value={wpm}
onChange={debounce(val => dispatch(setWpm(val)), 50)} onChange={debounce(val => dispatch(setWpm(val)), 50)}
/> />
<Slider
title={'Offset from center'}
min={-50}
max={50}
value={offset}
onChange={val => dispatch(setOffset(val))}
/>
</div> </div>
) )
} }

View File

@ -1,9 +1,14 @@
.wrapper {
overflow: hidden;
}
.border { .border {
height: 2px; height: 2px;
background: black; background: black;
} }
.marker { .marker {
position: relative;
height: 6px; height: 6px;
width: 2px; width: 2px;
background: black; background: black;

View File

@ -1,6 +1,8 @@
import React from 'react' import React from 'react'
import { useSelector } from 'react-redux'
import styles from './PivotMarker.css' import styles from './PivotMarker.css'
import { selectOffset } from '../store/selectors'
export const PipeMarker = ({ children }) => ( export const PipeMarker = ({ children }) => (
<div> <div>
@ -10,12 +12,17 @@ export const PipeMarker = ({ children }) => (
</div> </div>
) )
export const BorderMarker = ({ children }) => ( export const BorderMarker = ({ children }) => {
const offset = useSelector(selectOffset)
return (
<div> <div>
<div className={styles.border}></div> <div className={styles.border}></div>
<div className={styles.marker}></div> <div className={styles.wrapper}>
<div className={styles.marker} style={{ left: offset + '%' }}></div>
{children} {children}
<div className={styles.marker}></div> <div className={styles.marker} style={{ left: offset + '%' }}></div>
</div>
<div className={styles.border}></div> <div className={styles.border}></div>
</div> </div>
) )
}

View File

@ -1,6 +1,11 @@
.wrapper {
overflow: hidden;
}
.container { .container {
display: flex; display: flex;
font-size: 2.4em; font-size: 2.4em;
position: relative;
} }
.pivot { .pivot {
color: red; color: red;

View File

@ -1,16 +1,19 @@
import React from 'react' import React from 'react'
import { useSelector } from 'react-redux' import { useSelector } from 'react-redux'
import { selectPivotizedSegment } from '../store/selectors' import { selectPivotizedSegment, selectOffset } from '../store/selectors'
import styles from './Segment.css' import styles from './Segment.css'
export const Segment = () => { export const Segment = () => {
const [prefix, pivot, suffix] = useSelector(selectPivotizedSegment) const [prefix, pivot, suffix] = useSelector(selectPivotizedSegment)
const offset = useSelector(selectOffset)
return ( return (
<div className={styles.container}> <div className={styles.wrapper}>
<div className={styles.container} style={{ left: offset + '%' }}>
<span className={styles.prefix}>{prefix}</span> <span className={styles.prefix}>{prefix}</span>
<span className={styles.pivot}>{pivot}</span> <span className={styles.pivot}>{pivot}</span>
<span className={styles.suffix}>{suffix}</span> <span className={styles.suffix}>{suffix}</span>
</div> </div>
</div>
) )
} }

View File

@ -11,6 +11,7 @@ export const setMaxLength = length => ({
payload: length payload: length
}) })
export const setWpm = wpm => ({ type: 'SET_WPM', payload: wpm }) export const setWpm = wpm => ({ type: 'SET_WPM', payload: wpm })
export const setOffset = offset => ({ type: 'SET_OFFSET', payload: offset })
export const start = () => ({ type: 'START' }) export const start = () => ({ type: 'START' })
export const stop = () => ({ type: 'STOP' }) export const stop = () => ({ type: 'STOP' })
export const pause = () => ({ type: 'PAUSE' }) export const pause = () => ({ type: 'PAUSE' })

View File

@ -34,6 +34,7 @@ const reducer = {
curIdx: 0 curIdx: 0
}), }),
SET_WPM: (state, payload) => ({ ...state, wpm: payload }), SET_WPM: (state, payload) => ({ ...state, wpm: payload }),
SET_OFFSET: (state, payload) => ({ ...state, offset: payload }),
START: state => ({ ...state, running: true }), START: state => ({ ...state, running: true }),
STOP: state => ({ ...state, running: false, curIdx: 0 }), STOP: state => ({ ...state, running: false, curIdx: 0 }),
PAUSE: state => ({ ...state, running: false }) PAUSE: state => ({ ...state, running: false })

View File

@ -84,6 +84,10 @@ export const selectPrevSentence = createSelector(
export const selectHasNextSentence = createSelector(selectNextSentence, Boolean) export const selectHasNextSentence = createSelector(selectNextSentence, Boolean)
export const selectHasPrevSentence = createSelector(selectPrevSentence, Boolean) export const selectHasPrevSentence = createSelector(selectPrevSentence, Boolean)
export const selectRunning = state => state.running
export const selectWpm = state => state.wpm export const selectWpm = state => state.wpm
export const selectInterval = createSelector(selectWpm, wpm => 60000 / wpm) export const selectInterval = createSelector(selectWpm, wpm => 60000 / wpm)
export const selectOffset = state => state.offset
// player
export const selectRunning = state => state.running