Skip to content

Commit 9af6af8

Browse files
Merge pull request #49 from topcoder-platform/dev
Hot Fix - challenges is loading blank page
2 parents f8c3c37 + 29bafe3 commit 9af6af8

File tree

8 files changed

+126
-82
lines changed

8 files changed

+126
-82
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ workflows:
7777
branches:
7878
only:
7979
- dev
80-
- challenge-details-page
8180

8281
# Production builds are exectuted only on tagged commits to the
8382
# master branch.

src/App.jsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22
* Main App component
33
*/
44
import React, { useEffect, useLayoutEffect, useRef } from "react";
5-
import { useLocation, Router } from "@reach/router";
5+
import { useLocation, Router, Redirect } from "@reach/router";
6+
import { usePreviousLocation } from "./utils/hooks";
67
import ChallengeList from "./routers/challenge-list";
78
import ChallengeDetail from "./routers/challenge-detail";
89
import "./styles/main.scss";
910

1011
const App = () => {
12+
const location = useLocation();
13+
const previousLocation = usePreviousLocation();
14+
15+
const varsRef = useRef();
16+
varsRef.current = { previousLocation };
17+
18+
useEffect(() => {
19+
if (location.pathname !== varsRef.current.previousLocation.pathname) {
20+
window.scrollTo(0, 0);
21+
}
22+
}, [location]);
23+
1124
return (
1225
<Router>
13-
<ChallengeList path="/earn/find/challenges" />
26+
<ChallengeList path="/earn/find/challenges/" />
1427
<ChallengeDetail path={`/earn/find/challenges/:challengeId`} />
28+
<Redirect from="/earn/*" to="/earn/find/challenges/" noThrow />
1529
</Router>
1630
);
1731
};

