Skip to content

Commit 290a34f

Browse files
authored
Merge pull request #3270 from processing/fix/collection-view
Update Collection View
2 parents 9ff3624 + 35c8b4f commit 290a34f

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

Diff for: client/modules/User/components/Collection.jsx

+8-12
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,14 @@ import ArrowDownIcon from '../../../images/sort-arrow-down.svg';
1313
import CollectionMetadata from './CollectionMetadata';
1414
import CollectionItemRow from './CollectionItemRow';
1515

16-
const Collection = ({ collectionId }) => {
16+
const Collection = ({ collectionId, username }) => {
1717
const { t } = useTranslation();
1818
const dispatch = useDispatch();
1919

20-
const { user, collection, sorting, loading, username } = useSelector(
21-
(state) => ({
22-
user: state.user,
23-
collection: getCollection(state, collectionId),
24-
sorting: state.sorting,
25-
loading: state.loading,
26-
username: state.user.username
27-
})
28-
);
20+
const user = useSelector((state) => state.user);
21+
const collection = useSelector((state) => getCollection(state, collectionId));
22+
const sorting = useSelector((state) => state.sorting);
23+
const loading = useSelector((state) => state.loading);
2924

3025
useEffect(() => {
3126
dispatch(CollectionsActions.getCollections(username));
@@ -34,7 +29,7 @@ const Collection = ({ collectionId }) => {
3429

3530
const isOwner = () =>
3631
user != null &&
37-
user.username &&
32+
typeof user.username !== 'undefined' &&
3833
collection?.owner?.username === user.username;
3934

4035
const hasCollection = () => !!collection;
@@ -160,7 +155,8 @@ const Collection = ({ collectionId }) => {
160155
};
161156

162157
Collection.propTypes = {
163-
collectionId: PropTypes.string.isRequired
158+
collectionId: PropTypes.string.isRequired,
159+
username: PropTypes.string.isRequired
164160
};
165161

166162
export default Collection;

Diff for: client/modules/User/components/CollectionItemRow.jsx

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import { Link } from 'react-router-dom';
44
import { useTranslation } from 'react-i18next';
5+
import { useDispatch } from 'react-redux';
6+
import { removeFromCollection } from '../../IDE/actions/collections';
57
import dates from '../../../utils/formatDate';
68
import RemoveIcon from '../../../images/close.svg';
79

8-
const CollectionItemRow = ({
9-
collection,
10-
item,
11-
isOwner,
12-
removeFromCollection
13-
}) => {
10+
const CollectionItemRow = ({ collection, item, isOwner }) => {
1411
const { t } = useTranslation();
12+
const dispatch = useDispatch();
1513
const projectIsDeleted = item.isDeleted;
16-
1714
const handleSketchRemove = () => {
1815
const name = projectIsDeleted ? 'deleted sketch' : item.project.name;
1916

@@ -22,7 +19,7 @@ const CollectionItemRow = ({
2219
t('Collection.DeleteFromCollection', { name_sketch: name })
2320
)
2421
) {
25-
removeFromCollection(collection.id, item.projectId);
22+
dispatch(removeFromCollection(collection.id, item.projectId));
2623
}
2724
};
2825

@@ -75,10 +72,9 @@ CollectionItemRow.propTypes = {
7572
user: PropTypes.shape({
7673
username: PropTypes.string.isRequired
7774
})
78-
}).isRequired
75+
})
7976
}).isRequired,
80-
isOwner: PropTypes.bool.isRequired,
81-
removeFromCollection: PropTypes.func.isRequired
77+
isOwner: PropTypes.bool.isRequired
8278
};
8379

8480
export default CollectionItemRow;

0 commit comments

Comments
 (0)