@@ -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" ;
@@ -38,6 +39,9 @@ const App = () => {
3839 selected = { selectedMenuItem }
3940 onSelect = { ( item ) => {
4041 setSelectedMenuItem ( item ) ;
42+ if ( item == "Gigs" ) {
43+ window . location . href = `${ process . env . URL . BASE } /gigs` ;
44+ }
4145 } }
4246 isLoggedIn = { isLoggedIn }
4347 />
@@ -46,7 +50,7 @@ const App = () => {
4650 const location = useLocation ( ) ;
4751 const previousLocation = usePreviousLocation ( ) ;
4852
49- const getChallengesDebounced = useRef ( _ . debounce ( ( f ) => f ( ) , 500 ) ) ;
53+ const getDataDebounced = useRef ( _ . debounce ( ( f ) => f ( ) , 500 ) ) ;
5054
5155 useEffect ( ( ) => {
5256 store . dispatch ( actions . lookup . checkIsLoggedIn ( ) ) ;
@@ -74,12 +78,44 @@ const App = () => {
7478 if ( diff ) {
7579 store . dispatch ( actions . filter . updateFilter ( updatedFilter ) ) ;
7680 }
77- getChallengesDebounced . current ( ( ) =>
81+ getDataDebounced . current ( ( ) =>
7882 store . dispatch ( actions . challenges . getChallenges ( updatedFilter ) )
7983 ) ;
8084 }
8185 } , [ location ] ) ;
8286
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+
83119 const varsRef = useRef ( ) ;
84120 varsRef . current = { previousLocation } ;
85121
@@ -108,7 +144,8 @@ const App = () => {
108144 < div className = "sidebar-content" >
109145 { menu }
110146 < hr />
111- < Filter />
147+ { location . pathname === "/earn/find/challenges" && < Filter /> }
148+ { location . pathname === "/earn/my-gigs" && < MyGigsFilter /> }
112149 </ div >
113150 < div className = "sidebar-footer" >
114151 < a
0 commit comments