Skip to content

Commit 610548c

Browse files
Merge branch 'develop' into develop
2 parents de635b9 + e7914d7 commit 610548c

File tree

9 files changed

+97
-200
lines changed

9 files changed

+97
-200
lines changed

client/constants.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ export const CLEAR_PERSISTED_STATE = 'CLEAR_PERSISTED_STATE';
130130

131131
export const HIDE_RUNTIME_ERROR_WARNING = 'HIDE_RUNTIME_ERROR_WARNING';
132132
export const SHOW_RUNTIME_ERROR_WARNING = 'SHOW_RUNTIME_ERROR_WARNING';
133-
export const SET_ASSETS = 'SET_ASSETS';
134-
export const DELETE_ASSET = 'DELETE_ASSET';
135133

136134
export const TOGGLE_DIRECTION = 'TOGGLE_DIRECTION';
137135
export const SET_SORTING = 'SET_SORTING';

client/modules/IDE/actions/assets.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import apiClient from '../../../utils/apiClient';
22
import * as ActionTypes from '../../../constants';
33
import { startLoader, stopLoader } from './loader';
4+
import { assetsActions } from '../reducers/assets';
45

5-
function setAssets(assets, totalSize) {
6-
return {
7-
type: ActionTypes.SET_ASSETS,
8-
assets,
9-
totalSize
10-
};
11-
}
6+
const { setAssets, deleteAsset } = assetsActions;
127

