Skip to content

Commit e8aa084

Browse files
committed
fix/projects.unit.test and reverting changes made in AddToCollectionList, AddToCollectionSketchList and Legal components
1 parent 48c4d97 commit e8aa084

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

client/modules/IDE/actions/projects.unit.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { rest } from 'msw';
55

66
import * as ProjectActions from './projects';
77
import * as ActionTypes from '../../../constants';
8+
import { startLoader, stopLoader } from '../reducers/loading';
89
import {
910
initialTestState,
1011
mockProjects
@@ -33,9 +34,9 @@ describe('projects action creator tests', () => {
3334
store = mockStore(initialTestState);
3435

3536
const expectedActions = [
36-
{ type: 'loading/startLoader' },
37+
{ type: startLoader.type },
3738
{ type: ActionTypes.SET_PROJECTS, projects: mockProjects },
38-
{ type: 'loading/stopLoader' }
39+
{ type: stopLoader.type }
3940
];
4041

4142
return store

client/modules/IDE/components/AddToCollectionList.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
2-
import React, { useEffect } from 'react';
2+
import React, { useEffect, useState } from 'react';
33
import { Helmet } from 'react-helmet';
44
import { useTranslation } from 'react-i18next';
55
import { useDispatch, useSelector } from 'react-redux';
@@ -13,7 +13,6 @@ import {
1313
import getSortedCollections from '../selectors/collections';
1414
import QuickAddList from './QuickAddList';
1515
import { remSize } from '../../../theme';
16-
import { startLoader, stopLoader } from '../reducers/loading';
1716

1817
export const CollectionAddSketchWrapper = styled.div`
1918
width: ${remSize(600)};
@@ -30,14 +29,20 @@ export const QuickAddWrapper = styled.div`
3029

3130
const AddToCollectionList = ({ projectId }) => {
3231
const { t } = useTranslation();
32+
3333
const dispatch = useDispatch();
34+
3435
const username = useSelector((state) => state.user.username);
36+
3537
const collections = useSelector(getSortedCollections);
38+
39+
// TODO: improve loading state
3640
const loading = useSelector((state) => state.loading);
41+
const [hasLoadedData, setHasLoadedData] = useState(false);
42+
const showLoader = loading && !hasLoadedData;
3743

3844
useEffect(() => {
39-
dispatch(startLoader());
40-
dispatch(getCollections(username)).then(() => dispatch(stopLoader()));
45+
dispatch(getCollections(username)).then(() => setHasLoadedData(true));
4146
}, [dispatch, username]);
4247

4348
const handleCollectionAdd = (collection) => {
@@ -55,7 +60,7 @@ const AddToCollectionList = ({ projectId }) => {
5560
}));
5661

5762
const getContent = () => {
58-
if (loading) {
63+
if (showLoader) {
5964
return <Loader />;
6065
} else if (collections.length === 0) {
6166
return t('AddToCollectionList.Empty');

client/modules/IDE/components/AddToCollectionSketchList.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
2-
import React, { useEffect } from 'react';
2+
import React, { useEffect, useState } from 'react';
33
import { Helmet } from 'react-helmet';
44
import { useDispatch, useSelector } from 'react-redux';
55
import { useTranslation } from 'react-i18next';
@@ -12,18 +12,23 @@ import {
1212
CollectionAddSketchWrapper,
1313
QuickAddWrapper
1414
} from './AddToCollectionList';
15-
import { startLoader, stopLoader } from '../reducers/loading';
1615

1716
const AddToCollectionSketchList = ({ collection }) => {
1817
const { t } = useTranslation();
18+
1919
const dispatch = useDispatch();
20+
2021
const username = useSelector((state) => state.user.username);
22+
2123
const sketches = useSelector(getSortedSketches);
24+
25+
// TODO: improve loading state
2226
const loading = useSelector((state) => state.loading);
27+
const [hasLoadedData, setHasLoadedData] = useState(false);
28+
const showLoader = loading && !hasLoadedData;
2329

2430
useEffect(() => {
25-
dispatch(startLoader());
26-
dispatch(getProjects(username)).then(() => dispatch(stopLoader()));
31+
dispatch(getProjects(username)).then(() => setHasLoadedData(true));
2732
}, [dispatch, username]);
2833

2934
const handleCollectionAdd = (sketch) => {
@@ -43,7 +48,7 @@ const AddToCollectionSketchList = ({ collection }) => {
4348
}));
4449

4550
const getContent = () => {
46-
if (loading) {
51+
if (showLoader) {
4752
return <Loader />;
4853
} else if (sketches.length === 0) {
4954
// TODO: shouldn't it be NoSketches? -Linda

client/modules/Legal/pages/Legal.jsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import React, { useEffect, useState } from 'react';
44
import Helmet from 'react-helmet';
55
import { useTranslation } from 'react-i18next';
66
import styled from 'styled-components';
7-
import { useDispatch, useSelector } from 'react-redux';
87
import RouterTab from '../../../common/RouterTab';
98
import RootPage from '../../../components/RootPage';
109
import { remSize } from '../../../theme';
1110
import Loader from '../../App/components/loader';
1211
import Nav from '../../IDE/components/Header/Nav';
1312
import PolicyContainer from '../components/PolicyContainer';
14-
import { startLoader, stopLoader } from '../../IDE/reducers/loading';
1513

1614
const StyledTabList = styled.nav`
1715
display: flex;
@@ -26,17 +24,15 @@ const StyledTabList = styled.nav`
2624

2725
function Legal({ policyFile, title }) {
2826
const { t } = useTranslation();
29-
const loading = useSelector((state) => state.loading);
30-
const dispatch = useDispatch();
27+
const [isLoading, setIsLoading] = useState(true);
3128
const [policy, setPolicy] = useState('');
3229

3330
useEffect(() => {
34-
dispatch(startLoader());
3531
axios.get(policyFile).then((response) => {
36-
dispatch(stopLoader());
3732
setPolicy(response.data);
33+
setIsLoading(false);
3834
});
39-
}, [dispatch, policyFile]);
35+
}, [policyFile]);
4036

4137
return (
4238
<RootPage>
@@ -55,7 +51,7 @@ function Legal({ policyFile, title }) {
5551
</ul>
5652
</StyledTabList>
5753
<PolicyContainer policy={policy} />
58-
{loading && <Loader />}
54+
{isLoading && <Loader />}
5955
</RootPage>
6056
);
6157
}

0 commit comments

Comments
 (0)