forked from 0xClpz/hyper-spotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (70 loc) · 2.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const get = require('lodash.get')
const { getThemeCssByName } = require('./dist/utils/ThemeManager')
const { HyperSpotifyHeaderFactory } = require('./dist/components/HyperSpotifyHeader')
const { HyperSpotifyFooterFactory } = require('./dist/components/HyperSpotifyFooter')
exports.decorateConfig = (config) => {
const hyperSpotify = Object.assign({
position: 'bottom',
margin: 'default',
controlsPosition: 'default'
}, config.hyperSpotify)
const { position, margin } = hyperSpotify
let marginValue = (position === 'top' ? 34 : 0)
switch (margin) {
case 'default':
marginValue += 30
break
case 'double':
marginValue += 60
break
default:
marginValue = margin
}
return Object.assign({}, config, {
css: `
${config.css || ''}
.terms_terms {
margin-${position}: ${marginValue}px;
}
.hyper-spotify.hoverable:hover,
.hyper-spotify .hoverable:hover {
opacity: 1 !important;
}
`
})
}
exports.reduceUI = (state, {type, config}) => {
switch (type) {
case 'CONFIG_LOAD':
case 'CONFIG_RELOAD': {
return state.set('hyperSpotify', config.hyperSpotify)
}
}
return state
}
exports.mapHyperState = ({ ui: { hyperSpotify } }, map) => Object.assign({}, map, {
hyperSpotify: Object.assign({}, hyperSpotify),
customCSS: `${map.customCSS || ''} ${getThemeCssByName(get(hyperSpotify, 'theme', 'default'), hyperSpotify)}`
})
exports.decorateHyper = (Hyper, { React }) => {
const HyperSpotifyHeader = HyperSpotifyHeaderFactory(React) // eslint-disable-line no-unused-vars
const HyperSpotifyFooter = HyperSpotifyFooterFactory(React) // eslint-disable-line no-unused-vars
return class extends React.PureComponent {
render () {
const {
customInnerChildren: existingInnerChildren,
hyperSpotify: pluginConfig
} = this.props
let customInnerChildren = existingInnerChildren ? existingInnerChildren instanceof Array ? existingInnerChildren : [existingInnerChildren] : []
const position = get(pluginConfig, 'position', 'bottom')
if (position === 'top') {
customInnerChildren = [].concat(React.createElement(HyperSpotifyHeader, { pluginConfig }), customInnerChildren)
} else if (position === 'bottom') {
customInnerChildren = [].concat(customInnerChildren, React.createElement(HyperSpotifyFooter, { pluginConfig }))
}
return (
React.createElement(Hyper, Object.assign({}, this.props, { customInnerChildren }))
)
}
}
}