11import PropTypes from 'prop-types' ;
22import React , { useEffect } from 'react' ;
33import { useDispatch , useSelector } from 'react-redux' ;
4- import { Link } from 'react-router-dom' ;
54import { Helmet } from 'react-helmet' ;
65import { useTranslation } from 'react-i18next' ;
76import classNames from 'classnames' ;
@@ -12,88 +11,7 @@ import Loader from '../../App/components/loader';
1211import ArrowUpIcon from '../../../images/sort-arrow-up.svg' ;
1312import ArrowDownIcon from '../../../images/sort-arrow-down.svg' ;
1413import CollectionMetadata from './CollectionMetadata' ;
15- import dates from '../../../utils/formatDate' ;
16- import RemoveIcon from '../../../images/close.svg' ;
17-
18- const CollectionItemRow = ( { item, isOwner, collection, user } ) => {
19- const { t } = useTranslation ( ) ;
20- const dispatch = useDispatch ( ) ;
21- const formatDateCell = ( date , mobile = false ) =>
22- dates . format ( date , { showTime : ! mobile } ) ;
23- const handleSketchRemove = ( ) => {
24- dispatch (
25- CollectionsActions . removeFromCollection ( collection . id , item . projectId )
26- ) ;
27- } ;
28-
29- const projectIsDeleted = item . isDeleted ;
30- const projectIsPrivate =
31- ! item . isDeleted && ! isOwner && item . project ?. visibility === 'Private' ;
32-
33- let name ;
34- if ( projectIsDeleted ) {
35- name = < span > { t ( 'Collection.SketchDeleted' ) } </ span > ;
36- } else if ( projectIsPrivate ) {
37- name = < span > Sketch is Private</ span > ;
38- } else {
39- name = (
40- < Link to = { `/${ item . project . user . username } /sketches/${ item . projectId } ` } >
41- { item . project . name }
42- </ Link >
43- ) ;
44- }
45-
46- const sketchOwnerUsername =
47- projectIsDeleted || projectIsPrivate ? null : item . project . user . username ;
48-
49- return (
50- < tr
51- className = { `sketches-table__row ${
52- projectIsDeleted || projectIsPrivate ? 'is-deleted-or-private' : ''
53- } `}
54- >
55- < th scope = "row" > { name } </ th >
56- < td > { formatDateCell ( item . createdAt ) } </ td >
57- < td > { sketchOwnerUsername } </ td >
58- < td className = "collection-row__action-column" >
59- { isOwner && (
60- < button
61- className = "collection-row__remove-button"
62- onClick = { handleSketchRemove }
63- aria-label = { t ( 'Collection.SketchRemoveARIA' ) }
64- >
65- < RemoveIcon focusable = "false" aria-hidden = "true" />
66- </ button >
67- ) }
68- </ td >
69- </ tr >
70- ) ;
71- } ;
72-
73- CollectionItemRow . propTypes = {
74- collection : PropTypes . shape ( {
75- id : PropTypes . string . isRequired ,
76- name : PropTypes . string . isRequired
77- } ) . isRequired ,
78- item : PropTypes . shape ( {
79- createdAt : PropTypes . string . isRequired ,
80- projectId : PropTypes . string . isRequired ,
81- isDeleted : PropTypes . bool . isRequired ,
82- project : PropTypes . shape ( {
83- id : PropTypes . string . isRequired ,
84- name : PropTypes . string . isRequired ,
85- visibility : PropTypes . string ,
86- user : PropTypes . shape ( {
87- username : PropTypes . string . isRequired
88- } )
89- } ) . isRequired
90- } ) . isRequired ,
91- isOwner : PropTypes . bool . isRequired ,
92- user : PropTypes . shape ( {
93- username : PropTypes . string ,
94- authenticated : PropTypes . bool . isRequired
95- } ) . isRequired
96- } ;
14+ import CollectionItemRow from './CollectionItemRow' ;
9715
9816const Collection = ( { collectionId, username } ) => {
9917 const { t } = useTranslation ( ) ;
@@ -177,7 +95,6 @@ const Collection = ({ collectionId, username }) => {
17795 ) : (
17896 < ArrowDownIcon
17997 role = "img"
180- IST
18198 aria-label = { t ( 'Collection.DirectionDescendingARIA' ) }
18299 />
183100 ) ) }
0 commit comments