-
Notifications
You must be signed in to change notification settings - Fork 2
Fix: Make problem statement visible to all team members #20
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
Fix: Make problem statement visible to all team members #20
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enables team members to view their team's problem statement by implementing a dual-fetch and dual-save strategy. Previously, problem statements were only stored in the team leader's profile, making them inaccessible to other team members.
Key Changes:
- Added logic to fetch problem statements from team documents or fallback to the leader's profile when team members load their profiles
- Modified the save operation to persist problem statements to both the user's profile and the team document for shared visibility
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Save to user profile (legacy support) | ||
| await updateDoc(doc(db, "registrations", user.uid), { | ||
| problemStatement, | ||
| solution, | ||
| techStack, | ||
| }); | ||
|
|
||
| // Save to team document (so all members can see it) | ||
| if (userData?.teamName) { | ||
| await updateDoc(doc(db, "teams", userData.teamName), { | ||
| problemStatement, | ||
| solution, | ||
| techStack, | ||
| }); | ||
| } |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The save operation updates two documents sequentially without proper transaction handling or permission checking. If the first update succeeds but the second fails, the data will be inconsistent between the user's profile and the team document. Additionally, there's no check to ensure only the team leader can update the problem statement. Consider using a Firestore transaction to ensure both updates succeed or fail together, and add a check to verify the user is the team leader before allowing updates to the team document.
| // Fetch problem statement for team members | ||
| if (!response?.problemStatement) { | ||
| if (teamInfo.problemStatement) { | ||
| setProblemStatement(teamInfo.problemStatement); | ||
| setSolution(teamInfo.solution || ""); | ||
| setTechStack(teamInfo.techStack || ""); | ||
| setHasProblemStatement(true); | ||
| } else if (teamInfo.leaderId) { | ||
| // Fallback: Fetch from leader's profile if not on team doc | ||
| const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId)); | ||
| if (leaderDoc.exists()) { | ||
| const leaderData = leaderDoc.data(); | ||
| if (leaderData.problemStatement) { | ||
| setProblemStatement(leaderData.problemStatement); | ||
| setSolution(leaderData.solution || ""); | ||
| setTechStack(leaderData.techStack || ""); | ||
| setHasProblemStatement(true); | ||
| } |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for fetching the problem statement is duplicated across multiple conditional branches. The same pattern of setting problemStatement, solution, and techStack appears three times (lines 78-81, 88-91, and earlier in lines 52-57). Consider extracting this into a helper function to improve maintainability and reduce code duplication.
| // Fetch problem statement for team members | |
| if (!response?.problemStatement) { | |
| if (teamInfo.problemStatement) { | |
| setProblemStatement(teamInfo.problemStatement); | |
| setSolution(teamInfo.solution || ""); | |
| setTechStack(teamInfo.techStack || ""); | |
| setHasProblemStatement(true); | |
| } else if (teamInfo.leaderId) { | |
| // Fallback: Fetch from leader's profile if not on team doc | |
| const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId)); | |
| if (leaderDoc.exists()) { | |
| const leaderData = leaderDoc.data(); | |
| if (leaderData.problemStatement) { | |
| setProblemStatement(leaderData.problemStatement); | |
| setSolution(leaderData.solution || ""); | |
| setTechStack(leaderData.techStack || ""); | |
| setHasProblemStatement(true); | |
| } | |
| const applyProblemData = (data: any) => { | |
| if (data && data.problemStatement) { | |
| setProblemStatement(data.problemStatement); | |
| setSolution(data.solution || ""); | |
| setTechStack(data.techStack || ""); | |
| setHasProblemStatement(true); | |
| } | |
| }; | |
| // Fetch problem statement for team members | |
| if (!response?.problemStatement) { | |
| if (teamInfo.problemStatement) { | |
| applyProblemData(teamInfo); | |
| } else if (teamInfo.leaderId) { | |
| // Fallback: Fetch from leader's profile if not on team doc | |
| const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId)); | |
| if (leaderDoc.exists()) { | |
| const leaderData = leaderDoc.data(); | |
| applyProblemData(leaderData); |
| if (!response?.problemStatement) { | ||
| if (teamInfo.problemStatement) { | ||
| setProblemStatement(teamInfo.problemStatement); | ||
| setSolution(teamInfo.solution || ""); | ||
| setTechStack(teamInfo.techStack || ""); | ||
| setHasProblemStatement(true); | ||
| } else if (teamInfo.leaderId) { | ||
| // Fallback: Fetch from leader's profile if not on team doc | ||
| const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId)); | ||
| if (leaderDoc.exists()) { | ||
| const leaderData = leaderDoc.data(); | ||
| if (leaderData.problemStatement) { | ||
| setProblemStatement(leaderData.problemStatement); | ||
| setSolution(leaderData.solution || ""); | ||
| setTechStack(leaderData.techStack || ""); | ||
| setHasProblemStatement(true); | ||
| } |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition checks if the user doesn't have a problem statement in their profile before fetching from team or leader data. However, if a team leader updates the problem statement after a team member has already loaded their profile data, the team member won't see the update until they reload. This could lead to team members viewing stale problem statement data. Consider removing the condition or adding a mechanism to detect when the team's problem statement has been updated more recently than the user's cached version.
| if (!response?.problemStatement) { | |
| if (teamInfo.problemStatement) { | |
| setProblemStatement(teamInfo.problemStatement); | |
| setSolution(teamInfo.solution || ""); | |
| setTechStack(teamInfo.techStack || ""); | |
| setHasProblemStatement(true); | |
| } else if (teamInfo.leaderId) { | |
| // Fallback: Fetch from leader's profile if not on team doc | |
| const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId)); | |
| if (leaderDoc.exists()) { | |
| const leaderData = leaderDoc.data(); | |
| if (leaderData.problemStatement) { | |
| setProblemStatement(leaderData.problemStatement); | |
| setSolution(leaderData.solution || ""); | |
| setTechStack(leaderData.techStack || ""); | |
| setHasProblemStatement(true); | |
| } | |
| if (teamInfo.problemStatement) { | |
| setProblemStatement(teamInfo.problemStatement); | |
| setSolution(teamInfo.solution || ""); | |
| setTechStack(teamInfo.techStack || ""); | |
| setHasProblemStatement(true); | |
| } else if (teamInfo.leaderId) { | |
| // Fallback: Fetch from leader's profile if not on team doc | |
| const leaderDoc = await getDoc(doc(db, "registrations", teamInfo.leaderId)); | |
| if (leaderDoc.exists()) { | |
| const leaderData = leaderDoc.data(); | |
| if (leaderData.problemStatement) { | |
| setProblemStatement(leaderData.problemStatement); | |
| setSolution(leaderData.solution || ""); | |
| setTechStack(leaderData.techStack || ""); | |
| setHasProblemStatement(true); |
No description provided.