Skip to content
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

Pulling data from challengeParticipantListRetrieve. #4045

Merged
merged 1 commit into from
Sep 20, 2024
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
80 changes: 55 additions & 25 deletions src/js/common/components/Challenge/ChallengeLeaderboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ import FirstChallengeParticipantListController from './FirstChallengeParticipant

// const FirstChallengeParticipantListController = React.lazy(() => import(/* webpackChunkName: 'FirstChallengeParticipantListController' */ './FirstChallengeParticipantListController'));

const participants = [
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter1238' },
{ rank: 5341, participant_name: 'David N.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter1237' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter1236' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter1235' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter1234' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter123' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12333' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12344' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12355' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12366' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12377' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12388' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12399' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12390' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12312' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12314' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12315' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12316' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12317' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12318' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12319' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12323' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12324' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12325' },
];

const LeaderboardContainer = styled.div`
max-width: 100vw;
margin: 0 auto;
Expand Down Expand Up @@ -80,15 +107,14 @@ const ChallengeLeaderboard = ({ classes, challengeWeVoteId }) => {
// eslint-disable-next-line no-unused-vars
const [latestParticipants, setLatestParticipants] = React.useState([]);

const onChallengeParticipantStoreChange = () => {
setLatestParticipants(ChallengeParticipantStore.getChallengeParticipantList(challengeWeVoteId));
};

React.useEffect(() => {
console.log('Fetching participants for:', challengeWeVoteId);
const handleStoreChange = () => {
const updatedParticipants = ChallengeParticipantStore.getChallengeParticipantList(challengeWeVoteId);
console.log('Updated participants:', updatedParticipants);
setLatestParticipants(updatedParticipants);
};
const storeListener = ChallengeParticipantStore.addListener(handleStoreChange);
handleStoreChange();
// console.log('Fetching participants for:', challengeWeVoteId);
const storeListener = ChallengeParticipantStore.addListener(onChallengeParticipantStoreChange);
onChallengeParticipantStoreChange();

return () => {
storeListener.remove();
Expand All @@ -100,32 +126,32 @@ const ChallengeLeaderboard = ({ classes, challengeWeVoteId }) => {
<ButtonAndSearchWrapper>
<ButtonWrapper>
<Button
classes={{ root: classes.buttonDesktop }}
color="primary"
id="challengeLeaderboardYouButton"
onClick={() => console.log('You button clicked', challengeWeVoteId)}
variant="outlined"
classes={{ root: classes.buttonDesktop }}
color="primary"
id="challengeLeaderboardYouButton"
onClick={() => console.log('You button clicked', challengeWeVoteId)}
variant="outlined"
>
You
</Button>
<Button
classes={{ root: classes.buttonDesktop }}
color="primary"
id="challengeLeaderboardTop50Button"
onClick={() => console.log('Top 50 button clicked')}
variant="outlined"
classes={{ root: classes.buttonDesktop }}
color="primary"
id="challengeLeaderboardTop50Button"
onClick={() => console.log('Top 50 button clicked')}
variant="outlined"
>
Top 50
</Button>
</ButtonWrapper>
<SearchBarWrapper>
<SearchBar2024
clearButton
searchButton
placeholder="Search by rank or name"
searchFunction={searchFunction}
clearFunction={clearSearchFunction}
searchUpdateDelayTime={500}
clearButton
searchButton
placeholder="Search by rank or name"
searchFunction={searchFunction}
clearFunction={clearSearchFunction}
searchUpdateDelayTime={500}
/>
</SearchBarWrapper>
</ButtonAndSearchWrapper>
Expand All @@ -150,7 +176,11 @@ const ChallengeLeaderboard = ({ classes, challengeWeVoteId }) => {
</div>
</LeaderboardTableHeader>
</TopSection>
<ChallengeLeaderboardList currentVoterWeVoteId={'wv02voter123'} />
<ChallengeLeaderboardList
// participantList={latestParticipants}
participantList={participants}
currentVoterWeVoteId={'wv02voter123'}
/>
<Suspense fallback={<></>}>
<FirstChallengeParticipantListController challengeWeVoteId={challengeWeVoteId} searchText="SEARCH TEXT HERE" />
</Suspense>
Expand Down
31 changes: 2 additions & 29 deletions src/js/common/components/Challenge/ChallengeLeaderboardList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,6 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import ChallengeParticipantListItem from './ChallengeParticipantListItem';

const participants = [
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter1238' },
{ rank: 5341, participant_name: 'David N.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter1237' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter1236' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter1235' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter1234' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter123' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12333' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12344' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12355' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12366' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12377' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12388' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12399' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12390' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12312' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12314' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12315' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12316' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12317' },
{ rank: 5341, participant_name: 'David B.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12318' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12319' },
{ rank: 5340, participant_name: 'Melina H.', points: 142, friends_who_joined: 3, friends_invited: 10, friends_who_viewed: 8, friends_who_viewed_plus: 21, voter_we_vote_id: 'wv02voter12323' },
{ rank: 5341, participant_name: 'David A.', points: 121, friends_who_joined: 1, friends_invited: 7, friends_who_viewed: 3, friends_who_viewed_plus: 18, voter_we_vote_id: 'wv02voter12324' },
{ rank: 5342, participant_name: 'Anusha G.', points: 118, friends_who_joined: 1, friends_invited: 5, friends_who_viewed: 2, friends_who_viewed_plus: 15, voter_we_vote_id: 'wv02voter12325' },
];

const LeaderboardListContainer = styled.div`
display: flex;
flex-direction: column;
Expand All @@ -40,9 +13,9 @@ const LeaderboardListContainer = styled.div`

const ChallengeLeaderboardList = ({ currentVoterWeVoteId, participantList }) => (
<LeaderboardListContainer>
{participants.map((participant, index) => (
{participantList.map((participant) => (
<ChallengeParticipantListItem
key={index}
key={`participantKey-${participant.voter_we_vote_id}`}
participant={participant}
isCurrentUser={participant.voter_we_vote_id === currentVoterWeVoteId}
/>
Expand Down
26 changes: 22 additions & 4 deletions src/js/common/stores/ChallengeParticipantStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class ChallengeParticipantStore extends ReduceStore {
return {
// TODO: Not quite right
allCachedChallengeParticipants: {}, // Dictionary with ChallengeParticipant simple id as key and the ChallengeParticipant as value
allCachedChallengeParticipantVoterEntries: {}, // Dictionary with challenge_we_vote_id as key and the ChallengeParticipant for this voter as value
challengeParticipantList: {}, // Dict with key challenge_we_vote_id and value of List of Dicts w/ latest challenge_participant entries, ordered newest to oldest
allCachedChallengeParticipantVoterEntries: {}, // Dictionary with challenge_we_vote_id and voter_we_vote_id as keys and the ChallengeParticipant for this voter as value
allChallengeParticipantLists: {}, // Dict with key challenge_we_vote_id and value of List of Dicts w/ challenge_participant entries, ordered highest rank to lowest
latestChallengeParticipants: {}, // Dict with key challenge_we_vote_id and value of List of Dicts w/ latest challenge_participant entries, ordered newest to oldest
shareButtonClicked: false,
participantEndorsementQueuedToSave: '',
Expand Down Expand Up @@ -50,9 +50,8 @@ class ChallengeParticipantStore extends ReduceStore {
return this.getState().allCachedChallengeParticipants[challengeParticipantId] || {};
}

// These are the most recent challenge_participant entries, with visible signers. May or may not have text endorsements.
getChallengeParticipantList (challengeWeVoteId) {
return this.getState().challengeParticipantList[challengeWeVoteId] || [];
return this.getState().allChallengeParticipantLists[challengeWeVoteId] || [];
}

getChallengeParticipantVoterEntry (challengeWeVoteId) {
Expand Down Expand Up @@ -121,12 +120,14 @@ class ChallengeParticipantStore extends ReduceStore {
reduce (state, action) {
const {
allCachedChallengeParticipants, allCachedChallengeParticipantVoterEntries,
allChallengeParticipantLists,
} = state;
let {
latestChallengeParticipants,
} = state;
let challengeList;
let challengeParticipant;
let challengeParticipantList;

let revisedState;
switch (action.type) {
Expand Down Expand Up @@ -165,6 +166,23 @@ class ChallengeParticipantStore extends ReduceStore {
revisedState = { ...revisedState, latestChallengeParticipants };
return revisedState;

case 'challengeParticipantListRetrieve':
// console.log('ChallengeParticipantStore challengeParticipantListRetrieve');
if (!action.res || !action.res.success) return state;
revisedState = state;
challengeParticipantList = action.res.challenge_participant_list || [];
// console.log('challengeParticipantListRetrieve challenge_participant_list:', challengeParticipantList);
allChallengeParticipantLists[action.res.challenge_we_vote_id] = challengeParticipantList;
challengeParticipantList.forEach((oneParticipant) => {
if (!(oneParticipant.voter_we_vote_id in allCachedChallengeParticipants)) {
allCachedChallengeParticipants[oneParticipant.voter_we_vote_id] = {};
}
allCachedChallengeParticipants[oneParticipant.voter_we_vote_id][oneParticipant.challenge_we_vote_id] = oneParticipant;
});
revisedState = { ...revisedState, allCachedChallengeParticipants };
revisedState = { ...revisedState, allChallengeParticipantLists };
return revisedState;

case 'challengeRetrieve':
case 'challengeRetrieveAsOwner':
// See ChallengeStore for code to take in the following challenge values:
Expand Down
Loading