src/actions/challenge.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,23 @@ function getBasicDetailsDone(challengeId, tokenV3, tokenV2) {
9292
* @param {Number|String} challengeId Challenge ID
9393
* @return {Action}
9494
*/
95-
function getFullDetailsInit(challengeId) {
96-
return _.toString(challengeId);
97-
}
95+
function getFullDetailsInit(challengeId) {
96+
return _.toString(challengeId);
97+
}
9898

99-
/**
100-
* @static
101-
* @desc Creates an action that loads full challenge details.
102-
* @param {Number|String} challengeId Challenge ID.
103-
* @param {String} tokenV3 Topcoder v3 auth token.
104-
* @param {String} tokenV2 Topcoder v2 auth token.
105-
* @return {Action}
106-
*/
107-
function getFullDetailsDone(challengeId, tokenV3, tokenV2) {
108-
const service = getChallengesService(tokenV3, tokenV2);
109-
const v3Promise = service.getFullChallengeDetails(challengeId);
110-
return v3Promise;
111-
}
99+
/**
100+
* @static
101+
* @desc Creates an action that loads full challenge details.
102+
* @param {Number|String} challengeId Challenge ID.
103+
* @param {String} tokenV3 Topcoder v3 auth token.
104+
* @param {String} tokenV2 Topcoder v2 auth token.
105+
* @return {Action}
106+
*/
107+
function getFullDetailsDone(challengeId, tokenV3, tokenV2) {
108+
const service = getChallengesService(tokenV3, tokenV2);
109+
const v3Promise = service.getFullChallengeDetails(challengeId);
110+
return v3Promise;
111+
}
112112

113113
/**
114114
* @static

src/components/challenge-detail/Header/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,12 @@ export default function ChallengeHeader(props) {
391391
</DangerButton>
392392
) : (
393393
<PrimaryButton
394-
disabled={isLoadingChallenge || registering || registrationEnded || isLegacyMM}
394+
disabled={
395+
isLoadingChallenge ||
396+
registering ||
397+
registrationEnded ||
398+
isLegacyMM
399+
}
395400
forceA
396401
onClick={registerForChallenge}
397402
theme={{ button: style.challengeAction }}

src/containers/challenge-detail/index.jsx

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -502,63 +502,73 @@ class ChallengeDetailPageContainer extends React.Component {
502502
updateChallenge={(x) => updateChallenge(x, auth.tokenV3)}
503503
/>
504504
)}
505-
{!isEmpty && selectedTab === DETAIL_TABS.REGISTRANTS && isLoadingFullChallenge && (
506-
<LoadingIndicator/>
507-
)}
508-
{!isEmpty && selectedTab === DETAIL_TABS.REGISTRANTS && !isLoadingFullChallenge && (
509-
<Registrants
510-
challenge={challenge}
511-
registrants={challenge.registrants}
512-
checkpointResults={_.merge(
513-
checkpointResults,
514-
checkpointResultsUi
515-
)}
516-
results={results2}
517-
registrantsSort={registrantsSort}
518-
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
519-
onGetFlagImageFail={(countryInfo) => {
520-
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
521-
this.setState({ notFoundCountryFlagUrl });
522-
}}
523-
onSortChange={(sort) => this.setState({ registrantsSort: sort })}
524-
/>
525-
)}
505+
{!isEmpty &&
506+
selectedTab === DETAIL_TABS.REGISTRANTS &&
507+
isLoadingFullChallenge && <LoadingIndicator />}
508+
{!isEmpty &&
509+
selectedTab === DETAIL_TABS.REGISTRANTS &&
510+
!isLoadingFullChallenge && (
511+
<Registrants
512+
challenge={challenge}
513+
registrants={challenge.registrants}
514+
checkpointResults={_.merge(
515+
checkpointResults,
516+
checkpointResultsUi
517+
)}
518+
results={results2}
519+
registrantsSort={registrantsSort}
520+
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
521+
onGetFlagImageFail={(countryInfo) => {
522+
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
523+
this.setState({ notFoundCountryFlagUrl });
524+
}}
525+
onSortChange={(sort) =>
526+
this.setState({ registrantsSort: sort })
527+
}
528+
/>
529+
)}
526530
{!isEmpty && selectedTab === DETAIL_TABS.CHECKPOINTS && (
527531
<ChallengeCheckpoints
528532
checkpoints={checkpoints}
529533
toggleCheckpointFeedback={toggleCheckpointFeedback}
530534
/>
531535
)}
532-
{!isEmpty && isLoggedIn && selectedTab === DETAIL_TABS.SUBMISSIONS && isLoadingFullChallenge && (
533-
<LoadingIndicator/>
534-
)}
535-
{!isEmpty && isLoggedIn && selectedTab === DETAIL_TABS.SUBMISSIONS && !isLoadingFullChallenge && (
536-
<Submissions
537-
challenge={challenge}
538-
submissions={challenge.submissions}
539-
loadingMMSubmissionsForChallengeId={
540-
loadingMMSubmissionsForChallengeId
541-
}
542-
mmSubmissions={mmSubmissions}
543-
loadMMSubmissions={loadMMSubmissions}
544-
auth={auth}
545-
isLoadingSubmissionInformation={isLoadingSubmissionInformation}
546-
submssionInformation={submissionInformation}
547-
loadSubmissionInformation={loadSubmissionInformation}
548-
submissionsSort={submissionsSort}
549-
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
550-
onGetFlagImageFail={(countryInfo) => {
551-
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
552-
this.setState({ notFoundCountryFlagUrl });
553-
}}
554-
onSortChange={(sort) => this.setState({ submissionsSort: sort })}
555-
hasRegistered={challenge.isRegistered}
556-
unregistering={unregistering}
557-
isLegacyMM={isLegacyMM}
558-
submissionEnded={submissionEnded}
559-
challengesUrl={challengesUrl}
560-
/>
561-
)}
536+
{!isEmpty &&
537+
isLoggedIn &&
538+
selectedTab === DETAIL_TABS.SUBMISSIONS &&
539+
isLoadingFullChallenge && <LoadingIndicator />}
540+
{!isEmpty &&
541+
isLoggedIn &&
542+
selectedTab === DETAIL_TABS.SUBMISSIONS &&
543+
!isLoadingFullChallenge && (
544+
<Submissions
545+
challenge={challenge}
546+
submissions={challenge.submissions}
547+
loadingMMSubmissionsForChallengeId={
548+
loadingMMSubmissionsForChallengeId
549+
}
550+
mmSubmissions={mmSubmissions}
551+
loadMMSubmissions={loadMMSubmissions}
552+
auth={auth}
553+
isLoadingSubmissionInformation={isLoadingSubmissionInformation}
554+
submssionInformation={submissionInformation}
555+
loadSubmissionInformation={loadSubmissionInformation}
556+
submissionsSort={submissionsSort}
557+
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
558+
onGetFlagImageFail={(countryInfo) => {
559+
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
560+
this.setState({ notFoundCountryFlagUrl });
561+
}}
562+
onSortChange={(sort) =>
563+
this.setState({ submissionsSort: sort })
564+
}
565+
hasRegistered={challenge.isRegistered}
566+
unregistering={unregistering}
567+
isLegacyMM={isLegacyMM}
568+
submissionEnded={submissionEnded}
569+
challengesUrl={challengesUrl}
570+
/>
571+
)}
562572
{isMM && !isEmpty && selectedTab === DETAIL_TABS.MY_SUBMISSIONS && (
563573
<MySubmissions
564574
challengesUrl={challengesUrl}
@@ -828,7 +838,9 @@ function mapStateToProps(state, props) {
828838
communitiesList: state.tcCommunities.list,
829839
domain: state.domain,
830840
isLoadingChallenge: Boolean(state.challenge.loadingDetailsForChallengeId),
831-
isLoadingFullChallenge: Boolean(state.challenge.loadingFullDetailsForChallengeId),
841+
isLoadingFullChallenge: Boolean(
842+
state.challenge.loadingFullDetailsForChallengeId
843+
),
832844
isLoadingTerms: _.isEqual(state.terms.loadingTermsForEntity, {
833845
type: "challenge",
834846
id: props.match.params.challengeId,
@@ -906,15 +918,15 @@ const mapDispatchToProps = (dispatch) => {
906918
});
907919
},
908920
loadFullChallengeDetails: (tokens, challengeId) => {
909-
const a = actions.challenge;
921+
const a = actions.challenge;
910922

911-
dispatch(a.getFullDetailsInit(challengeId));
912-
dispatch(
913-
a.getFullDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2)
914-
).then((res) => {
915-
return res;
916-
});
917-
},
923+
dispatch(a.getFullDetailsInit(challengeId));
924+
dispatch(
925+
a.getFullDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2)
926+
).then((res) => {
927+
return res;
928+
});
929+
},
918930
registerForChallenge: (auth, challengeId) => {
919931
const a = actions.challenge;
920932
dispatch(a.registerInit());

src/services/challenges.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ class ChallengesService {
398398
* @param {Number|String} challengeId
399399
* @returns {Promise} Resolves to the basic challenge object.
400400
*/
401-
async getBasicChallengeDetails(challengeId){
401+
async getBasicChallengeDetails(challengeId) {
402402
let challenge = {};
403403
let isLegacyChallenge = false;
404404

@@ -427,7 +427,7 @@ class ChallengesService {
427427
eventId: e.id,
428428
description: e.name,
429429
})),
430-
fetchedWithAuth: Boolean(this.private.apiV5.private.token)
430+
fetchedWithAuth: Boolean(this.private.apiV5.private.token),
431431
};
432432
}
433433

src/utils/hooks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./usePreviousLocation";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { useLocation } from "@reach/router";
2+
import { useEffect, useRef } from "react";
3+
4+
export const usePreviousLocation = () => {
5+
const location = useLocation();
6+
const ref = useRef(location);
7+
8+
useEffect(() => {
9+
ref.current = location;
10+
}, [location]);
11+
12+
return ref.current;
13+
};

0 commit comments

Comments
 (0)