Skip to content

v1.0.3 #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ workflows:
branches:
only:
- dev
- challenge-details-page

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
18 changes: 16 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@
* Main App component
*/
import React, { useEffect, useLayoutEffect, useRef } from "react";
import { useLocation, Router } from "@reach/router";
import { useLocation, Router, Redirect } from "@reach/router";
import { usePreviousLocation } from "./utils/hooks";
import ChallengeList from "./routers/challenge-list";
import ChallengeDetail from "./routers/challenge-detail";
import "./styles/main.scss";

const App = () => {
const location = useLocation();
const previousLocation = usePreviousLocation();

const varsRef = useRef();
varsRef.current = { previousLocation };

useEffect(() => {
if (location.pathname !== varsRef.current.previousLocation.pathname) {
window.scrollTo(0, 0);
}
}, [location]);

return (
<Router>
<ChallengeList path="/earn/find/challenges" />
<ChallengeList path="/earn/find/challenges/" />
<ChallengeDetail path={`/earn/find/challenges/:challengeId`} />
<Redirect from="/earn/*" to="/earn/find/challenges/" noThrow />
</Router>
);
};
Expand Down
32 changes: 16 additions & 16 deletions src/actions/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,23 @@ function getBasicDetailsDone(challengeId, tokenV3, tokenV2) {
* @param {Number|String} challengeId Challenge ID
* @return {Action}
*/
function getFullDetailsInit(challengeId) {
return _.toString(challengeId);
}
function getFullDetailsInit(challengeId) {
return _.toString(challengeId);
}

/**
* @static
* @desc Creates an action that loads full challenge details.
* @param {Number|String} challengeId Challenge ID.
* @param {String} tokenV3 Topcoder v3 auth token.
* @param {String} tokenV2 Topcoder v2 auth token.
* @return {Action}
*/
function getFullDetailsDone(challengeId, tokenV3, tokenV2) {
const service = getChallengesService(tokenV3, tokenV2);
const v3Promise = service.getFullChallengeDetails(challengeId);
return v3Promise;
}
/**
* @static
* @desc Creates an action that loads full challenge details.
* @param {Number|String} challengeId Challenge ID.
* @param {String} tokenV3 Topcoder v3 auth token.
* @param {String} tokenV2 Topcoder v2 auth token.
* @return {Action}
*/
function getFullDetailsDone(challengeId, tokenV3, tokenV2) {
const service = getChallengesService(tokenV3, tokenV2);
const v3Promise = service.getFullChallengeDetails(challengeId);
return v3Promise;
}

/**
* @static
Expand Down
7 changes: 6 additions & 1 deletion src/components/challenge-detail/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,12 @@ export default function ChallengeHeader(props) {
</DangerButton>
) : (
<PrimaryButton
disabled={isLoadingChallenge || registering || registrationEnded || isLegacyMM}
disabled={
isLoadingChallenge ||
registering ||
registrationEnded ||
isLegacyMM
}
forceA
onClick={registerForChallenge}
theme={{ button: style.challengeAction }}
Expand Down
132 changes: 72 additions & 60 deletions src/containers/challenge-detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -502,63 +502,73 @@ class ChallengeDetailPageContainer extends React.Component {
updateChallenge={(x) => updateChallenge(x, auth.tokenV3)}
/>
)}
{!isEmpty && selectedTab === DETAIL_TABS.REGISTRANTS && isLoadingFullChallenge && (
<LoadingIndicator/>
)}
{!isEmpty && selectedTab === DETAIL_TABS.REGISTRANTS && !isLoadingFullChallenge && (
<Registrants
challenge={challenge}
registrants={challenge.registrants}
checkpointResults={_.merge(
checkpointResults,
checkpointResultsUi
)}
results={results2}
registrantsSort={registrantsSort}
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
onGetFlagImageFail={(countryInfo) => {
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
this.setState({ notFoundCountryFlagUrl });
}}
onSortChange={(sort) => this.setState({ registrantsSort: sort })}
/>
)}
{!isEmpty &&
selectedTab === DETAIL_TABS.REGISTRANTS &&
isLoadingFullChallenge && <LoadingIndicator />}
{!isEmpty &&
selectedTab === DETAIL_TABS.REGISTRANTS &&
!isLoadingFullChallenge && (
<Registrants
challenge={challenge}
registrants={challenge.registrants}
checkpointResults={_.merge(
checkpointResults,
checkpointResultsUi
)}
results={results2}
registrantsSort={registrantsSort}
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
onGetFlagImageFail={(countryInfo) => {
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
this.setState({ notFoundCountryFlagUrl });
}}
onSortChange={(sort) =>
this.setState({ registrantsSort: sort })
}
/>
)}
{!isEmpty && selectedTab === DETAIL_TABS.CHECKPOINTS && (
<ChallengeCheckpoints
checkpoints={checkpoints}
toggleCheckpointFeedback={toggleCheckpointFeedback}
/>
)}
{!isEmpty && isLoggedIn && selectedTab === DETAIL_TABS.SUBMISSIONS && isLoadingFullChallenge && (
<LoadingIndicator/>
)}
{!isEmpty && isLoggedIn && selectedTab === DETAIL_TABS.SUBMISSIONS && !isLoadingFullChallenge && (
<Submissions
challenge={challenge}
submissions={challenge.submissions}
loadingMMSubmissionsForChallengeId={
loadingMMSubmissionsForChallengeId
}
mmSubmissions={mmSubmissions}
loadMMSubmissions={loadMMSubmissions}
auth={auth}
isLoadingSubmissionInformation={isLoadingSubmissionInformation}
submssionInformation={submissionInformation}
loadSubmissionInformation={loadSubmissionInformation}
submissionsSort={submissionsSort}
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
onGetFlagImageFail={(countryInfo) => {
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
this.setState({ notFoundCountryFlagUrl });
}}
onSortChange={(sort) => this.setState({ submissionsSort: sort })}
hasRegistered={challenge.isRegistered}
unregistering={unregistering}
isLegacyMM={isLegacyMM}
submissionEnded={submissionEnded}
challengesUrl={challengesUrl}
/>
)}
{!isEmpty &&
isLoggedIn &&
selectedTab === DETAIL_TABS.SUBMISSIONS &&
isLoadingFullChallenge && <LoadingIndicator />}
{!isEmpty &&
isLoggedIn &&
selectedTab === DETAIL_TABS.SUBMISSIONS &&
!isLoadingFullChallenge && (
<Submissions
challenge={challenge}
submissions={challenge.submissions}
loadingMMSubmissionsForChallengeId={
loadingMMSubmissionsForChallengeId
}
mmSubmissions={mmSubmissions}
loadMMSubmissions={loadMMSubmissions}
auth={auth}
isLoadingSubmissionInformation={isLoadingSubmissionInformation}
submssionInformation={submissionInformation}
loadSubmissionInformation={loadSubmissionInformation}
submissionsSort={submissionsSort}
notFoundCountryFlagUrl={notFoundCountryFlagUrl}
onGetFlagImageFail={(countryInfo) => {
notFoundCountryFlagUrl[countryInfo.countryCode] = true;
this.setState({ notFoundCountryFlagUrl });
}}
onSortChange={(sort) =>
this.setState({ submissionsSort: sort })
}
hasRegistered={challenge.isRegistered}
unregistering={unregistering}
isLegacyMM={isLegacyMM}
submissionEnded={submissionEnded}
challengesUrl={challengesUrl}
/>
)}
{isMM && !isEmpty && selectedTab === DETAIL_TABS.MY_SUBMISSIONS && (
<MySubmissions
challengesUrl={challengesUrl}
Expand Down Expand Up @@ -828,7 +838,9 @@ function mapStateToProps(state, props) {
communitiesList: state.tcCommunities.list,
domain: state.domain,
isLoadingChallenge: Boolean(state.challenge.loadingDetailsForChallengeId),
isLoadingFullChallenge: Boolean(state.challenge.loadingFullDetailsForChallengeId),
isLoadingFullChallenge: Boolean(
state.challenge.loadingFullDetailsForChallengeId
),
isLoadingTerms: _.isEqual(state.terms.loadingTermsForEntity, {
type: "challenge",
id: props.match.params.challengeId,
Expand Down Expand Up @@ -906,15 +918,15 @@ const mapDispatchToProps = (dispatch) => {
});
},
loadFullChallengeDetails: (tokens, challengeId) => {
const a = actions.challenge;
const a = actions.challenge;

dispatch(a.getFullDetailsInit(challengeId));
dispatch(
a.getFullDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2)
).then((res) => {
return res;
});
},
dispatch(a.getFullDetailsInit(challengeId));
dispatch(
a.getFullDetailsDone(challengeId, tokens.tokenV3, tokens.tokenV2)
).then((res) => {
return res;
});
},
registerForChallenge: (auth, challengeId) => {
const a = actions.challenge;
dispatch(a.registerInit());
Expand Down
4 changes: 2 additions & 2 deletions src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class ChallengesService {
* @param {Number|String} challengeId
* @returns {Promise} Resolves to the basic challenge object.
*/
async getBasicChallengeDetails(challengeId){
async getBasicChallengeDetails(challengeId) {
let challenge = {};
let isLegacyChallenge = false;

Expand Down Expand Up @@ -427,7 +427,7 @@ class ChallengesService {
eventId: e.id,
description: e.name,
})),
fetchedWithAuth: Boolean(this.private.apiV5.private.token)
fetchedWithAuth: Boolean(this.private.apiV5.private.token),
};
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./usePreviousLocation";
13 changes: 13 additions & 0 deletions src/utils/hooks/usePreviousLocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useLocation } from "@reach/router";
import { useEffect, useRef } from "react";

export const usePreviousLocation = () => {
const location = useLocation();
const ref = useRef(location);

useEffect(() => {
ref.current = location;
}, [location]);

return ref.current;
};