import { connect } from 'react-redux'

import List from 'butter-component-list';
import ButterSettings from 'butter-component-settings';

import MovieView from './components/movieview'
import ListView from './components/listview'

const locationToKey = (location) => (
    location.pathname.split('/').pop()
)

const ListContainer = connect(
    ({collections}, {location}) => {
        const {items, cache, isFetching, failed} = collections[locationToKey(location)]

        return {
            items: items.map(i => cache[i]),
            isFetching,
            failed,
        }
    },
    (dispatch, {location, history}) => ({
        action: (item) => history.push(`/movies/${locationToKey(location)}/${item.title}`)
    })
)(List)

const ButterSettingsContainer = connect (({settings}, props) => ({
    location: props.location,
    navbar: {goBack: () => (props.history.goBack())},
    ...settings
}))(ButterSettings)

const MovieViewContainer = connect (({collections}, {match, ...props}) => {
    const {items, cache} = collections[match.params.col]

    return {
        item: items
            .map(i => cache[i])
            .filter(
                (i) => (i.title === match.params.id)
            ).pop()
    }
})(MovieView)

const ListViewContainer = connect(({collections}, {match, ...props}) => {
    return {
        menu: Object.keys(collections)
    }
})(ListView)

export {ListContainer, ButterSettingsContainer, MovieViewContainer, ListViewContainer}

@@ -314,23 +314,75 @@
 nst 
-ListContainer =
+collectionConnect = ((mapStateToProps, mapDispatchToProps) =%3E (%0A   
  con
@@ -386,21 +386,16 @@
 connect(
-%0A    
 (%7Bcollec
@@ -395,24 +395,34 @@
 %7Bcollections
+, ...state
 %7D, %7Blocation
@@ -421,23 +421,33 @@
 location
+, ...props
 %7D) =%3E 
-%7B
+(
 %0A       
@@ -451,110 +451,286 @@
     
-const %7Bitems, cache, isFetching, failed%7D = collections%5BlocationToKey(location)%5D%0A%0A        return %7B%0A    
+mapStateToProps(%7B%0A            ...collections%5BlocationToKey(location)%5D,%0A            ...state%0A        %7D, %7B%0A            ...props,%0A            location%0A        %7D)%0A    ), mapDispatchToProps)%0A))%0A%0Aconst ListContainer = collectionConnect(%0A    (%7Bitems, cache, isFetching, failed%7D) =%3E (%7B%0A
     
@@ -774,20 +774,16 @@
         
-    
 isFetchi
@@ -786,20 +786,16 @@
 tching,%0A
-    
         
@@ -810,19 +810,10 @@
     
-    %7D%0A    
 %7D
+)
 ,%0A  

split out collectionConnect