11import PropTypes from 'prop-types' ;
2- import React , { useEffect , useState } from 'react' ;
2+ import React , { useEffect } from 'react' ;
33import { Helmet } from 'react-helmet' ;
44import { useTranslation } from 'react-i18next' ;
55import { useDispatch , useSelector } from 'react-redux' ;
@@ -13,6 +13,7 @@ import {
1313import getSortedCollections from '../selectors/collections' ;
1414import QuickAddList from './QuickAddList' ;
1515import { remSize } from '../../../theme' ;
16+ import { startLoader , stopLoader } from '../reducers/loading' ;
1617
1718export const CollectionAddSketchWrapper = styled . div `
1819 width: ${ remSize ( 600 ) } ;
@@ -29,20 +30,14 @@ export const QuickAddWrapper = styled.div`
2930
3031const AddToCollectionList = ( { projectId } ) => {
3132 const { t } = useTranslation ( ) ;
32-
3333 const dispatch = useDispatch ( ) ;
34-
3534 const username = useSelector ( ( state ) => state . user . username ) ;
36-
3735 const collections = useSelector ( getSortedCollections ) ;
38-
39- // TODO: improve loading state
4036 const loading = useSelector ( ( state ) => state . loading ) ;
41- const [ hasLoadedData , setHasLoadedData ] = useState ( false ) ;
42- const showLoader = loading && ! hasLoadedData ;
4337
4438 useEffect ( ( ) => {
45- dispatch ( getCollections ( username ) ) . then ( ( ) => setHasLoadedData ( true ) ) ;
39+ dispatch ( startLoader ( ) ) ;
40+ dispatch ( getCollections ( username ) ) . then ( ( ) => dispatch ( stopLoader ( ) ) ) ;
4641 } , [ dispatch , username ] ) ;
4742
4843 const handleCollectionAdd = ( collection ) => {
@@ -60,7 +55,7 @@ const AddToCollectionList = ({ projectId }) => {
6055 } ) ) ;
6156
6257 const getContent = ( ) => {
63- if ( showLoader ) {
58+ if ( loading ) {
6459 return < Loader /> ;
6560 } else if ( collections . length === 0 ) {
6661 return t ( 'AddToCollectionList.Empty' ) ;
0 commit comments