Show empty state when no collections
This commit is contained in:
parent
7137c7bd73
commit
f928665737
2 changed files with 48 additions and 29 deletions
|
@ -9,27 +9,13 @@ import getSortedCollections from '../../selectors/collections';
|
||||||
|
|
||||||
import exitUrl from '../../../../images/exit.svg';
|
import exitUrl from '../../../../images/exit.svg';
|
||||||
|
|
||||||
|
import Loader from '../../../App/components/loader';
|
||||||
import { Searchbar } from '../Searchbar';
|
import { Searchbar } from '../Searchbar';
|
||||||
import Item from './Item';
|
import Item from './Item';
|
||||||
|
|
||||||
// const reducer = () => {
|
|
||||||
// switch ()
|
|
||||||
// case 'noItems':
|
|
||||||
// return 'NoCollections';
|
|
||||||
// case
|
|
||||||
// }
|
|
||||||
|
|
||||||
const NoCollections = () => (
|
const NoCollections = () => (
|
||||||
<div>
|
<div className="collection-popover__empty">
|
||||||
<p>No collections</p>
|
<p>No collections</p>
|
||||||
{/* <p>
|
|
||||||
<Link
|
|
||||||
to="/andrewn/collections/create"
|
|
||||||
className="searchbar__clear-button"
|
|
||||||
onClick={() => {}}
|
|
||||||
>Create
|
|
||||||
</Link>
|
|
||||||
</p> */}
|
|
||||||
</div>);
|
</div>);
|
||||||
|
|
||||||
const projectInCollection = (project, collection) => (
|
const projectInCollection = (project, collection) => (
|
||||||
|
@ -38,8 +24,9 @@ const projectInCollection = (project, collection) => (
|
||||||
|
|
||||||
|
|
||||||
const CollectionPopover = ({
|
const CollectionPopover = ({
|
||||||
onClose, project, collections, addToCollection, removeFromCollection, getCollections, user
|
loading, onClose, project, collections, addToCollection, removeFromCollection, getCollections, user
|
||||||
}) => {
|
}) => {
|
||||||
|
const [didLoadData, setDidLoadData] = React.useState(null);
|
||||||
const [searchTerm, setSearchTerm] = React.useState('');
|
const [searchTerm, setSearchTerm] = React.useState('');
|
||||||
const filteredCollections = searchTerm === '' ?
|
const filteredCollections = searchTerm === '' ?
|
||||||
collections :
|
collections :
|
||||||
|
@ -49,6 +36,18 @@ const CollectionPopover = ({
|
||||||
getCollections(user.username);
|
getCollections(user.username);
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (didLoadData === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading && didLoadData === null) {
|
||||||
|
setDidLoadData(false);
|
||||||
|
} else if (!loading && didLoadData === false) {
|
||||||
|
setDidLoadData(true);
|
||||||
|
}
|
||||||
|
}, [loading]);
|
||||||
|
|
||||||
const handleAddToCollection = (collectionId) => {
|
const handleAddToCollection = (collectionId) => {
|
||||||
addToCollection(collectionId, project.id);
|
addToCollection(collectionId, project.id);
|
||||||
};
|
};
|
||||||
|
@ -57,6 +56,29 @@ const CollectionPopover = ({
|
||||||
removeFromCollection(collectionId, project.id);
|
removeFromCollection(collectionId, project.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let content = null;
|
||||||
|
|
||||||
|
if (didLoadData && collections.length === 0) {
|
||||||
|
content = <NoCollections />;
|
||||||
|
} else if (didLoadData) {
|
||||||
|
content = (
|
||||||
|
<ul>
|
||||||
|
{
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
content = <Loader />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="collection-popover">
|
<div className="collection-popover">
|
||||||
<div className="collection-popover__header">
|
<div className="collection-popover__header">
|
||||||
|
@ -71,24 +93,14 @@ const CollectionPopover = ({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="collection-popover__items">
|
<div className="collection-popover__items">
|
||||||
<ul>
|
{content}
|
||||||
{
|
|
||||||
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>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
CollectionPopover.propTypes = {
|
CollectionPopover.propTypes = {
|
||||||
|
loading: PropTypes.bool.isRequired,
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
getCollections: PropTypes.func.isRequired,
|
getCollections: PropTypes.func.isRequired,
|
||||||
addToCollection: PropTypes.func.isRequired,
|
addToCollection: PropTypes.func.isRequired,
|
||||||
|
|
|
@ -86,3 +86,10 @@
|
||||||
.collection-popover__item__view-button {
|
.collection-popover__item__view-button {
|
||||||
@extend %button;
|
@extend %button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.collection-popover__empty {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue