@@ -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,46 @@ 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 ( actions . filter . updateGigFilter ( initialGigFilter ) ) ;
91+
92+ store . dispatch (
93+ actions . myGigs . getMyGigs (
94+ constants . GIGS_FILTER_STATUSES_PARAM [ initialGigFilter . status ]
95+ )
96+ ) ;
97+ return ;
98+ }
99+ const params = utils . url . parseUrlQuery ( location . search ) ;
100+ if ( _ . keys ( params ) . length == 1 && params . externalId ) {
101+ return ;
102+ }
103+ const updatedGigFilter = {
104+ status : params . status || "Open Applications" ,
105+ } ;
106+ const currentGig = store . getState ( ) . filter . gig ;
107+ const diff = ! _ . isEqual ( updatedGigFilter , currentGig ) ;
108+ if ( diff ) {
109+ store . dispatch ( actions . filter . updateGigFilter ( updatedGigFilter ) ) ;
110+ }
111+ getDataDebounced . current ( ( ) =>
112+ store . dispatch (
113+ actions . myGigs . getMyGigs (
114+ constants . GIGS_FILTER_STATUSES_PARAM [ updatedGigFilter . status ]
115+ )
116+ )
117+ ) ;
118+ }
119+ } , [ location , isLoggedIn ] ) ;
120+
83121 const varsRef = useRef ( ) ;
84122 varsRef . current = { previousLocation } ;
85123
@@ -108,7 +146,8 @@ const App = () => {
108146 < div className = "sidebar-content" >
109147 { menu }
110148 < hr />
111- < Filter />
149+ { location . pathname === "/earn/find/challenges" && < Filter /> }
150+ { location . pathname === "/earn/my-gigs" && < MyGigsFilter /> }
112151 </ div >
113152 < div className = "sidebar-footer" >
114153 < a
0 commit comments