Commit 43eb9e4e authored by Paul Kaplan's avatar Paul Kaplan

Include if user projects are already in the studio

parent 968afdb4
import keyMirror from 'keymirror'; import keyMirror from 'keymirror';
import api from '../../../lib/api'; import api from '../../../lib/api';
import {selectUsername} from '../../../redux/session'; import {selectUsername} from '../../../redux/session';
import {userProjects} from './redux-modules'; import {userProjects, projects} from './redux-modules';
const Errors = keyMirror({ const Errors = keyMirror({
NETWORK: null, NETWORK: null,
...@@ -40,7 +40,12 @@ const loadUserProjects = type => ((dispatch, getState) => { ...@@ -40,7 +40,12 @@ const loadUserProjects = type => ((dispatch, getState) => {
}, (err, body, res) => { }, (err, body, res) => {
const error = normalizeError(err, body, res); const error = normalizeError(err, body, res);
if (error) return dispatch(userProjects.actions.error(error)); if (error) return dispatch(userProjects.actions.error(error));
dispatch(userProjects.actions.append(body, body.length === projectsPerPage)); const moreToLoad = body.length === projectsPerPage;
const studioProjectIds = projects.selector(getState()).items.map(item => item.id);
const loadedProjects = body.map(item => Object.assign(item, {
inStudio: studioProjectIds.indexOf(item.id) !== -1
}));
dispatch(userProjects.actions.append(loadedProjects, moreToLoad));
}); });
}); });
......
...@@ -69,6 +69,7 @@ const UserProjectsModal = ({ ...@@ -69,6 +69,7 @@ const UserProjectsModal = ({
id={project.id} id={project.id}
title={project.title} title={project.title}
image={project.image} image={project.image}
inStudio={project.inStudio}
onAdd={onAdd} onAdd={onAdd}
onRemove={onRemove} onRemove={onRemove}
/> />
...@@ -92,7 +93,8 @@ UserProjectsModal.propTypes = { ...@@ -92,7 +93,8 @@ UserProjectsModal.propTypes = {
items: PropTypes.arrayOf(PropTypes.shape({ items: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.id, id: PropTypes.id,
image: PropTypes.string, image: PropTypes.string,
title: PropTypes.string title: PropTypes.string,
inStudio: PropTypes.bool
})), })),
loading: PropTypes.bool, loading: PropTypes.bool,
error: PropTypes.object, // eslint-disable-line react/forbid-prop-types error: PropTypes.object, // eslint-disable-line react/forbid-prop-types
......
...@@ -3,9 +3,9 @@ import React, {useState} from 'react'; ...@@ -3,9 +3,9 @@ import React, {useState} from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
const UserProjectsTile = ({id, title, image, onAdd, onRemove}) => { const UserProjectsTile = ({id, title, image, inStudio, onAdd, onRemove}) => {
const [submitting, setSubmitting] = useState(false); const [submitting, setSubmitting] = useState(false);
const [added, setAdded] = useState(false); const [added, setAdded] = useState(inStudio);
const [error, setError] = useState(null); const [error, setError] = useState(null);
const toggle = () => { const toggle = () => {
setSubmitting(true); setSubmitting(true);
...@@ -50,6 +50,7 @@ UserProjectsTile.propTypes = { ...@@ -50,6 +50,7 @@ UserProjectsTile.propTypes = {
id: PropTypes.number.isRequired, id: PropTypes.number.isRequired,
title: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
image: PropTypes.string.isRequired, image: PropTypes.string.isRequired,
inStudio: PropTypes.bool.isRequired,
onAdd: PropTypes.func.isRequired, onAdd: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired onRemove: PropTypes.func.isRequired
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment