forked from AkkomaGang/akkoma-fe
Use hoc definitions to be factor of factory
This commit is contained in:
parent
8f608e060c
commit
f81b82b471
4 changed files with 22 additions and 24 deletions
|
@ -10,21 +10,19 @@ import MuteCard from '../mute_card/mute_card.vue'
|
||||||
import withSubscription from '../../hocs/with_subscription/with_subscription'
|
import withSubscription from '../../hocs/with_subscription/with_subscription'
|
||||||
import withList from '../../hocs/with_list/with_list'
|
import withList from '../../hocs/with_list/with_list'
|
||||||
|
|
||||||
const BlockList = withList(BlockCard, userId => ({ userId }))
|
const BlockList = withList({ getEntryProps: userId => ({ userId }) })(BlockCard)
|
||||||
const BlockListWithSubscription = withSubscription(
|
const BlockListWithSubscription = withSubscription({
|
||||||
BlockList,
|
fetch: (props, $store) => $store.dispatch('fetchBlocks'),
|
||||||
(props, $store) => $store.dispatch('fetchBlocks'),
|
select: (props, $store) => get($store.state.users.currentUser, 'blockIds', []),
|
||||||
(props, $store) => get($store.state.users.currentUser, 'blockIds', []),
|
contentPropName: 'entries'
|
||||||
'entries'
|
})(BlockList)
|
||||||
)
|
|
||||||
|
|
||||||
const MuteList = withList(MuteCard, userId => ({ userId }))
|
const MuteList = withList({ getEntryProps: userId => ({ userId }) })(MuteCard)
|
||||||
const MuteListWithSubscription = withSubscription(
|
const MuteListWithSubscription = withSubscription({
|
||||||
MuteList,
|
fetch: (props, $store) => $store.dispatch('fetchMutes'),
|
||||||
(props, $store) => $store.dispatch('fetchMutes'),
|
select: (props, $store) => get($store.state.users.currentUser, 'muteIds', []),
|
||||||
(props, $store) => get($store.state.users.currentUser, 'muteIds', []),
|
contentPropName: 'entries'
|
||||||
'entries'
|
})(MuteList)
|
||||||
)
|
|
||||||
|
|
||||||
const UserSettings = {
|
const UserSettings = {
|
||||||
data () {
|
data () {
|
||||||
|
|
|
@ -4,8 +4,8 @@ import map from 'lodash/map'
|
||||||
const defaultEntryPropsGetter = entry => ({ entry })
|
const defaultEntryPropsGetter = entry => ({ entry })
|
||||||
const defaultKeyGetter = entry => entry.id
|
const defaultKeyGetter = entry => entry.id
|
||||||
|
|
||||||
const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter) => {
|
const withList = ({ getEntryProps = defaultEntryPropsGetter, getKey = defaultKeyGetter }) => (ItemComponent) => (
|
||||||
return Vue.component('withList', {
|
Vue.component('withList', {
|
||||||
render (createElement) {
|
render (createElement) {
|
||||||
return (
|
return (
|
||||||
<div class="with-list">
|
<div class="with-list">
|
||||||
|
@ -18,13 +18,13 @@ const withList = (Component, getEntryProps = defaultEntryPropsGetter, getKey = d
|
||||||
},
|
},
|
||||||
on: this.$props.entryListeners
|
on: this.$props.entryListeners
|
||||||
}
|
}
|
||||||
return <Component {...props} />
|
return <ItemComponent {...props} />
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
props: ['entries', 'entryProps', 'entryListeners']
|
props: ['entries', 'entryProps', 'entryListeners']
|
||||||
})
|
})
|
||||||
}
|
)
|
||||||
|
|
||||||
export default withList
|
export default withList
|
||||||
|
|
|
@ -3,8 +3,8 @@ import filter from 'lodash/filter'
|
||||||
import isEmpty from 'lodash/isEmpty'
|
import isEmpty from 'lodash/isEmpty'
|
||||||
import './with_load_more.scss'
|
import './with_load_more.scss'
|
||||||
|
|
||||||
const withLoadMore = (Component, fetch, select, entriesPropName = 'entries') => {
|
const withLoadMore = ({ fetch, select, entriesPropName = 'entries' }) => (WrappedComponent) => {
|
||||||
const originalProps = Component.props || []
|
const originalProps = WrappedComponent.props || []
|
||||||
const props = filter(originalProps, v => v !== 'entries')
|
const props = filter(originalProps, v => v !== 'entries')
|
||||||
|
|
||||||
return Vue.component('withLoadMore', {
|
return Vue.component('withLoadMore', {
|
||||||
|
@ -18,7 +18,7 @@ const withLoadMore = (Component, fetch, select, entriesPropName = 'entries') =>
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div class="with-load-more">
|
<div class="with-load-more">
|
||||||
<Component {...props} />
|
<WrappedComponent {...props} />
|
||||||
<div class="with-load-more-footer">
|
<div class="with-load-more-footer">
|
||||||
{this.error && <a onClick={this.fetchEntries} class="alert error">{this.$t('general.generic_error')}</a>}
|
{this.error && <a onClick={this.fetchEntries} class="alert error">{this.$t('general.generic_error')}</a>}
|
||||||
{!this.error && this.loading && <i class="icon-spin3 animate-spin"/>}
|
{!this.error && this.loading && <i class="icon-spin3 animate-spin"/>}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import isEmpty from 'lodash/isEmpty'
|
||||||
import omit from 'lodash/omit'
|
import omit from 'lodash/omit'
|
||||||
import './with_subscription.scss'
|
import './with_subscription.scss'
|
||||||
|
|
||||||
const withSubscription = (Component, fetch, select, contentPropName = 'content') => {
|
const withSubscription = ({ fetch, select, contentPropName = 'content' }) => (WrapperComponent) => {
|
||||||
const originalProps = Component.props || []
|
const originalProps = WrapperComponent.props || []
|
||||||
const props = reject(originalProps, v => v === 'content')
|
const props = reject(originalProps, v => v === 'content')
|
||||||
|
|
||||||
return Vue.component('withSubscription', {
|
return Vue.component('withSubscription', {
|
||||||
|
@ -19,7 +19,7 @@ const withSubscription = (Component, fetch, select, contentPropName = 'content')
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div class="with-subscription">
|
<div class="with-subscription">
|
||||||
{!this.error && !this.loading && <Component {...props} />}
|
{!this.error && !this.loading && <WrapperComponent {...props} />}
|
||||||
<div class="with-subscription-footer">
|
<div class="with-subscription-footer">
|
||||||
{this.error && <a onClick={this.fetchData} class="alert error">{this.$t('general.generic_error')}</a>}
|
{this.error && <a onClick={this.fetchData} class="alert error">{this.$t('general.generic_error')}</a>}
|
||||||
{!this.error && this.loading && <i class="icon-spin3 animate-spin"/>}
|
{!this.error && this.loading && <i class="icon-spin3 animate-spin"/>}
|
||||||
|
|
Loading…
Reference in a new issue