Skip to content

Commit 4d0aa23

Browse files
committed
Display Add Sketches Overlay from Collection List
1 parent a2da26d commit 4d0aa23

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

client/modules/IDE/components/CollectionList/CollectionList.jsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import InlineSVG from 'react-inlinesvg';
55
import { connect } from 'react-redux';
66
import { bindActionCreators } from 'redux';
77
import classNames from 'classnames';
8+
import find from 'lodash/find';
89
import * as ProjectActions from '../../actions/project';
910
import * as ProjectsActions from '../../actions/projects';
1011
import * as CollectionsActions from '../../actions/collections';
1112
import * as ToastActions from '../../actions/toast';
1213
import * as SortingActions from '../../actions/sorting';
1314
import getSortedCollections from '../../selectors/collections';
1415
import Loader from '../../../App/components/loader';
16+
import Overlay from '../../../App/components/Overlay';
17+
import AddToCollectionSketchList from '../AddToCollectionSketchList';
18+
import { SketchSearchbar } from '../Searchbar';
19+
1520
import CollectionListRow from './CollectionListRow';
1621

1722
const arrowUp = require('../../../../images/sort-arrow-up.svg');
@@ -27,14 +32,14 @@ class CollectionList extends React.Component {
2732

2833
this.props.getCollections(this.props.username);
2934
this.props.resetSorting();
30-
this._renderFieldHeader = this._renderFieldHeader.bind(this);
3135

3236
this.state = {
3337
hasLoadedData: false,
38+
addingSketchesToCollectionId: null,
3439
};
3540
}
3641

37-
componentDidUpdate(prevProps) {
42+
componentDidUpdate(prevProps, prevState) {
3843
if (prevProps.loading === true && this.props.loading === false) {
3944
// eslint-disable-next-line react/no-did-update-set-state
4045
this.setState({
@@ -50,6 +55,19 @@ class CollectionList extends React.Component {
5055
return `p5.js Web Editor | ${this.props.username}'s collections`;
5156
}
5257

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+
5371
hasCollections() {
5472
return (!this.props.loading || this.state.hasLoadedData) && this.props.collections.length > 0;
5573
}
@@ -66,7 +84,7 @@ class CollectionList extends React.Component {
6684
return null;
6785
}
6886

69-
_renderFieldHeader(fieldName, displayName) {
87+
_renderFieldHeader = (fieldName, displayName) => {
7088
const { field, direction } = this.props.sorting;
7189
const headerClass = classNames({
7290
'sketches-table__header': true,
@@ -117,9 +135,19 @@ class CollectionList extends React.Component {
117135
user={this.props.user}
118136
username={username}
119137
project={this.props.project}
138+
onAddSketches={() => this.showAddSketches(collection.id)}
120139
/>))}
121140
</tbody>
122141
</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+
}
123151
</div>
124152
);
125153
}

client/modules/IDE/components/CollectionList/CollectionListRow.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class CollectionListRowBase extends React.Component {
6767
});
6868
}
6969

70+
handleAddSketches = () => {
71+
this.closeAll();
72+
this.props.onAddSketches();
73+
}
74+
7075
handleDropdownOpen = () => {
7176
this.closeAll();
7277
this.openOptions();
@@ -105,7 +110,6 @@ class CollectionListRowBase extends React.Component {
105110
});
106111
}
107112

108-
109113
renderActions = () => {
110114
const { optionsOpen } = this.state;
111115
const userIsOwner = this.props.user.username === this.props.username;
@@ -124,6 +128,16 @@ class CollectionListRowBase extends React.Component {
124128
<ul
125129
className="sketch-list__action-dialogue"
126130
>
131+
<li>
132+
<button
133+
className="sketch-list__action-option"
134+
onClick={this.handleAddSketches}
135+
onBlur={this.onBlurComponent}
136+
onFocus={this.onFocusComponent}
137+
>
138+
Add sketches
139+
</button>
140+
</li>
127141
{userIsOwner &&
128142
<li>
129143
<button
@@ -217,6 +231,7 @@ CollectionListRowBase.propTypes = {
217231
}).isRequired,
218232
deleteCollection: PropTypes.func.isRequired,
219233
editCollection: PropTypes.func.isRequired,
234+
onAddSketches: PropTypes.func.isRequired,
220235
};
221236

222237
function mapDispatchToPropsSketchListRow(dispatch) {

0 commit comments

Comments
 (0)