From 7b629fdfb74922a810047b79a8e74ea0319986cc Mon Sep 17 00:00:00 2001 From: raclim Date: Thu, 7 Nov 2024 13:53:33 -0500 Subject: [PATCH 1/3] pass username prop --- client/modules/User/components/Collection.jsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/client/modules/User/components/Collection.jsx b/client/modules/User/components/Collection.jsx index 59f89e4a34..b18191ebbd 100644 --- a/client/modules/User/components/Collection.jsx +++ b/client/modules/User/components/Collection.jsx @@ -13,19 +13,16 @@ import ArrowDownIcon from '../../../images/sort-arrow-down.svg'; import CollectionMetadata from './CollectionMetadata'; import CollectionItemRow from './CollectionItemRow'; -const Collection = ({ collectionId }) => { +const Collection = ({ collectionId, username }) => { const { t } = useTranslation(); const dispatch = useDispatch(); - const { user, collection, sorting, loading, username } = useSelector( - (state) => ({ - user: state.user, - collection: getCollection(state, collectionId), - sorting: state.sorting, - loading: state.loading, - username: state.user.username - }) - ); + const { user, collection, sorting, loading } = useSelector((state) => ({ + user: state.user, + collection: getCollection(state, collectionId), + sorting: state.sorting, + loading: state.loading + })); useEffect(() => { dispatch(CollectionsActions.getCollections(username)); @@ -34,7 +31,7 @@ const Collection = ({ collectionId }) => { const isOwner = () => user != null && - user.username && + typeof user.username !== 'undefined' && collection?.owner?.username === user.username; const hasCollection = () => !!collection; @@ -160,7 +157,8 @@ const Collection = ({ collectionId }) => { }; Collection.propTypes = { - collectionId: PropTypes.string.isRequired + collectionId: PropTypes.string.isRequired, + username: PropTypes.string.isRequired }; export default Collection; From 0595b6cc834edf46f0aa045ccb6ba9904b959869 Mon Sep 17 00:00:00 2001 From: raclim Date: Thu, 7 Nov 2024 13:54:07 -0500 Subject: [PATCH 2/3] add removeFromCollection action --- .../User/components/CollectionItemRow.jsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/client/modules/User/components/CollectionItemRow.jsx b/client/modules/User/components/CollectionItemRow.jsx index f34479d468..98017bbc66 100644 --- a/client/modules/User/components/CollectionItemRow.jsx +++ b/client/modules/User/components/CollectionItemRow.jsx @@ -2,18 +2,15 @@ import PropTypes from 'prop-types'; import React from 'react'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; +import { useDispatch } from 'react-redux'; +import { removeFromCollection } from '../../IDE/actions/collections'; import dates from '../../../utils/formatDate'; import RemoveIcon from '../../../images/close.svg'; -const CollectionItemRow = ({ - collection, - item, - isOwner, - removeFromCollection -}) => { +const CollectionItemRow = ({ collection, item, isOwner }) => { const { t } = useTranslation(); + const dispatch = useDispatch(); const projectIsDeleted = item.isDeleted; - const handleSketchRemove = () => { const name = projectIsDeleted ? 'deleted sketch' : item.project.name; @@ -22,7 +19,7 @@ const CollectionItemRow = ({ t('Collection.DeleteFromCollection', { name_sketch: name }) ) ) { - removeFromCollection(collection.id, item.projectId); + dispatch(removeFromCollection(collection.id, item.projectId)); } }; @@ -75,10 +72,9 @@ CollectionItemRow.propTypes = { user: PropTypes.shape({ username: PropTypes.string.isRequired }) - }).isRequired + }) }).isRequired, - isOwner: PropTypes.bool.isRequired, - removeFromCollection: PropTypes.func.isRequired + isOwner: PropTypes.bool.isRequired }; export default CollectionItemRow; From 35c8b4f0e5a855380a5529105ccb7659cb5ed40c Mon Sep 17 00:00:00 2001 From: raclim Date: Thu, 7 Nov 2024 14:24:47 -0500 Subject: [PATCH 3/3] update selectors --- client/modules/User/components/Collection.jsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client/modules/User/components/Collection.jsx b/client/modules/User/components/Collection.jsx index b18191ebbd..197104561f 100644 --- a/client/modules/User/components/Collection.jsx +++ b/client/modules/User/components/Collection.jsx @@ -17,12 +17,10 @@ const Collection = ({ collectionId, username }) => { const { t } = useTranslation(); const dispatch = useDispatch(); - const { user, collection, sorting, loading } = useSelector((state) => ({ - user: state.user, - collection: getCollection(state, collectionId), - sorting: state.sorting, - loading: state.loading - })); + const user = useSelector((state) => state.user); + const collection = useSelector((state) => getCollection(state, collectionId)); + const sorting = useSelector((state) => state.sorting); + const loading = useSelector((state) => state.loading); useEffect(() => { dispatch(CollectionsActions.getCollections(username));