Skip to content

Commit 23f9f05

Browse files
committed
Idle and hovered state hooked up to Player Controls and Metadata
1 parent 87f836e commit 23f9f05

19 files changed

+199
-30
lines changed

package-lock.json

+30-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
"chroma-js": "^2.0.2",
2727
"gradient-color": "^2.0.1",
2828
"lodash": "^4.17.11",
29+
"lodash.memoize": "^4.1.2",
30+
"memoize": "^0.1.1",
2931
"randomcolor": "^0.5.3",
3032
"react": "^16.7.0",
3133
"react-dom": "^16.7.0",
3234
"react-icons-kit": "^1.2.1",
35+
"react-idle-timer": "^4.2.1",
3336
"react-redux": "^6.0.0",
3437
"redux": "^4.0.1",
3538
"redux-saga": "^0.16.2",
39+
"reselect": "^4.0.0",
3640
"visualizer-micro": "^0.1.0"
3741
}
3842
}

src/components/Audio/Audio.connect.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ import {
22
connect
33
} from 'react-redux'
44

5-
import _ from 'lodash'
5+
import { select } from '../../units/utils/connect'
66

77
import { actions } from './Audio.actions'
8-
98
import * as selectors from './Audio.selectors'
109

1110
export default (Component) => connect((state) => {
12-
return _.mapValues(selectors, (selector, key) => {
13-
const value = selector(state)
14-
return value
15-
})
11+
return select(selectors, state)
1612
}, {
1713
...actions,
1814
})(Component)

src/components/Audio/Audio.selectors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
_Audio,
77
audio as _audio,
88
paused as _paused,
9+
playing as _playing,
910
volume as _volume,
1011
fakeTriggered as _fakeTriggered,
1112
vm as _vm,
@@ -22,7 +23,6 @@ export const timestamp = createSelector(
2223
_timestamp,
2324
)
2425

