Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit c4b6224

Browse files
author
dengjun
committed
winner output from challenge:30186501
1 parent 533d3c9 commit c4b6224

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2508
-245
lines changed

src/App.jsx

+67-43
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
* Main App component
33
*/
44
import React, { useState, useLayoutEffect, useEffect, useRef } from "react";
5-
import { Router, useLocation, redirectTo } from "@reach/router";
5+
import { Router, useLocation, Redirect } from "@reach/router";
66
import Challenges from "./containers/Challenges";
77
import Filter from "./containers/Filter";
8+
import MyGigs from "./containers/MyGigs";
89
import Menu from "./components/Menu";
910
import { disableSidebarForRoute } from "@topcoder/micro-frontends-navbar-app";
10-
import Button from "./components/Button";
1111
import * as constants from "./constants";
1212
import actions from "./actions";
1313
import * as utils from "./utils";
1414
import store from "./store";
1515
import { initialChallengeFilter } from "./reducers/filter";
1616
import _ from "lodash";
17+
import { usePreviousLocation } from "./utils/hooks";
18+
import { useSelector } from "react-redux";
1719

1820
import "react-date-range/dist/theme/default.css";
1921
import "react-date-range/dist/styles.css";
@@ -23,6 +25,7 @@ import "./styles/main.scss";
2325

