@@ -5,13 +5,18 @@ import InlineSVG from 'react-inlinesvg';
5
5
import { connect } from 'react-redux' ;
6
6
import { bindActionCreators } from 'redux' ;
7
7
import classNames from 'classnames' ;
8
+ import find from 'lodash/find' ;
8
9
import * as ProjectActions from '../../actions/project' ;
9
10
import * as ProjectsActions from '../../actions/projects' ;
10
11
import * as CollectionsActions from '../../actions/collections' ;
11
12
import * as ToastActions from '../../actions/toast' ;
12
13
import * as SortingActions from '../../actions/sorting' ;
13
14
import getSortedCollections from '../../selectors/collections' ;
14
15
import Loader from '../../../App/components/loader' ;
16
+ import Overlay from '../../../App/components/Overlay' ;
17
+ import AddToCollectionSketchList from '../AddToCollectionSketchList' ;
18
+ import { SketchSearchbar } from '../Searchbar' ;
19
+
15
20
import CollectionListRow from './CollectionListRow' ;
16
21
17
22
const arrowUp = require ( '../../../../images/sort-arrow-up.svg' ) ;
@@ -27,14 +32,14 @@ class CollectionList extends React.Component {
27
32
28
33
this . props . getCollections ( this . props . username ) ;
29
34
this . props . resetSorting ( ) ;
30
- this . _renderFieldHeader = this . _renderFieldHeader . bind ( this ) ;
31
35
32
36
this . state = {
33
37
hasLoadedData : false ,
38
+ addingSketchesToCollectionId : null ,
34
39
} ;
35
40
}
36
41
37
- componentDidUpdate ( prevProps ) {
42
+ componentDidUpdate ( prevProps , prevState ) {
38
43
if ( prevProps . loading === true && this . props . loading === false ) {
39
44
// eslint-disable-next-line react/no-did-update-set-state
40
45
this . setState ( {
@@ -50,6 +55,19 @@ class CollectionList extends React.Component {
50
55
return `p5.js Web Editor | ${ this . props . username } 's collections` ;
51
56
}
52
57
58
+ showAddSketches = ( collectionId ) => {
59
+ this . setState ( {
60
+ addingSketchesToCollectionId : collectionId ,
61
+ } ) ;
62
+ }
63
+
64
+ hideAddSketches = ( ) => {
65
+ console . log ( 'hideAddSketches' ) ;
66
+ this . setState ( {
67
+ addingSketchesToCollectionId : null ,
68
+ } ) ;
69
+ }
70
+
53
71
hasCollections ( ) {
54
72
return ( ! this . props . loading || this . state . hasLoadedData ) && this . props . collections . length > 0 ;
55
73
}
@@ -66,7 +84,7 @@ class CollectionList extends React.Component {
66
84
return null ;
67
85
}
68
86
69
- _renderFieldHeader ( fieldName , displayName ) {
87
+ _renderFieldHeader = ( fieldName , displayName ) => {
70
88
const { field, direction } = this . props . sorting ;
71
89
const headerClass = classNames ( {
72
90
'sketches-table__header' : true ,
@@ -117,9 +135,19 @@ class CollectionList extends React.Component {
117
135
user = { this . props . user }
118
136
username = { username }
119
137
project = { this . props . project }
138
+ onAddSketches = { ( ) => this . showAddSketches ( collection . id ) }
120
139
/> ) ) }
121
140
</ tbody >
122
141
</ table > }
142
+ {
143
+ this . state . addingSketchesToCollectionId && (
144
+ < Overlay title = "Add sketches" actions = { < SketchSearchbar /> } closeOverlay = { this . hideAddSketches } isFixedHeight >
145
+ < div className = "collection-add-sketch" >
146
+ < AddToCollectionSketchList username = { this . props . username } collection = { find ( this . props . collections , { id : this . state . addingSketchesToCollectionId } ) } />
147
+ </ div >
148
+ </ Overlay >
149
+ )
150
+ }
123
151
</ div >
124
152
) ;
125
153
}
0 commit comments