138
export function getAssets() {
149
return async (dispatch) => {
@@ -26,13 +21,6 @@ export function getAssets() {
2621
};
2722
}
2823

29-
export function deleteAsset(assetKey) {
30-
return {
31-
type: ActionTypes.DELETE_ASSET,
32-
key: assetKey
33-
};
34-
}
35-
3624
export function deleteAssetRequest(assetKey) {
3725
return async (dispatch) => {
3826
try {

client/modules/IDE/actions/collections.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { setToastText, showToast } from './toast';
66

77
const TOAST_DISPLAY_TIME_MS = 1500;
88

9-
// eslint-disable-next-line
109
export function getCollections(username) {
1110
return (dispatch) => {
1211
dispatch(startLoader());
@@ -16,8 +15,7 @@ export function getCollections(username) {
1615
} else {
1716
url = '/collections';
1817
}
19-
console.log(url);
20-
apiClient
18+
return apiClient
2119
.get(url)
2220
.then((response) => {
2321
dispatch({
Lines changed: 55 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import PropTypes from 'prop-types';
2-
import React from 'react';
2+
import React, { useEffect, useState } from 'react';
33
import { Helmet } from 'react-helmet';
4-
import { connect } from 'react-redux';
5-
import { bindActionCreators } from 'redux';
6-
import { withTranslation } from 'react-i18next';
4+
import { useTranslation } from 'react-i18next';
5+
import { useDispatch, useSelector } from 'react-redux';
76
import styled from 'styled-components';
8-
import * as ProjectActions from '../actions/project';
9-
import * as ProjectsActions from '../actions/projects';
10-
import * as CollectionsActions from '../actions/collections';
11-
import * as ToastActions from '../actions/toast';
12-
import * as SortingActions from '../actions/sorting';
13-
import getSortedCollections from '../selectors/collections';
147
import Loader from '../../App/components/loader';
8+
import {
9+
addToCollection,
10+
getCollections,
11+
removeFromCollection
12+
} from '../actions/collections';
13+
import getSortedCollections from '../selectors/collections';
1514
import QuickAddList from './QuickAddList';
1615
import { remSize } from '../../../theme';
1716

18-
const projectInCollection = (project, collection) =>
19-
collection.items.find((item) => item.projectId === project.id) != null;
20-
2117
export const CollectionAddSketchWrapper = styled.div`
2218
width: ${remSize(600)};
2319
max-width: 100%;
@@ -31,166 +27,67 @@ export const QuickAddWrapper = styled.div`
3127
height: 100%;
3228
`;
3329

34-
class CollectionList extends React.Component {
35-
constructor(props) {
36-
super(props);
30+
const AddToCollectionList = ({ projectId }) => {
31+
const { t } = useTranslation();
3732

38-
if (props.projectId) {
39-
props.getProject(props.projectId);
40-
}
33+
const dispatch = useDispatch();
4134

42-
this.props.getCollections(this.props.user.username);
35+
const username = useSelector((state) => state.user.username);
4336

44-
this.state = {
45-
hasLoadedData: false
46-
};
47-
}
37+
const collections = useSelector(getSortedCollections);
4838

49-
componentDidUpdate(prevProps) {
50-
if (prevProps.loading === true && this.props.loading === false) {
51-
// eslint-disable-next-line react/no-did-update-set-state
52-
this.setState({
53-
hasLoadedData: true
54-
});
55-
}
56-
}
39+
// TODO: improve loading state
40+
const loading = useSelector((state) => state.loading);
41+
const [hasLoadedData, setHasLoadedData] = useState(false);
42+
const showLoader = loading && !hasLoadedData;
5743

58-
getTitle() {
59-
if (this.props.username === this.props.user.username) {
60-
return this.props.t('AddToCollectionList.Title');
61-
}
62-
return this.props.t('AddToCollectionList.AnothersTitle', {
63-
anotheruser: this.props.username
64-
});
65-
}
44+
useEffect(() => {
45+
dispatch(getCollections(username)).then(() => setHasLoadedData(true));
46+
}, [dispatch, username]);
6647

67-
handleCollectionAdd = (collection) => {
68-
this.props.addToCollection(collection.id, this.props.project.id);
48+
const handleCollectionAdd = (collection) => {
49+
dispatch(addToCollection(collection.id, projectId));
6950
};
7051

71-
handleCollectionRemove = (collection) => {
72-
this.props.removeFromCollection(collection.id, this.props.project.id);
52+
const handleCollectionRemove = (collection) => {
53+
dispatch(removeFromCollection(collection.id, projectId));
7354
};
7455

75-
render() {
76-
const { collections, project } = this.props;
77-
const hasCollections = collections.length > 0;
78-
const collectionWithSketchStatus = collections.map((collection) => ({
79-
...collection,
80-
url: `/${collection.owner.username}/collections/${collection.id}`,
81-
isAdded: projectInCollection(project, collection)
82-
}));
83-
84-
let content = null;
85-
86-
if (this.props.loading && !this.state.hasLoadedData) {
87-
content = <Loader />;
88-
} else if (hasCollections) {
89-
content = (
90-
<QuickAddList
91-
items={collectionWithSketchStatus}
92-
onAdd={this.handleCollectionAdd}
93-
onRemove={this.handleCollectionRemove}
94-
t={this.props.t}
95-
/>
96-
);
97-
} else {
98-
content = this.props.t('AddToCollectionList.Empty');
56+
const collectionWithSketchStatus = collections.map((collection) => ({
57+
...collection,
58+
url: `/${collection.owner.username}/collections/${collection.id}`,
59+
isAdded: collection.items.some((item) => item.projectId === projectId)
60+
}));
61+
62+
const getContent = () => {
63+
if (showLoader) {
64+
return <Loader />;
65+
} else if (collections.length === 0) {
66+
return t('AddToCollectionList.Empty');
9967
}
100-
10168
return (
102-
<CollectionAddSketchWrapper>
103-
<QuickAddWrapper>
104-
<Helmet>
105-
<title>{this.getTitle()}</title>
106-
</Helmet>
107-
{content}
108-
</QuickAddWrapper>
109-
</CollectionAddSketchWrapper>
69+
<QuickAddList
70+
items={collectionWithSketchStatus}
71+
onAdd={handleCollectionAdd}
72+
onRemove={handleCollectionRemove}
73+
/>
11074
);
111-
}
112-
}
113-
114-
const ProjectShape = PropTypes.shape({
115-
id: PropTypes.string.isRequired,
116-
name: PropTypes.string.isRequired,
117-
createdAt: PropTypes.string.isRequired,
118-
updatedAt: PropTypes.string.isRequired,
119-
user: PropTypes.shape({
120-
username: PropTypes.string.isRequired
121-
}).isRequired
122-
});
123-
124-
const ItemsShape = PropTypes.shape({
125-
createdAt: PropTypes.string.isRequired,
126-
updatedAt: PropTypes.string.isRequired,
127-
project: ProjectShape
128-
});
75+
};
12976

130-
CollectionList.propTypes = {
131-
user: PropTypes.shape({
132-
username: PropTypes.string,
133-
authenticated: PropTypes.bool.isRequired
134-
}).isRequired,
135-
projectId: PropTypes.string.isRequired,
136-
getCollections: PropTypes.func.isRequired,
137-
getProject: PropTypes.func.isRequired,
138-
addToCollection: PropTypes.func.isRequired,
139-
removeFromCollection: PropTypes.func.isRequired,
140-
collections: PropTypes.arrayOf(
141-
PropTypes.shape({
142-
id: PropTypes.string.isRequired,
143-
name: PropTypes.string.isRequired,
144-
description: PropTypes.string,
145-
createdAt: PropTypes.string.isRequired,
146-
updatedAt: PropTypes.string.isRequired,
147-
items: PropTypes.arrayOf(ItemsShape)
148-
})
149-
).isRequired,
150-
username: PropTypes.string,
151-
loading: PropTypes.bool.isRequired,
152-
project: PropTypes.shape({
153-
id: PropTypes.string,
154-
owner: PropTypes.shape({
155-
id: PropTypes.string
156-
})
157-
}),
158-
t: PropTypes.func.isRequired
77+
return (
78+
<CollectionAddSketchWrapper>
79+
<QuickAddWrapper>
80+
<Helmet>
81+
<title>{t('AddToCollectionList.Title')}</title>
82+
</Helmet>
83+
{getContent()}
84+
</QuickAddWrapper>
85+
</CollectionAddSketchWrapper>
86+
);
15987
};
16088

161-
CollectionList.defaultProps = {
162-
project: {
163-
id: undefined,
164-
owner: undefined
165-
},
166-
username: undefined
89+
AddToCollectionList.propTypes = {
90+
projectId: PropTypes.string.isRequired
16791
};
16892

169-
function mapStateToProps(state, ownProps) {
170-
return {
171-
user: state.user,
172-
collections: getSortedCollections(state),
173-
sorting: state.sorting,
174-
loading: state.loading,
175-
project: ownProps.project || state.project,
176-
projectId: ownProps && ownProps.params ? ownProps.prams.project_id : null
177-
};
178-
}
179-
180-
function mapDispatchToProps(dispatch) {
181-
return bindActionCreators(
182-
Object.assign(
183-
{},
184-
CollectionsActions,
185-
ProjectsActions,
186-
ProjectActions,
187-
ToastActions,
188-
SortingActions
189-
),
190-
dispatch
191-
);
192-
}
193-
194-
export default withTranslation()(
195-
connect(mapStateToProps, mapDispatchToProps)(CollectionList)
196-
);
93+
export default AddToCollectionList;

client/modules/IDE/components/IDEOverlays.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ export default function IDEOverlays() {
7878
actions={<CollectionSearchbar />}
7979
isFixedHeight
8080
>
81-
<AddToCollectionList
82-
projectId={params.project_id}
83-
username={params.username}
84-
/>
81+
<AddToCollectionList projectId={params.project_id} />
8582
</Overlay>
8683
)}
8784
{shareModalVisible && (

client/modules/IDE/components/SketchList.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ class SketchList extends React.Component {
418418
}
419419
>
420420
<AddToCollectionList
421-
project={this.state.sketchToAddToCollection}
422-
username={this.props.username}
423-
user={this.props.user}
421+
projectId={this.state.sketchToAddToCollection.id}
424422
/>
425423
</Overlay>
426424
)}

client/modules/IDE/pages/IDEView.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const IDEView = () => {
102102
const [consoleSize, setConsoleSize] = useState(150);
103103
const [sidebarSize, setSidebarSize] = useState(160);
104104
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
105+
const [MaxSize, setMaxSize] = useState(window.innerWidth);
105106

106107
const cmRef = useRef({});
107108

@@ -146,6 +147,17 @@ const IDEView = () => {
146147
}
147148
};
148149
}, [shouldAutosave, dispatch]);
150+
useEffect(() => {
151+
const updateInnerWidth = (e) => {
152+
setMaxSize(e.target.innerWidth);
153+
};
154+
155+
window.addEventListener('resize', updateInnerWidth);
156+
157+
return () => {
158+
window.removeEventListener('resize', updateInnerWidth);
159+
};
160+
}, [setMaxSize]);
149161

150162
const consoleCollapsedSize = 29;
151163
const currentConsoleSize = ide.consoleIsExpanded
@@ -179,6 +191,7 @@ const IDEView = () => {
179191
<Sidebar />
180192
<SplitPane
181193
split="vertical"
194+
maxSize={MaxSize * 0.965}
182195
defaultSize="50%"
183196
onChange={() => {
184197
setIsOverlayVisible(true);

0 commit comments

Comments
 (0)