From 4006fb27e0e5941a8070a176f3863ba5dff858f9 Mon Sep 17 00:00:00 2001 From: dalemcgrew Date: Fri, 20 Sep 2024 12:12:34 -0700 Subject: [PATCH] Pulling data from challengeParticipantListRetrieve. --- .../Challenge/ChallengeLeaderboard.jsx | 80 +++++++++++++------ .../Challenge/ChallengeLeaderboardList.jsx | 31 +------ .../stores/ChallengeParticipantStore.js | 26 +++++- 3 files changed, 79 insertions(+), 58 deletions(-) diff --git a/src/js/common/components/Challenge/ChallengeLeaderboard.jsx b/src/js/common/components/Challenge/ChallengeLeaderboard.jsx index 08b9be32d..7bc0acf0c 100644 --- a/src/js/common/components/Challenge/ChallengeLeaderboard.jsx +++ b/src/js/common/components/Challenge/ChallengeLeaderboard.jsx @@ -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; @@ -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(); @@ -100,32 +126,32 @@ const ChallengeLeaderboard = ({ classes, challengeWeVoteId }) => { @@ -150,7 +176,11 @@ const ChallengeLeaderboard = ({ classes, challengeWeVoteId }) => { - + }> diff --git a/src/js/common/components/Challenge/ChallengeLeaderboardList.jsx b/src/js/common/components/Challenge/ChallengeLeaderboardList.jsx index e6fd88f60..42f0442b4 100644 --- a/src/js/common/components/Challenge/ChallengeLeaderboardList.jsx +++ b/src/js/common/components/Challenge/ChallengeLeaderboardList.jsx @@ -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; @@ -40,9 +13,9 @@ const LeaderboardListContainer = styled.div` const ChallengeLeaderboardList = ({ currentVoterWeVoteId, participantList }) => ( - {participants.map((participant, index) => ( + {participantList.map((participant) => ( diff --git a/src/js/common/stores/ChallengeParticipantStore.js b/src/js/common/stores/ChallengeParticipantStore.js index 0abf02bab..951deb51f 100644 --- a/src/js/common/stores/ChallengeParticipantStore.js +++ b/src/js/common/stores/ChallengeParticipantStore.js @@ -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: '', @@ -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) { @@ -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) { @@ -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: