Skip to content

Commit

Permalink
rework list and allow for options from tabs settings
Browse files Browse the repository at this point in the history
Signed-off-by: Niv Sardi <xaiki@evilgiggle.com>
  • Loading branch information
xaiki committed Jun 12, 2018
1 parent f8241bf commit 01567d6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 51 deletions.
99 changes: 50 additions & 49 deletions src/containers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,61 +46,62 @@ const processTabState = (providers, collections, filters, cache, providerActions
}])
}
}, {items: [], failed: [], providers: []})

}

const memoizedProcessTabState = memoize (processTabState)

const ListContainer = connect(
({markers, collections, filters, cache, providerActions}, {tab}) => {
console.error('list', tab, filters)
let url = `/list/${tab.id}`

/**
* XXX: we pass the long argument list for memoization to work
* I know it's tempting to just pass state, but don't
*/
try {
const tabState = memoizedProcessTabState(
tab.providers, collections, filters, cache, providerActions
)
const mapStateToProps = ({markers, collections, filters, cache, providerActions}, {tab}) => {
console.error('list', tab, filters)
let url = `/list/${tab.id}`

/**
* XXX: we pass the long argument list for memoization to work
* I know it's tempting to just pass state, but don't
*/
try {
const tabState = memoizedProcessTabState(
tab.providers, collections, filters, cache, providerActions
)

return {
...tabState,
markers,
collections
}
} catch (e) {
console.error('error in list', e)
return {
markers,
collections,
items: []
}
return {
...tabState,
markers,
collections
}
},
(dispatch, {match, history}) => ({
dispatch,
actions: {
...bindMarkersActions(dispatch),
show: (item) => history.push(`${match.url}/${itemURL(item)}`),
play: (item) => history.push(`${match.url}/${itemURL(item)}/play`)
} catch (e) {
console.error('error in list', e)
return {
markers,
collections,
items: []
}
}),
({providers, collections, ...stateProps}, {dispatch, ...dispatchProps}, ownProps) => ({
...stateProps,
...dispatchProps,
...ownProps,
onStarve: (e) => providers.map(
provider => provider.isFetching || do {
const {ids} = collections[provider.name]
const page = Object.keys(ids).sort().pop() || 0
dispatch(
provider.actions.FETCH({page: Number(page) + 1})
)
}
)
})
)(List)
}
}

const mapDispatchToProps = (dispatch, {match, history}) => ({
dispatch,
actions: {
...bindMarkersActions(dispatch),
show: (item) => history.push(`${match.url}/${itemURL(item)}`),
play: (item) => history.push(`${match.url}/${itemURL(item)}/play`)
}
})

const mergeProps = ({providers, collections, ...stateProps}, {dispatch, ...dispatchProps}, {tab}) => ({
...stateProps,
...dispatchProps,
...tab.options,
onStarve: (e) => providers.map(
provider => provider.isFetching || do {
const {ids} = collections[provider.name]
const page = Object.keys(ids).sort().pop() || 0
dispatch(
provider.actions.FETCH({page: Number(page) + 1})
)
}
)
})

const ListContainer = connect(mapStateToProps, mapDispatchToProps, mergeProps)(List)

export {ListContainer as default}
4 changes: 2 additions & 2 deletions src/containers/listview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const mapStateToProps = ({tabs}, {match}) => {
let tab = tabs[tabId]
tab.id = tabId

const menu = Object.entries(tabs).map(([key, value]) => ({
title: value.name,
const menu = Object.entries(tabs).map(([key, {name}]) => ({
title: name,
path: `/list/${key}`
}))

Expand Down
1 change: 1 addition & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Settings.tabs = {
tvshow: {
order: 2,
name: 'Series',
options: {itemShowPlay: false},
providers: ['youtube?channel=midianinjafly&mode=shows']
},
telesur: {
Expand Down

0 comments on commit 01567d6

Please sign in to comment.