25-
2626
export const audio = createSelector(
2727
_Audio,
2828
timestamp,
@@ -52,7 +52,7 @@ export const paused = createSelector(
5252

5353
export const playing = createSelector(
5454
paused,
55-
_paused,
55+
_playing,
5656
)
5757

5858
export const volume = createSelector(

src/components/Audio/Audio.units.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
export const audio = ({ audio }) => audio
22
export const volume = ({ volume }) => volume
3-
export const paused = ({ paused }) => paused
4-
export const playing = (paused) => !paused
5-
export const duration = ({ duration }) => duration
3+
export const paused = ({ paused }) => {
4+
return paused
5+
}
6+
export const duration = ({ duration }) => {
7+
return duration
8+
}
69
export const currentTime = ({ currentTime }) => currentTime
710
export const fakeTriggered = ({ fakeTriggered }) => fakeTriggered
811
export const vm = ({ vm }) => vm
912
export const visualizerLoaded = ({ visualizerLoaded }) => visualizerLoaded
1013
export const timestamp = ({ timestamp }) => timestamp
14+
export const playing = (paused) => !paused
1115

1216
export const _Audio = ({ _Audio }) => _Audio || {}
1317

src/components/Player/Controls.actions.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const CONTROLS__RESET_COLORS = 'CONTROLS__RESET_COLORS'
44
const CONTROLS__SET_COLORS = 'CONTROLS__SET_COLORS'
55
const CONTROLS__SET_COLOR = 'CONTROLS__SET_COLOR'
66
const CONTROLS__SET_NUM_COLORS = 'CONTROLS__SET_NUM_COLORS'
7-
8-
import _ from 'lodash'
7+
const CONTROLS__SET_IDLE_INACTIVE = 'CONTROLS__SET_IDLE_INACTIVE'
8+
const CONTROLS__SET_IDLE_ACTIVE = 'CONTROLS__SET_IDLE_ACTIVE'
9+
const CONTROLS__SET_HOVER_ACTIVE = 'CONTROLS__SET_HOVER_ACTIVE'
10+
const CONTROLS__SET_HOVER_INACTIVE = 'CONTROLS__SET_HOVER_INACTIVE'
911

1012
export const types = {
1113
CONTROLS__SET_GENRE,
@@ -14,6 +16,10 @@ export const types = {
1416
CONTROLS__SET_NUM_COLORS,
1517
CONTROLS__RESET_COLORS,
1618
CONTROLS__SET_COLOR,
19+
CONTROLS__SET_IDLE_INACTIVE,
20+
CONTROLS__SET_IDLE_ACTIVE,
21+
CONTROLS__SET_HOVER_ACTIVE,
22+
CONTROLS__SET_HOVER_INACTIVE,
1723
}
1824

1925
const setGenre = (index) => {
@@ -45,8 +51,36 @@ const resetColors = (numColors) => {
4551
}
4652
}
4753

54+
const setIdleActive = () => {
55+
return {
56+
type: types.CONTROLS__SET_IDLE_ACTIVE,
57+
}
58+
}
59+
60+
const setIdleInactive = () => {
61+
return {
62+
type: types.CONTROLS__SET_IDLE_INACTIVE,
63+
}
64+
}
65+
66+
const setHoverActive = () => {
67+
return {
68+
type: types.CONTROLS__SET_HOVER_ACTIVE,
69+
}
70+
}
71+
72+
const setHoverInactive = () => {
73+
return {
74+
type: types.CONTROLS__SET_HOVER_INACTIVE,
75+
}
76+
}
77+
4878
export const actions = {
4979
// setColors,
80+
setHoverActive,
81+
setHoverInactive,
82+
setIdleActive,
83+
setIdleInactive,
5084
setVisualizer,
5185
setGenre,
5286
setColor,

src/components/Player/Controls.component.js

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class Controls extends Component {
207207

208208
return <div
209209
style={styles.container}
210+
onMouseOut={this.props.setHoverInactive}
211+
onMouseOver={this.props.setHoverActive}
210212
>
211213
<div style={styles.row}>
212214
<SimpleIcon icon={paused ? ic_play_arrow : ic_pause} onClick={this.props.onPlay}/>

src/components/Player/Controls.connect.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ import {
44

55
import _ from 'lodash'
66

7+
import { select } from '../../units/utils/connect'
8+
79
import { actions as actionsAudio } from '../Audio/Audio.actions'
810
import { actions } from './Controls.actions'
911

1012
import * as selectorsAudio from '../Audio/Audio.selectors'
1113
import * as selectors from './Controls.selectors'
1214

1315
export default (Component) => connect((state) => {
14-
return _.mapValues({
16+
const selected = select({
1517
...selectorsAudio,
1618
...selectors,
17-
}, (selector, key) => {
18-
const value = selector(state)
19-
return value
20-
})
19+
}, state)
20+
21+
return selected
2122
}, {
2223
...actionsAudio,
2324
...actions,

src/components/Player/Controls.reducer.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export const initialState = {
66
visualizerIndex: 0,
77
numColors: 3,
88
colors: [],
9+
idle: false,
10+
hovered: false,
911
}
1012

1113
export const reducer = {
@@ -41,5 +43,28 @@ export const reducer = {
4143
numColors,
4244
}
4345
},
44-
46+
[types.CONTROLS__SET_IDLE_ACTIVE]: (state, action) => {
47+
return {
48+
...state,
49+
idle: true,
50+
}
51+
},
52+
[types.CONTROLS__SET_IDLE_INACTIVE]: (state, action) => {
53+
return {
54+
...state,
55+
idle: false,
56+
}
57+
},
58+
[types.CONTROLS__SET_HOVER_ACTIVE]: (state, action) => {
59+
return {
60+
...state,
61+
hovered: true,
62+
}
63+
},
64+
[types.CONTROLS__SET_HOVER_INACTIVE]: (state, action) => {
65+
return {
66+
...state,
67+
hovered: false,
68+
}
69+
},
4570
}

src/components/Player/Controls.selectors.js

+12
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,25 @@ import {
1111
color1 as _color1,
1212
color2 as _color2,
1313
color3 as _color3,
14+
idle as _idle,
15+
hovered as _hovered,
1416
} from './Controls.units'
1517

18+
export const idle = createSelector(
19+
Controls,
20+
_idle,
21+
)
22+
1623
export const colors = createSelector(
1724
Controls,
1825
_colors,
1926
)
2027

28+
export const hovered = createSelector(
29+
Controls,
30+
_hovered,
31+
)
32+
2133
export const visualizerIndex = createSelector(
2234
Controls,
2335
_visualizerIndex,

src/components/Player/Controls.units.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export const colors = ({ colors }) => colors
22
export const visualizerIndex = ({ visualizerIndex }) => visualizerIndex
33
export const genreIndex = ({ genreIndex }) => genreIndex
44
export const numColors = ({ numColors }) => numColors
5+
export const hovered = ({ hovered }) => hovered
6+
export const idle = ({ idle }) => idle
57
export const color1 = (colors) => colors[0]
68
export const color2 = (colors) => colors[1]
79
export const color3 = (colors) => colors[2]

src/components/Player/DurationChecker.component.js

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ class DurationChecker extends Component {
2626
}
2727
}
2828

29+
componentDidUpdate(prevProps, prevState, snapshot) {
30+
if (this.props.playing && !prevProps.playing) {
31+
this.setTimer()
32+
}
33+
34+
if (this.props.paused && !prevProps.paused) {
35+
this.clearTimer()
36+
}
37+
}
38+
2939
render() {
3040
return <Fragment />
3141
}

src/components/Player/Metadata.component.js

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class Metadata extends Component {
7777

7878
return <div
7979
style={styles.container}
80+
onMouseOut={this.props.setHoverInactive}
81+
onMouseOver={this.props.setHoverActive}
8082
>
8183
<Duration percentComplete={percentComplete}/>
8284

0 commit comments

Comments
 (0)