Show if sketch is in collection and allow removal
This commit is contained in:
parent
ad09ce15ab
commit
7e5613b2b4
3 changed files with 31 additions and 7 deletions
|
@ -7,8 +7,6 @@ import { bindActionCreators } from 'redux';
|
||||||
import * as CollectionsActions from '../../actions/collections';
|
import * as CollectionsActions from '../../actions/collections';
|
||||||
import getSortedCollections from '../../selectors/collections';
|
import getSortedCollections from '../../selectors/collections';
|
||||||
|
|
||||||
// import { Link } from 'react-router';
|
|
||||||
|
|
||||||
import exitUrl from '../../../../images/exit.svg';
|
import exitUrl from '../../../../images/exit.svg';
|
||||||
|
|
||||||
import { Searchbar } from '../Searchbar';
|
import { Searchbar } from '../Searchbar';
|
||||||
|
@ -34,9 +32,13 @@ const NoCollections = () => (
|
||||||
</p> */}
|
</p> */}
|
||||||
</div>);
|
</div>);
|
||||||
|
|
||||||
|
const projectInCollection = (project, collection) => (
|
||||||
|
collection.items.find(item => item.project.id === project.id) != null
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
const CollectionPopover = ({
|
const CollectionPopover = ({
|
||||||
onClose, project, collections, addToCollection, getCollections, user
|
onClose, project, collections, addToCollection, removeFromCollection, getCollections, user
|
||||||
}) => {
|
}) => {
|
||||||
const [searchTerm, setSearchTerm] = React.useState('');
|
const [searchTerm, setSearchTerm] = React.useState('');
|
||||||
const filteredCollections = searchTerm === '' ?
|
const filteredCollections = searchTerm === '' ?
|
||||||
|
@ -51,6 +53,10 @@ const CollectionPopover = ({
|
||||||
addToCollection(collectionId, project.id);
|
addToCollection(collectionId, project.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRemoveFromCollection = (collectionId) => {
|
||||||
|
removeFromCollection(collectionId, project.id);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="collection-popover">
|
<div className="collection-popover">
|
||||||
<div className="collection-popover__header">
|
<div className="collection-popover__header">
|
||||||
|
@ -67,7 +73,14 @@ const CollectionPopover = ({
|
||||||
<div className="collection-popover__items">
|
<div className="collection-popover__items">
|
||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
filteredCollections.map(collection => <Item key={collection.id} collection={collection} onSelect={() => handleAddToCollection(collection.id)} />)
|
filteredCollections.map((collection) => {
|
||||||
|
const inCollection = projectInCollection(project, collection);
|
||||||
|
const handleSelect = inCollection ? handleRemoveFromCollection : handleAddToCollection;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Item inCollection={inCollection} key={collection.id} collection={collection} onSelect={() => handleSelect(collection.id)} />
|
||||||
|
);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -79,6 +92,7 @@ CollectionPopover.propTypes = {
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
getCollections: PropTypes.func.isRequired,
|
getCollections: PropTypes.func.isRequired,
|
||||||
addToCollection: PropTypes.func.isRequired,
|
addToCollection: PropTypes.func.isRequired,
|
||||||
|
removeFromCollection: PropTypes.func.isRequired,
|
||||||
user: PropTypes.shape({
|
user: PropTypes.shape({
|
||||||
username: PropTypes.string.isRequired,
|
username: PropTypes.string.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Link } from 'react-router';
|
import { Link } from 'react-router';
|
||||||
|
import InlineSVG from 'react-inlinesvg';
|
||||||
|
|
||||||
const CollectionItem = ({ collection, onSelect }) => (
|
import check from '../../../../images/check.svg';
|
||||||
|
|
||||||
|
const checkIcon = (
|
||||||
|
<InlineSVG className="sketch-list__check-icon" src={check} alt="In collection" />
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const CollectionItem = ({ inCollection, collection, onSelect }) => (
|
||||||
<li className="collection-popover__item">
|
<li className="collection-popover__item">
|
||||||
<div className="collection-popover__item__info">
|
<div className="collection-popover__item__info">
|
||||||
|
{inCollection && checkIcon}
|
||||||
|
|
||||||
<button onClick={onSelect}>
|
<button onClick={onSelect}>
|
||||||
{collection.name}
|
{collection.name}
|
||||||
</button>
|
</button>
|
||||||
|
@ -17,6 +27,7 @@ const CollectionItem = ({ collection, onSelect }) => (
|
||||||
);
|
);
|
||||||
|
|
||||||
CollectionItem.propTypes = {
|
CollectionItem.propTypes = {
|
||||||
|
inCollection: PropTypes.bool.isRequired,
|
||||||
onSelect: PropTypes.func.isRequired,
|
onSelect: PropTypes.func.isRequired,
|
||||||
collection: PropTypes.shape({
|
collection: PropTypes.shape({
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
|
|
|
@ -66,8 +66,7 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: stretch;
|
align-items: center;
|
||||||
align-items: stretch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.collection-popover__item__info button,
|
.collection-popover__item__info button,
|
||||||
|
|
Loading…
Reference in a new issue