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

Commit a9341d3

Browse files
Merge branch 'nursoltan-s-issue-44' into bugbash
2 parents d7de22c + 7aa57f8 commit a9341d3

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

src/actions/lookup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ async function getCommunityList() {
99
return service.getCommunityList();
1010
}
1111

12+
async function isLoggedIn() {
13+
return service.isLoggedIn();
14+
}
15+
1216
export default createActions({
1317
GET_TAGS: getTags,
1418
GET_COMMUNITY_LIST: getCommunityList,
19+
IS_LOGGED_IN: isLoggedIn,
1520
});

src/containers/Challenges/Listing/ChallengeItem/index.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import TagsMoreTooltip from "../tooltips/TagsMoreTooltip";
1414

1515
import "./styles.scss";
1616

17-
const ChallengeItem = ({ challenge, onClickTag, onClickTrack }) => {
17+
const ChallengeItem = ({ challenge, onClickTag, onClickTrack, isLoggedIn }) => {
1818
const totalPrizes = challenge.overview.totalPrizes;
1919
const currencySymbol = utils.challenge.getCurrencySymbol(challenge.prizeSets);
2020
const placementPrizes = utils.challenge.getPlacementPrizes(
@@ -24,6 +24,12 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack }) => {
2424
challenge.prizeSets
2525
);
2626

27+
let submissionLink = `${process.env.URL.BASE}/challenges/${challenge.id}`;
28+
29+
if (isLoggedIn && challenge.numOfSubmissions > 0) {
30+
submissionLink += "?tab=submissions";
31+
}
32+
2733
return (
2834
<div styleName="challenge-item">
2935
<div styleName="track">
@@ -69,9 +75,7 @@ const ChallengeItem = ({ challenge, onClickTag, onClickTrack }) => {
6975
>
7076
<NumRegistrants numOfRegistrants={challenge.numOfRegistrants} />
7177
</a>
72-
<a
73-
href={`${process.env.URL.BASE}/challenges/${challenge.id}?tab=submissions`} // eslint-disable-line no-undef
74-
>
78+
<a href={submissionLink}>
7579
<NumSubmissions numOfSubmissions={challenge.numOfSubmissions} />
7680
</a>
7781
</div>
@@ -96,6 +100,7 @@ ChallengeItem.propTypes = {
96100
challenge: PT.shape(),
97101
onClickTag: PT.func,
98102
onClickTrack: PT.func,
103+
isLoggedIn: PT.bool,
99104
};
100105

101106
export default ChallengeItem;

src/containers/Challenges/Listing/index.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const Listing = ({
2626
updateFilter,
2727
bucket,
2828
sortByLabels,
29+
isLoggedIn,
2930
}) => {
3031
const sortByOptions = utils.createDropdownOptions(
3132
sortByLabels,
@@ -112,6 +113,7 @@ const Listing = ({
112113
const filterChange = { tracks: [track] };
113114
updateFilter(filterChange);
114115
}}
116+
isLoggedIn={isLoggedIn}
115117
/>
116118
</div>
117119
))}
@@ -146,6 +148,7 @@ Listing.propTypes = {
146148
updateFilter: PT.func,
147149
bucket: PT.string,
148150
sortByLabels: PT.arrayOf(PT.string),
151+
isLoggedIn: PT.bool,
149152
};
150153

151154
export default Listing;

src/containers/Challenges/index.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useRef, useState } from "react";
22
import PT from "prop-types";
33
import { connect } from "react-redux";
44
import Listing from "./Listing";
@@ -26,7 +26,16 @@ const Challenges = ({
2626
recommendedChallenges,
2727
initialized,
2828
updateQuery,
29+
userLoggedIn,
30+
isLoggedIn,
2931
}) => {
32+
const latestPropsRef = useRef(null);
33+
latestPropsRef.current = { userLoggedIn };
34+
35+
useEffect(() => {
36+
latestPropsRef.current.userLoggedIn();
37+
}, []);
38+
3039
const BUCKET_OPEN_FOR_REGISTRATION = constants.FILTER_BUCKETS[1];
3140
const isRecommended = recommended && bucket === BUCKET_OPEN_FOR_REGISTRATION;
3241
const sortByValue = isRecommended
@@ -76,6 +85,7 @@ const Challenges = ({
7685
}}
7786
bucket={bucket}
7887
sortByLabels={sortByLabels}
88+
isLoggedIn={isLoggedIn}
7989
/>
8090
</>
8191
)}
@@ -98,6 +108,7 @@ Challenges.propTypes = {
98108
recommendedChallenges: PT.arrayOf(PT.shape()),
99109
initialized: PT.bool,
100110
updateQuery: PT.func,
111+
isLoggedIn: PT.bool,
101112
};
102113

103114
const mapStateToProps = (state) => ({
@@ -114,11 +125,13 @@ const mapStateToProps = (state) => ({
114125
recommended: state.filter.challenge.recommended,
115126
recommendedChallenges: state.challenges.recommendedChallenges,
116127
initialized: state.challenges.initialized,
128+
isLoggedIn: state.lookup.isLoggedIn,
117129
});
118130

119131
const mapDispatchToProps = {
120132
updateFilter: actions.filter.updateFilter,
121133
updateQuery: actions.filter.updateChallengeQuery,
134+
userLoggedIn: actions.lookup.isLoggedIn,
122135
};
123136

124137
const mergeProps = (stateProps, dispatchProps, ownProps) => ({

src/reducers/lookup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const defaultState = {
77
tracks: constants.FILTER_CHALLENGE_TRACKS,
88
tags: [],
99
subCommunities: [],
10+
isLoggedIn: false,
1011
};
1112

1213
function onGetTagsDone(state, { payload }) {
@@ -17,10 +18,15 @@ function onGetCommunityListDone(state, { payload }) {
1718
return { ...state, subCommunities: payload };
1819
}
1920

21+
function onIsLoggedInDone(state, { payload }) {
22+
return { ...state, isLoggedIn: payload };
23+
}
24+
2025
export default handleActions(
2126
{
2227
GET_TAGS_DONE: onGetTagsDone,
2328
GET_COMMUNITY_LIST_DONE: onGetCommunityListDone,
29+
IS_LOGGED_IN_DONE: onIsLoggedInDone,
2430
},
2531
defaultState
2632
);

src/services/lookup.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ async function getTags() {
1818
return data.result.content.map((tag) => tag.name);
1919
}
2020

21-
async function doGetUserGroups() {
21+
async function isLoggedIn() {
2222
const isLoggedIn = await utils.auth.isLoggedIn();
23+
return isLoggedIn;
24+
}
25+
26+
async function doGetUserGroups() {
27+
const isLoggedIn = await isLoggedIn();
2328

2429
if (isLoggedIn) {
2530
const userId = await utils.auth.getUserId();
@@ -51,4 +56,5 @@ async function getCommunityList() {
5156
export default {
5257
getTags,
5358
getCommunityList,
59+
isLoggedIn,
5460
};

0 commit comments

Comments
 (0)