Skip to content
Merged
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
33 changes: 33 additions & 0 deletions src/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@ export default function Profile() {
if (teamDoc.exists()) {
const teamInfo = teamDoc.data();
setTeamData(teamInfo);

// 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);
}
Comment on lines +75 to +92
Copy link

Copilot AI Jan 1, 2026

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.

Suggested change
// 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);

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +92
Copy link

Copilot AI Jan 1, 2026

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
}
}
}

// Fetch all team members
const membersData = await Promise.all(
Expand Down Expand Up @@ -134,11 +156,22 @@ export default function Profile() {

setSaving(true);
try {
// 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,
});
}
Comment on lines +159 to +173
Copy link

Copilot AI Jan 1, 2026

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.

Copilot uses AI. Check for mistakes.

setHasProblemStatement(true);
setIsEditingProblem(false);
alert("Problem statement saved successfully!");
Expand Down