Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
feat(minimal-version): Harden player for minimal configuration
Browse files Browse the repository at this point in the history
- new configuration for active and visible tabs
  • Loading branch information
alexander-heimbuch committed Aug 14, 2017
1 parent d9d0793 commit 5d970f0
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 46 deletions.
18 changes: 18 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,21 @@ _Not providing chapters will disable all chapter related functions._
name: 'Denis Ahrens'
}]
```

#### Tabs

| tabs.info | toggle the info tab |
| tabs.share | toggle the share tab |
| tabs.chapters | toggle the chapters tab |
| tabs.audio | toggle the audio tab |
| tabs.download | toggle the download tab |
| visibleTabs | List of visible tabs, available: 'chapters', 'audio', 'share', 'download', 'info' |

_Note: not providing visibleTabs enables all tabs_

```javascript
tabs: {
info: true // will expand the info tab on load
},
visibleTabs: ['info', 'chapters'] // only info and chapter tabs are visible
```
12 changes: 10 additions & 2 deletions docs/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,22 @@ navigation: 7
name: 'Tim Pritlove'
}, {
avatar: 'https://freakshow.fm/wp-content/cache/podlove/0f/9c18f5e825496b9060337f92814142/clemens-schrimpe_50x50.jpg',
name: ' Clemens Schrimpe'
name: 'Clemens Schrimpe'
}, {
avatar: 'https://freakshow.fm/wp-content/cache/podlove/8e/f30cbe274c3f5e43dc4a7219676f50/hukl_50x50.jpg',
name: 'hukl'
}, {
avatar: 'https://freakshow.fm/wp-content/cache/podlove/b2/425e5c8f180ddf548c95be1c2d7bcf/denis-ahrens_50x50.jpg',
name: 'Denis Ahrens'
}]
}],
tabs: {
chapters: false,
audio: false,
share: false,
download: false,
info: false
},
visibleTabs: ['chapters', 'audio', 'share', 'download', 'info']
};

function loadEditor(store) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/header/Header.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="header" :style="backgroundStyle">
<div class="header" :style="backgroundStyle" v-if="components.error || components.info">
<PodloveError v-if="components.error"></PodloveError>
<PodloveInfo v-if="components.info"></PodloveInfo>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/Tabs.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="tabs" :style="containerStyle">
<div class="tabs" :style="containerStyle" v-if="components.visibleTabs.length > 0">
<TabHeaderComponent>
<TabHeaderItemComponent :active="tabs.chapters" :click="toggleTab('chapters')" v-if="components.tabs.chapters">
<ChaptersIcon slot="icon"></ChaptersIcon>
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/download/Download.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="download-tab">
<div class="show-info centered column">
<div class="show-info centered column" v-if="episode.poster || show.poster">
<img class="episode-poster shadowed" v-if="episode.poster || show.poster" :src="episode.poster || show.poster">
<ul class="episode-meta centered">
<li class="meta centered" v-if="episode.publicationDate"><CalendarIcon class="icon"></CalendarIcon>{{ publicationDate }}</li>
Expand Down
7 changes: 5 additions & 2 deletions src/components/tabs/share/ShareChannels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<li><ChannelFacebookComponent :link="shareLink"></ChannelFacebookComponent></li>
<li><ChannelGooglePlusComponent :link="shareLink"></ChannelGooglePlusComponent></li>
<li><ChannelMailComponent :text="shareText" :subject="shareSubject"></ChannelMailComponent></li>
<li v-if="type !== 'show'"><ChannelEmbedComponent :color="theme.tabs.share.platform.button"></ChannelEmbedComponent></li>
<li v-if="type !== 'show' && ((reference.config && reference.share) || reference.origin)">
<ChannelEmbedComponent :color="theme.tabs.share.platform.button"></ChannelEmbedComponent>
</li>
</ul>
</template>

Expand All @@ -27,7 +29,8 @@
episode: this.$select('episode'),
playtime: this.$select('playtime'),
chapters: this.$select('chapters'),
theme: this.$select('theme')
theme: this.$select('theme'),
reference: this.$select('reference')
}
},
computed: {
Expand Down
29 changes: 24 additions & 5 deletions src/store/effects/components.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { get } from 'lodash'
import actions from '../actions'

const hasChapters = chapters => chapters.length > 0
const hasMeta = (show, episode) => episode.poster || show.poster || show.title || episode.title || episode.subtitle
const hasFiles = files => files.length > 0

export default (store, action) => {
switch (action.type) {
case 'LOADING':
Expand Down Expand Up @@ -29,22 +33,37 @@ export default (store, action) => {
case 'INIT':
const state = store.getState()
const chapters = get(state, 'chapters', [])
const reference = get(state, 'reference', {})
const downloadFiles = get(state, 'download.files', [])
const episode = get(state, 'episode', {})
const show = get(state, 'show', {})
const tabs = get(state, 'components.visibleTabs', [])

if (chapters.length > 0) {
// Tabs
if (tabs.includes('chapters') && hasChapters(chapters)) {
store.dispatch(actions.toggleChaptersTab(true))
}

if ((reference.config && reference.share) || reference.origin) {
if (tabs.includes('share')) {
store.dispatch(actions.toggleShareTab(true))
}

if (downloadFiles.length > 0) {
if (tabs.includes('info')) {
store.dispatch(actions.toggleInfoTab(true))
}

if (tabs.includes('download') && hasFiles(downloadFiles)) {
store.dispatch(actions.toggleDownloadTab(true))
}

store.dispatch(actions.toggleInfoTab(true))
if (tabs.includes('audio')) {
store.dispatch(actions.toggleAudioTab(true))
}

// Meta
if (hasMeta(show, episode)) {
store.dispatch(actions.toggleInfo(true))
}

break
case 'STOP':
store.dispatch(actions.showReplayButton())
Expand Down
111 changes: 90 additions & 21 deletions src/store/effects/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@ import sinon from 'sinon'

import components from './components'

let store
let store, state

test.beforeEach(t => {
state = {
chapters: ['chapter 1', 'chapter 2'],
download: {
files: [{
url: 'http://foo.bar'
}, {
url: 'http://foo.baz'
}]
},
episode: {
url: 'http://foo.bar/episode',
poster: './img/src'
},
show: {
url: 'http://foo.bar',
poster: './img/src'
},
reference: {
config: 'reference-config',
share: 'reference-share',
origin: 'reference-origin'
},
components: {
visibleTabs: ['chapters', 'share', 'info', 'download', 'audio']
}
}

store = {
dispatch: sinon.stub(),
getState: sinon.stub().returns({
chapters: ['chapter 1', 'chapter 2'],
download: {
files: [{
url: 'http://foo.bar'
}, {
url: 'http://foo.baz'
}]
},
reference: {
config: 'reference-config',
share: 'reference-share',
origin: 'reference-origin'
}
})
getState: sinon.stub().returns(state)
}
})

Expand Down Expand Up @@ -106,7 +119,7 @@ test(`componentsEffect: it shows correct ui components for IDLE action`, t => {
})
})

test(`componentsEffect: it shows correct ui components for restore INIT action`, t => {
test(`componentsEffect: it shows correct ui components for INIT action`, t => {
const testAction = {
type: 'INIT'
}
Expand All @@ -121,26 +134,82 @@ test(`componentsEffect: it shows correct ui components for restore INIT action`,
payload: true
})
t.deepEqual(store.dispatch.getCall(2).args[0], {
type: 'TOGGLE_COMPONENT_TABS_INFO',
payload: true
})
t.deepEqual(store.dispatch.getCall(3).args[0], {
type: 'TOGGLE_COMPONENT_TABS_DOWNLOAD',
payload: true
})
t.deepEqual(store.dispatch.getCall(4).args[0], {
type: 'TOGGLE_COMPONENT_TABS_AUDIO',
payload: true
})
t.deepEqual(store.dispatch.getCall(5).args[0], {
type: 'TOGGLE_COMPONENT_INFO',
payload: true
})
})

test(`componentsEffect: it shows correct ui components for INIT action`, t => {
test(`componentsEffect: it respects the visibleTabs on INIT`, t => {
const testAction = {
type: 'INIT'
}

store.getState = sinon.stub().returns({})
state.components.visibleTabs = []
store.getState = sinon.stub().returns(state)

components(store, testAction)
t.is(store.dispatch.getCalls().length, 1)
t.deepEqual(store.dispatch.getCall(0).args[0], {
type: 'TOGGLE_COMPONENT_TABS_INFO',
type: 'TOGGLE_COMPONENT_INFO',
payload: true
})
})

test(`componentsEffect: it shows the chapters tab only when chapters are available on INIT`, t => {
const testAction = {
type: 'INIT'
}

state.chapters = []
store.getState = sinon.stub().returns(state)

components(store, testAction)
t.deepEqual(store.dispatch.getCall(0).args[0], {
type: 'TOGGLE_COMPONENT_TABS_SHARE',
payload: true
})
})

test(`componentsEffect: it shows the download tab only when audio files are available on INIT`, t => {
const testAction = {
type: 'INIT'
}

state.download = []
store.getState = sinon.stub().returns(state)

components(store, testAction)
t.deepEqual(store.dispatch.getCall(3).args[0], {
type: 'TOGGLE_COMPONENT_TABS_AUDIO',
payload: true
})
})

test(`componentsEffect: it shows the info section only when meta available on INIT`, t => {
const testAction = {
type: 'INIT'
}

state.components.visibleTabs = []
state.show = {}
state.episode = {}
store.getState = sinon.stub().returns(state)

components(store, testAction)
t.is(store.dispatch.getCalls().length, 0)
})

test(`componentsEffect: it shows correct ui components for STOP action`, t => {
const testAction = {
type: 'STOP'
Expand Down
14 changes: 11 additions & 3 deletions src/store/reducers/components.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { get } from 'lodash'

const INITIAL = {
info: true,
info: false,
error: false,
controls: {
button: {
Expand All @@ -21,10 +23,11 @@ const INITIAL = {
tabs: {
chapters: false,
share: false,
audio: true,
audio: false,
download: false,
info: false
}
},
visibleTabs: ['chapters', 'share', 'audio', 'download', 'info']
}

const buttonVariant = (state, variant, active) => {
Expand Down Expand Up @@ -55,6 +58,11 @@ const buttonVariant = (state, variant, active) => {

const components = (state = INITIAL, action) => {
switch (action.type) {
case 'INIT':
return {
...INITIAL,
visibleTabs: get(action.payload, 'visibleTabs', INITIAL.visibleTabs)
}
case 'TOGGLE_COMPONENT_INFO':
return {
...state,
Expand Down
7 changes: 4 additions & 3 deletions src/store/reducers/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let uiState, compareState

test.beforeEach(() => {
uiState = {
info: true,
info: false,
error: false,
controls: {
button: {
Expand All @@ -27,10 +27,11 @@ test.beforeEach(() => {
tabs: {
chapters: false,
share: false,
audio: true,
audio: false,
download: false,
info: false
}
},
visibleTabs: ['chapters', 'share', 'audio', 'download', 'info']
}

compareState = Object.assign({}, uiState)
Expand Down
25 changes: 18 additions & 7 deletions src/store/reducers/tabs.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
const get = require('lodash/get')

const INITIAL = {
'chapters': false,
'audio': false,
'share': false,
'download': false,
'info': false
chapters: false,
audio: false,
share: false,
download: false,
info: false
}

const tabs = (state = INITIAL, action) => {
let tabs

switch (action.type) {
case 'INIT':
tabs = get(action.payload, 'tabs', null)

return {
...INITIAL,
...tabs
}

case 'TOGGLE_TAB':
return Object.assign({}, INITIAL, {
return {
...INITIAL,
[action.payload]: !get(state, action.payload, false)
})
}

case 'SET_TABS':
return action.payload
Expand Down

0 comments on commit 5d970f0

Please sign in to comment.