1
1
import PropTypes from 'prop-types' ;
2
- import React , { useEffect , useState } from 'react' ;
2
+ import React , { useEffect } from 'react' ;
3
3
import { Helmet } from 'react-helmet' ;
4
4
import { useTranslation } from 'react-i18next' ;
5
5
import { useDispatch , useSelector } from 'react-redux' ;
@@ -13,6 +13,7 @@ import {
13
13
import getSortedCollections from '../selectors/collections' ;
14
14
import QuickAddList from './QuickAddList' ;
15
15
import { remSize } from '../../../theme' ;
16
+ import { startLoader , stopLoader } from '../reducers/loading' ;
16
17
17
18
export const CollectionAddSketchWrapper = styled . div `
18
19
width: ${ remSize ( 600 ) } ;
@@ -29,20 +30,14 @@ export const QuickAddWrapper = styled.div`
29
30
30
31
const AddToCollectionList = ( { projectId } ) => {
31
32
const { t } = useTranslation ( ) ;
32
-
33
33
const dispatch = useDispatch ( ) ;
34
-
35
34
const username = useSelector ( ( state ) => state . user . username ) ;
36
-
37
35
const collections = useSelector ( getSortedCollections ) ;
38
-
39
- // TODO: improve loading state
40
36
const loading = useSelector ( ( state ) => state . loading ) ;
41
- const [ hasLoadedData , setHasLoadedData ] = useState ( false ) ;
42
- const showLoader = loading && ! hasLoadedData ;
43
37
44
38
useEffect ( ( ) => {
45
- dispatch ( getCollections ( username ) ) . then ( ( ) => setHasLoadedData ( true ) ) ;
39
+ dispatch ( startLoader ( ) ) ;
40
+ dispatch ( getCollections ( username ) ) . then ( ( ) => dispatch ( stopLoader ( ) ) ) ;
46
41
} , [ dispatch , username ] ) ;
47
42
48
43
const handleCollectionAdd = ( collection ) => {
@@ -60,7 +55,7 @@ const AddToCollectionList = ({ projectId }) => {
60
55
} ) ) ;
61
56
62
57
const getContent = ( ) => {
63
- if ( showLoader ) {
58
+ if ( loading ) {
64
59
return < Loader /> ;
65
60
} else if ( collections . length === 0 ) {
66
61
return t ( 'AddToCollectionList.Empty' ) ;
0 commit comments