2426
const App = () => {
2527
const [selectedMenuItem, setSelectedMenuItem] = useState(null);
28+
const isLoggedIn = useSelector((state) => state.lookup.isLoggedIn);
2629

2730
useLayoutEffect(() => {
2831
disableSidebarForRoute("/earn/*");
@@ -31,42 +34,58 @@ const App = () => {
3134
const menu = (
3235
<Menu
3336
menu={constants.NAV_MENU}
34-
icons={constants.NAV_MENU_ICONS}
3537
selected={selectedMenuItem}
3638
onSelect={(item) => {
3739
setSelectedMenuItem(item);
3840
}}
41+
isLoggedIn={isLoggedIn}
3942
/>
4043
);
4144

4245
const location = useLocation();
46+
const previousLocation = usePreviousLocation();
4347

4448
const getChallengesDebounced = useRef(_.debounce((f) => f(), 500));
4549

4650
useEffect(() => {
47-
if (!location.search) {
48-
store.dispatch(actions.challenges.getChallenges(initialChallengeFilter));
49-
return;
50-
}
51+
store.dispatch(actions.lookup.checkIsLoggedIn());
52+
}, []);
53+
54+
useEffect(() => {
55+
if (location.pathname === "/earn/find/challenges") {
56+
if (!location.search) {
57+
store.dispatch(
58+
actions.challenges.getChallenges(initialChallengeFilter)
59+
);
60+
return;
61+
}
5162

52-
//if (location.pathname === "/earn/find/challenges") {
53-
const params = utils.url.parseUrlQuery(location.search);
54-
const toUpdate = utils.challenge.createChallengeFilter(params);
63+
const params = utils.url.parseUrlQuery(location.search);
64+
const toUpdate = utils.challenge.createChallengeFilter(params);
5565

56-
if (!toUpdate.types) toUpdate.types = [];
57-
if (!toUpdate.tracks) toUpdate.tracks = [];
58-
if (!toUpdate.bucket) toUpdate.bucket = "";
66+
if (!toUpdate.types) toUpdate.types = [];
67+
if (!toUpdate.tracks) toUpdate.tracks = [];
68+
if (!toUpdate.bucket) toUpdate.bucket = "";
5969

60-
const updatedFilter = { ...initialChallengeFilter, ...toUpdate };
61-
const currentFilter = store.getState().filter.challenge;
62-
const diff = !_.isEqual(updatedFilter, currentFilter);
63-
if (diff) {
64-
store.dispatch(actions.filter.updateFilter(updatedFilter));
70+
const updatedFilter = { ...initialChallengeFilter, ...toUpdate };
71+
const currentFilter = store.getState().filter.challenge;
72+
const diff = !_.isEqual(updatedFilter, currentFilter);
73+
if (diff) {
74+
store.dispatch(actions.filter.updateFilter(updatedFilter));
75+
}
76+
getChallengesDebounced.current(() =>
77+
store.dispatch(actions.challenges.getChallenges(updatedFilter))
78+
);
79+
}
80+
}, [location]);
81+
82+
const varsRef = useRef();
83+
varsRef.current = { previousLocation };
84+
85+
useEffect(() => {
86+
if (location.pathname !== varsRef.current.previousLocation.pathname) {
87+
window.scrollTo(0, 0);
6588
}
66-
getChallengesDebounced.current(() =>
67-
store.dispatch(actions.challenges.getChallenges(updatedFilter))
68-
);
69-
//}
7089
}, [location]);
7190

7291
useEffect(() => {
@@ -82,29 +101,34 @@ const App = () => {
82101
}, [location]);
83102

84103
return (
85-
<div className="layout">
86-
<aside className="sidebar">
87-
<div className="sidebar-content">
88-
{menu}
89-
<hr />
90-
<Filter />
91-
</div>
92-
<div className="sidebar-footer">
93-
<a
94-
className="button button-primary"
95-
href="https://github.com/topcoder-platform/micro-frontends-earn-app/issues/new?assignees=&labels=&template=bug_report.md&title="
96-
target="_blank"
97-
>
98-
GIVE APPLICATION FEEDBACK
99-
</a>
104+
<>
105+
<div className="layout">
106+
<aside className="sidebar">
107+
<div className="sidebar-content">
108+
{menu}
109+
<hr />
110+
<Filter />
111+
</div>
112+
<div className="sidebar-footer">
113+
<a
114+
className="button button-primary"
115+
href="https://github.com/topcoder-platform/micro-frontends-earn-app/issues/new?assignees=&labels=&template=bug_report.md&title="
116+
target="_blank"
117+
>
118+
GIVE APPLICATION FEEDBACK
119+
</a>
120+
</div>
121+
</aside>
122+
<div className="content">
123+
<Router>
124+
<Challenges path="/earn/find/challenges" />
125+
<MyGigs path="/earn/my-gigs" />
126+
<Redirect from="/earn/*" to="/earn/find/challenges" noThrow />
127+
</Router>
100128
</div>
101-
</aside>
102-
<div className="content">
103-
<Router>
104-
<Challenges path="/earn/*" />
105-
</Router>
106129
</div>
107-
</div>
130+
<div id="tooltips-container-id" />
131+
</>
108132
);
109133
};
110134

src/actions/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import challenges from "./challenges";
22
import filter from "./filter";
33
import lookup from "./lookup";
44
import init from "./initApp";
5+
import myGigs from "./myGigs";
56

67
export default {
78
challenges,
89
filter,
910
lookup,
1011
init,
12+
myGigs,
1113
};

src/actions/lookup.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@ async function getCommunityList() {
99
return service.getCommunityList();
1010
}
1111

12-
async function isLoggedIn() {
13-
return service.isLoggedIn();
12+
async function checkIsLoggedIn() {
13+
return service.checkIsLoggedIn();
14+
}
15+
16+
async function getGigPhases() {
17+
return service.getGigPhases();
1418
}
1519

1620
export default createActions({
1721
GET_TAGS: getTags,
1822
GET_COMMUNITY_LIST: getCommunityList,
19-
IS_LOGGED_IN: isLoggedIn,
23+
CHECK_IS_LOGGED_IN: checkIsLoggedIn,
24+
GET_GIG_PHASES: getGigPhases,
2025
});

src/actions/myGigs.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createActions } from "redux-actions";
2+
import service from "../services/myGigs";
3+
4+
async function getMyGigs() {
5+
return service.getMyGigs();
6+
}
7+
8+
async function loadMoreMyGigs() {
9+
return service.loadMoreMyGigs();
10+
}
11+
12+
export default createActions({
13+
GET_MY_GIGS: getMyGigs,
14+
LOAD_MORE_MY_GIGS: loadMoreMyGigs,
15+
});

0 commit comments

Comments
 (0)