2018-10-18 16:45:24 -04:00
|
|
|
const connect = require('react-redux').connect;
|
|
|
|
|
|
|
|
const previewActions = require('../../redux/preview.js');
|
|
|
|
const AddToStudioModal = require('../../components/modal/addtostudio/container.jsx');
|
|
|
|
|
|
|
|
// Build consolidated curatedStudios object from all studio info.
|
|
|
|
// We add flags to indicate whether the project is currently in the studio,
|
|
|
|
// and the status of requests to join/leave studios.
|
2019-01-17 11:22:00 -05:00
|
|
|
const consolidateStudiosInfo = (curatedStudios, projectStudios, currentStudioIds, studioRequests) => {
|
2018-10-18 16:45:24 -04:00
|
|
|
const consolidatedStudios = [];
|
|
|
|
|
|
|
|
projectStudios.forEach(projectStudio => {
|
2019-01-17 11:22:00 -05:00
|
|
|
const includesProject = (currentStudioIds.indexOf(projectStudio.id) !== -1);
|
|
|
|
const consolidatedStudio =
|
|
|
|
Object.assign({}, projectStudio, {includesProject: includesProject});
|
|
|
|
consolidatedStudios.push(consolidatedStudio);
|
2018-10-18 16:45:24 -04:00
|
|
|
});
|
|
|
|
|
2019-01-17 11:22:00 -05:00
|
|
|
// copy the curated studios that project is not in
|
2018-10-18 16:45:24 -04:00
|
|
|
curatedStudios.forEach(curatedStudio => {
|
|
|
|
if (!projectStudios.some(projectStudio => (projectStudio.id === curatedStudio.id))) {
|
2019-01-17 11:22:00 -05:00
|
|
|
const includesProject = (currentStudioIds.indexOf(curatedStudio.id) !== -1);
|
|
|
|
const consolidatedStudio =
|
|
|
|
Object.assign({}, curatedStudio, {includesProject: includesProject});
|
|
|
|
consolidatedStudios.push(consolidatedStudio);
|
2018-10-18 16:45:24 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// set studio state to hasRequestOutstanding==true if it's being fetched,
|
|
|
|
// false if it's not
|
|
|
|
consolidatedStudios.forEach(consolidatedStudio => {
|
|
|
|
const id = consolidatedStudio.id;
|
|
|
|
consolidatedStudio.hasRequestOutstanding =
|
|
|
|
((id in studioRequests) &&
|
2019-01-17 11:22:00 -05:00
|
|
|
(studioRequests[id] === previewActions.Status.FETCHING));
|
2018-10-18 16:45:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
return consolidatedStudios;
|
|
|
|
};
|
|
|
|
|
2019-01-17 11:22:00 -05:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
studios: consolidateStudiosInfo(state.preview.curatedStudios,
|
|
|
|
state.preview.projectStudios, state.preview.currentStudioIds,
|
|
|
|
state.preview.status.studioRequests)
|
2018-10-18 16:45:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = () => ({});
|
|
|
|
|
|
|
|
const ConnectedAddToStudioModal = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(AddToStudioModal);
|
|
|
|
|
|
|
|
module.exports = ConnectedAddToStudioModal;
|