@@ -5,14 +5,15 @@ import React, { useState, useLayoutEffect, useEffect, useRef } from "react";
55import { Router , useLocation , Redirect } from "@reach/router" ;
66import Challenges from "./containers/Challenges" ;
77import Filter from "./containers/Filter" ;
8+ import MyGigsFilter from "./containers/MyGigsFilter" ;
89import MyGigs from "./containers/MyGigs" ;
910import Menu from "./components/Menu" ;
1011import { disableSidebarForRoute } from "@topcoder/micro-frontends-navbar-app" ;
1112import * as constants from "./constants" ;
1213import actions from "./actions" ;
1314import * as utils from "./utils" ;
1415import store from "./store" ;
15- import { initialChallengeFilter } from "./reducers/filter" ;
16+ import { initialChallengeFilter , initialGigFilter } from "./reducers/filter" ;
1617import _ from "lodash" ;
1718import { usePreviousLocation } from "./utils/hooks" ;
1819import { useSelector } from "react-redux" ;
@@ -49,7 +50,7 @@ const App = () => {
4950 const location = useLocation ( ) ;
5051 const previousLocation = usePreviousLocation ( ) ;
5152
52- const getChallengesDebounced = useRef ( _ . debounce ( ( f ) => f ( ) , 500 ) ) ;
53+ const getDataDebounced = useRef ( _ . debounce ( ( f ) => f ( ) , 500 ) ) ;
5354
5455 useEffect ( ( ) => {
5556 store . dispatch ( actions . lookup . checkIsLoggedIn ( ) ) ;
@@ -77,12 +78,44 @@ const App = () => {
7778 if ( diff ) {
7879 store . dispatch ( actions . filter . updateFilter ( updatedFilter ) ) ;
7980 }
80- getChallengesDebounced . current ( ( ) =>
81+ getDataDebounced . current ( ( ) =>
8182 store . dispatch ( actions . challenges . getChallenges ( updatedFilter ) )
8283 ) ;
8384 }
8485 } , [ location ] ) ;
8586
87+ useEffect ( ( ) => {
88+ if ( location . pathname === "/earn/my-gigs" && isLoggedIn ) {
89+ if ( ! location . search ) {
90+ store . dispatch (
91+ actions . myGigs . getMyGigs (
92+ constants . GIGS_FILTER_STATUSES_PARAM [ initialGigFilter . status ]
93+ )
94+ ) ;
95+ return ;
96+ }
97+ const params = utils . url . parseUrlQuery ( location . search ) ;
98+ if ( _ . keys ( params ) . length == 1 && params . externalId ) {
99+ return ;
100+ }
101+ const updatedGigFilter = {
102+ status : params . status || "Open Applications" ,
103+ } ;
104+ const currentGig = store . getState ( ) . filter . gig ;
105+ const diff = ! _ . isEqual ( updatedGigFilter , currentGig ) ;
106+ if ( diff ) {
107+ store . dispatch ( actions . filter . updateGigFilter ( updatedGigFilter ) ) ;
108+ }
109+ getDataDebounced . current ( ( ) =>
110+ store . dispatch (
111+ actions . myGigs . getMyGigs (
112+ constants . GIGS_FILTER_STATUSES_PARAM [ updatedGigFilter . status ]
113+ )
114+ )
115+ ) ;
116+ }
117+ } , [ location , isLoggedIn ] ) ;
118+
86119 const varsRef = useRef ( ) ;
87120 varsRef . current = { previousLocation } ;
88121
@@ -111,7 +144,8 @@ const App = () => {
111144 < div className = "sidebar-content" >
112145 { menu }
113146 < hr />
114- < Filter />
147+ { location . pathname === "/earn/find/challenges" && < Filter /> }
148+ { location . pathname === "/earn/my-gigs" && < MyGigsFilter /> }
115149 </ div >
116150 < div className = "sidebar-footer" >
117151 < a
0 commit comments