@@ -8,7 +8,8 @@ import Loading from "../../components/Loading";
88import Empty from "../../components/Empty" ;
99import JobListing from "./JobListing" ;
1010import actions from "../../actions" ;
11- import * as utils from "../../utils" ;
11+ import * as constants from "../../constants" ;
12+ // import * as utils from "../../utils";
1213
1314import UpdateGigProfile from "./modals/UpdateGigProfile" ;
1415import UpdateSuccess from "./modals/UpdateSuccess" ;
@@ -21,6 +22,10 @@ const MyGigs = ({
2122 loadMore,
2223 total,
2324 numLoaded,
25+ myActiveGigs,
26+ myOpenGigs,
27+ myCompletedGigs,
28+ myArchivedGigs,
2429 profile,
2530 getProfile,
2631 updateProfile,
@@ -29,26 +34,22 @@ const MyGigs = ({
2934 checkingGigs,
3035 startCheckingGigs,
3136 gigStatus,
37+ loadingMyGigs,
3238} ) => {
33- const location = useLocation ( ) ;
34- const params = utils . url . parseUrlQuery ( location . search ) ;
39+ // const location = useLocation();
40+ // const params = utils.url.parseUrlQuery(location.search);
3541 const propsRef = useRef ( ) ;
3642 propsRef . current = {
3743 getMyGigs,
3844 getProfile,
3945 getAllCountries,
4046 startCheckingGigs,
41- params,
47+ // params,
4248 } ;
4349
4450 useEffect ( ( ) => {
4551 propsRef . current . getProfile ( ) ;
4652 propsRef . current . getAllCountries ( ) ;
47- if ( propsRef . current . params . externalId ) {
48- propsRef . current . startCheckingGigs ( propsRef . current . params . externalId ) ;
49- } else {
50- // propsRef.current.getMyGigs();
51- }
5253 } , [ ] ) ;
5354
5455 const isInitialMount = useRef ( true ) ;
@@ -64,6 +65,22 @@ const MyGigs = ({
6465
6566 const [ openUpdateProfile , setOpenUpdateProfile ] = useState ( false ) ;
6667 const [ openUpdateSuccess , setOpenUpdateSuccess ] = useState ( false ) ;
68+ const [ currentGigs , setCurrentGigs ] = useState ( { } ) ;
69+
70+ useEffect ( ( ) => {
71+ if ( gigStatus == constants . GIGS_FILTER_STATUSES . ACTIVE_JOBS ) {
72+ setCurrentGigs ( myActiveGigs ) ;
73+ }
74+ if ( gigStatus == constants . GIGS_FILTER_STATUSES . OPEN_JOBS ) {
75+ setCurrentGigs ( myOpenGigs ) ;
76+ }
77+ if ( gigStatus == constants . GIGS_FILTER_STATUSES . COMPLETED_JOBS ) {
78+ setCurrentGigs ( myCompletedGigs ) ;
79+ }
80+ if ( gigStatus == constants . GIGS_FILTER_STATUSES . ARCHIVED_JOBS ) {
81+ setCurrentGigs ( myArchivedGigs ) ;
82+ }
83+ } , [ gigStatus , myActiveGigs , myOpenGigs , myCompletedGigs , myArchivedGigs ] ) ;
6784
6885 useEffect ( ( ) => {
6986 if ( updateProfileSuccess ) {
@@ -99,19 +116,22 @@ const MyGigs = ({
99116 </ Button >
100117 </ div >
101118 </ h1 >
102- { ! checkingGigs && myGigs && myGigs . length == 0 && (
103- < Empty gigStatus = { gigStatus } />
104- ) }
105- { ! checkingGigs && myGigs && myGigs . length > 0 && (
106- < JobListing
107- gigStatus = { gigStatus }
108- jobs = { myGigs }
109- loadMore = { loadMore }
110- total = { total }
111- numLoaded = { numLoaded }
112- />
113- ) }
114- { checkingGigs && < Loading /> }
119+ { ! checkingGigs &&
120+ ! loadingMyGigs &&
121+ currentGigs . myGigs &&
122+ currentGigs . myGigs . length == 0 && < Empty gigStatus = { gigStatus } /> }
123+ { ! checkingGigs &&
124+ currentGigs . myGigs &&
125+ currentGigs . myGigs . length > 0 && (
126+ < JobListing
127+ gigStatus = { gigStatus }
128+ jobs = { currentGigs . myGigs }
129+ loadMore = { loadMore }
130+ total = { currentGigs . total }
131+ numLoaded = { currentGigs . numLoaded }
132+ />
133+ ) }
134+ { checkingGigs || ( loadingMyGigs && ! currentGigs . myGigs && < Loading /> ) }
115135 </ div >
116136 < Modal open = { openUpdateProfile } >
117137 < UpdateGigProfile
@@ -150,6 +170,11 @@ MyGigs.propTypes = {
150170 getAllCountries : PT . func ,
151171 checkingGigs : PT . bool ,
152172 startCheckingGigs : PT . func ,
173+ myActiveGigs : PT . shape ( ) ,
174+ myOpenGigs : PT . shape ( ) ,
175+ myCompletedGigs : PT . shape ( ) ,
176+ myArchivedGigs : PT . shape ( ) ,
177+ loadingMyGigs : PT . bool ,
153178} ;
154179
155180const mapStateToProps = ( state ) => ( {
@@ -158,6 +183,11 @@ const mapStateToProps = (state) => ({
158183 myGigs : state . myGigs . myGigs ,
159184 total : state . myGigs . total ,
160185 numLoaded : state . myGigs . numLoaded ,
186+ loadingMyGigs : state . myGigs . loadingMyGigs ,
187+ myActiveGigs : state . myGigs [ constants . GIGS_FILTER_STATUSES . ACTIVE_JOBS ] ,
188+ myOpenGigs : state . myGigs [ constants . GIGS_FILTER_STATUSES . OPEN_JOBS ] ,
189+ myCompletedGigs : state . myGigs [ constants . GIGS_FILTER_STATUSES . COMPLETED_JOBS ] ,
190+ myArchivedGigs : state . myGigs [ constants . GIGS_FILTER_STATUSES . ARCHIVED_JOBS ] ,
161191 profile : state . myGigs . profile ,
162192 updateProfileSuccess : state . myGigs . updatingProfileSucess ,
163193} ) ;
0 commit comments