File tree Expand file tree Collapse file tree 3 files changed +29
-14
lines changed Expand file tree Collapse file tree 3 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import { FeedbackButton, showMenu } from "@topcoder/micro-frontends-earn-app";
9
9
import actions from "../../actions" ;
10
10
import * as utils from "../../utils" ;
11
11
import store from "../../store" ;
12
- import { initialChallengeFilter } from "../..// reducers/filter" ;
12
+ import { initialChallengeFilter } from "../../reducers/filter" ;
13
13
import _ from "lodash" ;
14
14
15
15
import "react-date-range/dist/theme/default.css" ;
@@ -29,12 +29,19 @@ const App = () => {
29
29
30
30
useEffect ( ( ) => {
31
31
if ( ! location . search ) {
32
- const filterChange = utils . challenge . createEmptyChallengeFilter ( ) ;
33
- store . dispatch ( actions . filter . clearChallengeFilter ( filterChange ) ) ;
34
- store . dispatch ( actions . challenges . getChallengesInit ( ) ) ;
35
- store . dispatch (
36
- actions . challenges . getChallengesDone ( initialChallengeFilter )
37
- ) ;
32
+ const currentFilter = store . getState ( ) . filter . challenge ;
33
+ const diff = ! _ . isEqual ( initialChallengeFilter , currentFilter ) ;
34
+
35
+ if ( diff ) {
36
+ const params = utils . challenge . createChallengeParams ( currentFilter ) ;
37
+ utils . url . updateQuery ( params , true ) ;
38
+ } else {
39
+ store . dispatch ( actions . challenges . getChallengesInit ( ) ) ;
40
+ store . dispatch (
41
+ actions . challenges . getChallengesDone ( currentFilter )
42
+ ) ;
43
+ }
44
+
38
45
return ;
39
46
}
40
47
Original file line number Diff line number Diff line change @@ -5,20 +5,24 @@ import * as utils from "../utils";
5
5
export default function appInit ( ) {
6
6
let initialQuery ;
7
7
let urlPath ;
8
+ let firstMounted = true ;
8
9
9
10
function bootstrap ( ) {
10
11
return Promise . resolve ( ) . then ( ( ) => {
11
12
initialQuery = window . location . search ;
12
- urlPath = window . location . pathname ;
13
+ urlPath = utils . url . removeTrailingSlash ( window . location . pathname ) ;
13
14
} ) ;
14
15
}
15
16
16
17
async function mount ( ) {
17
18
try {
18
- if ( initialQuery ) {
19
- const params = utils . url . parseUrlQuery ( initialQuery ) ;
20
- const filter = utils . challenge . createChallengeFilter ( params ) ;
21
- store . dispatch ( action . initApp ( filter ) ) ;
19
+ if ( firstMounted ) {
20
+ if ( initialQuery && urlPath === '/earn/find/challenges' ) {
21
+ const params = utils . url . parseUrlQuery ( initialQuery ) ;
22
+ const filter = utils . challenge . createChallengeFilter ( params ) ;
23
+ store . dispatch ( action . initApp ( filter ) ) ;
24
+ }
25
+ firstMounted = false ;
22
26
}
23
27
} catch ( error ) {
24
28
console . error ( error )
Original file line number Diff line number Diff line change @@ -37,12 +37,16 @@ export function parseUrlQuery(queryString) {
37
37
return params
38
38
}
39
39
40
- export function updateQuery ( params ) {
40
+ export function updateQuery ( params , replace = false ) {
41
41
const oldQuery = decodeURIComponent ( window . location . search ) ;
42
42
let query = buildQueryString ( params ) ;
43
43
query = `?${ query . substring ( 1 ) . split ( "&" ) . sort ( ) . join ( "&" ) } ` ;
44
44
if ( query !== oldQuery ) {
45
- window . history . pushState ( window . history . state , "" , query ) ;
45
+ if ( replace ) {
46
+ window . history . replaceState ( window . history . state , "" , query ) ;
47
+ } else {
48
+ window . history . pushState ( window . history . state , "" , query ) ;
49
+ }
46
50
}
47
51
}
48
52
You can’t perform that action at this time.
0 commit comments