mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-14 15:09:59 -04:00
Include if user projects are already in the studio
This commit is contained in:
parent
968afdb412
commit
43eb9e4e91
3 changed files with 13 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
import keyMirror from 'keymirror';
|
||||
import api from '../../../lib/api';
|
||||
import {selectUsername} from '../../../redux/session';
|
||||
import {userProjects} from './redux-modules';
|
||||
import {userProjects, projects} from './redux-modules';
|
||||
|
||||
const Errors = keyMirror({
|
||||
NETWORK: null,
|
||||
|
@ -40,7 +40,12 @@ const loadUserProjects = type => ((dispatch, getState) => {
|
|||
}, (err, body, res) => {
|
||||
const error = normalizeError(err, body, res);
|
||||
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 = ({
|
|||
id={project.id}
|
||||
title={project.title}
|
||||
image={project.image}
|
||||
inStudio={project.inStudio}
|
||||
onAdd={onAdd}
|
||||
onRemove={onRemove}
|
||||
/>
|
||||
|
@ -92,7 +93,8 @@ UserProjectsModal.propTypes = {
|
|||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
id: PropTypes.id,
|
||||
image: PropTypes.string,
|
||||
title: PropTypes.string
|
||||
title: PropTypes.string,
|
||||
inStudio: PropTypes.bool
|
||||
})),
|
||||
loading: PropTypes.bool,
|
||||
error: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
||||
|
|
|
@ -3,9 +3,9 @@ import React, {useState} from 'react';
|
|||
import PropTypes from 'prop-types';
|
||||
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 [added, setAdded] = useState(false);
|
||||
const [added, setAdded] = useState(inStudio);
|
||||
const [error, setError] = useState(null);
|
||||
const toggle = () => {
|
||||
setSubmitting(true);
|
||||
|
@ -50,6 +50,7 @@ UserProjectsTile.propTypes = {
|
|||
id: PropTypes.number.isRequired,
|
||||
title: PropTypes.string.isRequired,
|
||||
image: PropTypes.string.isRequired,
|
||||
inStudio: PropTypes.bool.isRequired,
|
||||
onAdd: PropTypes.func.isRequired,
|
||||
onRemove: PropTypes.func.isRequired
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue