2021-03-16 14:58:54 -04:00
|
|
|
import React, {useEffect, useCallback} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2021-03-09 15:24:45 -05:00
|
|
|
import {useParams} from 'react-router-dom';
|
2021-03-16 14:15:16 -04:00
|
|
|
import {connect} from 'react-redux';
|
|
|
|
|
2021-03-16 14:58:54 -04:00
|
|
|
import {curators, managers} from './lib/redux-modules';
|
|
|
|
import {curatorFetcher, managerFetcher} from './lib/fetchers';
|
2021-03-16 14:15:16 -04:00
|
|
|
import Debug from './debug.jsx';
|
2021-03-09 15:24:45 -05:00
|
|
|
|
|
|
|
const StudioCurators = () => {
|
|
|
|
const {studioId} = useParams();
|
|
|
|
return (
|
|
|
|
<div>
|
2021-03-16 14:15:16 -04:00
|
|
|
<h3>Managers</h3>
|
|
|
|
<ManagerList studioId={studioId} />
|
|
|
|
<hr />
|
|
|
|
<h3>Curators</h3>
|
|
|
|
<CuratorList studioId={studioId} />
|
2021-03-09 15:24:45 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-03-16 14:15:16 -04:00
|
|
|
const MemberList = ({studioId, items, error, loading, moreToLoad, onLoadMore}) => {
|
|
|
|
useEffect(() => {
|
|
|
|
if (studioId && items.length === 0) onLoadMore(studioId, 0);
|
|
|
|
}, [studioId]);
|
2021-03-16 14:58:54 -04:00
|
|
|
|
|
|
|
const handleLoadMore = useCallback(() => onLoadMore(studioId, items.length), [studioId, items.length]);
|
2021-03-16 14:15:16 -04:00
|
|
|
|
2021-03-16 14:58:54 -04:00
|
|
|
return (<React.Fragment>
|
|
|
|
{error && <Debug
|
|
|
|
label="Error"
|
|
|
|
data={error}
|
|
|
|
/>}
|
2021-03-16 14:15:16 -04:00
|
|
|
{items.map((item, index) =>
|
2021-03-16 14:58:54 -04:00
|
|
|
(<Debug
|
|
|
|
label="Member"
|
|
|
|
data={item}
|
|
|
|
key={index}
|
|
|
|
/>)
|
2021-03-16 14:15:16 -04:00
|
|
|
)}
|
|
|
|
{loading ? <small>Loading...</small> : (
|
|
|
|
moreToLoad ?
|
2021-03-16 14:58:54 -04:00
|
|
|
<button onClick={handleLoadMore}>
|
2021-03-16 14:15:16 -04:00
|
|
|
Load more
|
|
|
|
</button> :
|
|
|
|
<small>No more to load</small>
|
|
|
|
)}
|
2021-03-16 14:58:54 -04:00
|
|
|
</React.Fragment>);
|
|
|
|
};
|
|
|
|
|
|
|
|
MemberList.propTypes = {
|
|
|
|
studioId: PropTypes.string,
|
|
|
|
items: PropTypes.array, // eslint-disable-line react/forbid-prop-types
|
|
|
|
loading: PropTypes.bool,
|
|
|
|
error: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
|
|
|
moreToLoad: PropTypes.bool,
|
|
|
|
onLoadMore: PropTypes.func
|
2021-03-16 14:15:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const ManagerList = connect(
|
|
|
|
state => managers.selector(state),
|
|
|
|
dispatch => ({
|
|
|
|
onLoadMore: (studioId, offset) => dispatch(
|
|
|
|
managers.actions.loadMore(managerFetcher.bind(null, studioId, offset)))
|
|
|
|
})
|
|
|
|
)(MemberList);
|
|
|
|
|
|
|
|
const CuratorList = connect(
|
|
|
|
state => curators.selector(state),
|
|
|
|
dispatch => ({
|
|
|
|
onLoadMore: (studioId, offset) => dispatch(
|
|
|
|
curators.actions.loadMore(curatorFetcher.bind(null, studioId, offset)))
|
|
|
|
})
|
|
|
|
)(MemberList);
|
|
|
|
|
2021-03-09 15:24:45 -05:00
|
|
|
export default StudioCurators;
|