From 80cec94e21216387610eb2675ccb3e18f47b3ed8 Mon Sep 17 00:00:00 2001 From: Daniel Pan <57362494+daniel-panhead@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:07:50 -0800 Subject: [PATCH 1/2] Sum up points for each hacker's event attendance in firebase queries --- utility/firebase.js | 9 ++++----- utility/utilities.js | 9 ++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/utility/firebase.js b/utility/firebase.js index dce8ef23..5507d7f7 100644 --- a/utility/firebase.js +++ b/utility/firebase.js @@ -592,11 +592,10 @@ export const getHackerInfo = async (callback, hackathon, collection) => { .doc(hackathon) .collection(collection) .onSnapshot(snap => { - callback( - snap.docs.map(doc => { - return orderObj(flattenObj(filterHackerInfoFields(doc.data(), collection))) - }) - ) + const hackerInfoPromises = snap.docs.map(async doc => { + return orderObj(flattenObj(await filterHackerInfoFields(db, doc.data(), hackathon, collection))) + }) + Promise.all(hackerInfoPromises).then(callback) }) return res } diff --git a/utility/utilities.js b/utility/utilities.js index 19dfe7ea..43a941e3 100644 --- a/utility/utilities.js +++ b/utility/utilities.js @@ -100,7 +100,8 @@ const createStringFromSelection = (selection, other = '') => { } // Specifically for hacker info page - fixes/removes certain fields for table display -export const filterHackerInfoFields = (obj, collection) => { +// Take `db` as a parameter to avoid circular dependency with firebase.js +export const filterHackerInfoFields = async (db, obj, hackathon, collection) => { let newObj = {} if (collection === 'Applicants') { delete obj.questionnaire?.eventsAttended @@ -139,6 +140,12 @@ export const filterHackerInfoFields = (obj, collection) => { newObj.longAnswers3 = obj.skills?.longAnswers3 || false newObj.attendedEvents = obj.dayOf?.events?.map(e => e.eventName).join(', ') ?? '' + + const dayOfDocsPromises = obj.dayOf?.events?.map(e => + db.collection('Hackathons').doc(hackathon).collection('DayOf').doc(e.eventId).get() + ) + const dayOfDocs = await Promise.all(dayOfDocsPromises ?? []) + newObj.points = dayOfDocs.reduce((acc, curr) => acc + Number(curr.data().points ?? 0), 0) } else if (collection === 'Projects') { newObj = { ...obj } delete newObj.grades From 15863d071f973dd10211f89a076b54c7f7203dec Mon Sep 17 00:00:00 2001 From: byronwang93 Date: Thu, 9 Jan 2025 16:15:51 -0800 Subject: [PATCH 2/2] added new reward type to create edit + view reward modal --- pages/[id]/rewards.js | 39 +++++++++++++++++++++++++++++++++++++-- utility/firebase.js | 3 +++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pages/[id]/rewards.js b/pages/[id]/rewards.js index f854a902..7e740f40 100644 --- a/pages/[id]/rewards.js +++ b/pages/[id]/rewards.js @@ -37,6 +37,8 @@ export default function Rewards({ id, hackathons }) { const [alertMsg, setAlertMsg] = useState('') const { email: user } = useAuth().user + const REWARD_TYPES = [{ label: 'Reward' }, { label: 'Raffle' }] + const fetchRewards = async () => { const rewardsFetched = await getRewards(id) if (Object.keys(rewardsFetched).length > 0) { @@ -116,6 +118,7 @@ export default function Rewards({ id, hackathons }) { return ( {props.reward} + {props.type} {props.blurb} {props.prizesAvailable} {props.requiredPoints} @@ -143,11 +146,12 @@ export default function Rewards({ id, hackathons }) { @@ -175,6 +179,7 @@ export default function Rewards({ id, hackathons }) { Reward + Type Blurb Number of Prizes Available Required Points @@ -189,6 +194,7 @@ export default function Rewards({ id, hackathons }) { key={rewards[curr].rewardID} rewardID={rewards[curr].rewardID} reward={rewards[curr].reward} + type={rewards[curr].type} blurb={rewards[curr].blurb} prizesAvailable={rewards[curr].prizesAvailable} requiredPoints={rewards[curr].requiredPoints} @@ -216,6 +222,17 @@ export default function Rewards({ id, hackathons }) { onChange={reward => handleInput('reward', reward.target.value, newReward, setNewReward)} /> + + { + handleInput('type', type.label, newReward, setNewReward) + }} + /> + + + + @@ -303,6 +323,18 @@ export default function Rewards({ id, hackathons }) { }} /> + + { + handleInput('type', type.label, rewardEditing, setRewardEditing) + }} + /> + + + + diff --git a/utility/firebase.js b/utility/firebase.js index dce8ef23..a356baf2 100644 --- a/utility/firebase.js +++ b/utility/firebase.js @@ -158,6 +158,7 @@ export const getReward = (rewardID, data) => { rewardID, reward: data.reward || 'Empty reward field', // Title of the reward key: data.key || rewardID, // Key of the reward (defaults to rewardID) + type: data.type, // Reward type blurb: data.blurb || 'Empty blurb description for reward', // Short description of the reward from: data.from || 'None', // Source or sponsor of the reward imgName: data.imgName || 'None', // Image name (if applicable) @@ -185,6 +186,7 @@ export const addReward = async (hackathon, reward) => { await ref.set({ reward: reward.reward, // Title of the reward key: ref.id, // Key generated for the reward + type: reward.type, // Reward type blurb: reward.blurb, // Short description of the reward imgName: reward.imgName, // Image name (if applicable) imgURL: reward.imgURL, // URL to the reward image @@ -202,6 +204,7 @@ export const updateReward = async (hackathon, reward) => { await ref.update({ reward: reward.reward || 'Empty reward field', key: reward.key || reward.rewardID, + type: reward.type, blurb: reward.blurb || 'Empty blurb description for reward', from: reward.from || 'None', imgName: reward.imgName || 'None',