Lashtw commited on
Commit
2c33e4e
·
verified ·
1 Parent(s): 5bdcc59

Upload 9 files

Browse files
src/services/classroom.js CHANGED
@@ -464,10 +464,15 @@ export async function getClassSize(roomCode) {
464
  * @param {number} newStage
465
  * @param {string} monsterId (Optional, for persisting specific form)
466
  */
467
- export async function updateUserMonster(userId, newStage, monsterId = null) {
468
  const userRef = doc(db, USERS_COLLECTION, userId);
469
  const data = { monster_stage: newStage };
470
- if (monsterId) data.monster_id = monsterId;
 
 
 
 
 
471
 
472
  await updateDoc(userRef, data);
473
  }
 
464
  * @param {number} newStage
465
  * @param {string} monsterId (Optional, for persisting specific form)
466
  */
467
+ export async function updateUserMonster(userId, newStage, monsterId = undefined) {
468
  const userRef = doc(db, USERS_COLLECTION, userId);
469
  const data = { monster_stage: newStage };
470
+ // If monsterId is explicitly provided (including null/empty string), update it.
471
+ // If undefined, leave as is.
472
+ // We want to allow clearing it (null) or setting 'Egg'.
473
+ if (monsterId !== undefined) {
474
+ data.monster_id = monsterId;
475
+ }
476
 
477
  await updateDoc(userRef, data);
478
  }
src/views/StudentView.js CHANGED
@@ -155,12 +155,19 @@ export async function renderStudentView() {
155
 
156
  // Regression Logic Check
157
  if (actualStage > potentialStage) {
158
- updateUserMonster(userId, potentialStage, null).then(() => {
 
 
 
 
 
 
 
159
  setTimeout(() => window.location.reload(), 500);
160
  });
161
  // Return corrected state temporary
162
  return {
163
- ...calculateMonsterState(currentUserProgress, classSize, { ...userProfile, monster_stage: potentialStage }),
164
  isRegressing: true
165
  };
166
  }
 
155
 
156
  // Regression Logic Check
157
  if (actualStage > potentialStage) {
158
+ // Regression Logic: Pass 'Egg' (or null) to enforce downgrade
159
+ const targetId = potentialStage === 0 ? 'Egg' : null; // If going to 0, force Egg. Else keep null to let system decide? Or should we query?
160
+ // Actually, if we devolve, we lose the specific form. So we should probably reset ID to something generic or clear it.
161
+ // If we go to stage 0, 'Egg' is safe.
162
+ // If we go to stage 1 (from 2), we might want to keep the stage 1 form (if we knew it).
163
+ // But simplifying: just clear the ID so getNextMonster picks default for that stage.
164
+
165
+ updateUserMonster(userId, potentialStage, targetId).then(() => {
166
  setTimeout(() => window.location.reload(), 500);
167
  });
168
  // Return corrected state temporary
169
  return {
170
+ ...calculateMonsterState(currentUserProgress, classSize, { ...userProfile, monster_stage: potentialStage, monster_id: targetId }),
171
  isRegressing: true
172
  };
173
  }