Lashtw commited on
Commit
66ccfc2
·
verified ·
1 Parent(s): c520e90

Upload 9 files

Browse files
Files changed (2) hide show
  1. src/services/auth.js +5 -1
  2. src/views/InstructorView.js +23 -22
src/services/auth.js CHANGED
@@ -130,7 +130,11 @@ export async function checkInstructorPermission(user) {
130
 
131
  if (snap.exists()) {
132
  const data = snap.data();
133
- await updateDoc(instructorRef, { lastLogin: serverTimestamp() });
 
 
 
 
134
  return data;
135
  }
136
 
 
130
 
131
  if (snap.exists()) {
132
  const data = snap.data();
133
+ try {
134
+ await updateDoc(instructorRef, { lastLogin: serverTimestamp() });
135
+ } catch (e) {
136
+ console.warn("Failed to update lastLogin (likely permission), proceeding anyway.", e);
137
+ }
138
  return data;
139
  }
140
 
src/views/InstructorView.js CHANGED
@@ -340,37 +340,38 @@ export function setupInstructorEvents() {
340
  // Utility for cleaning prompt indentation
341
  function stripIndent(str) {
342
  if (!str) return '';
343
- // 1. Split into lines
344
- let lines = str.split('\n');
345
 
346
- // 2. Remove leading empty lines (often result of template literals)
347
- while (lines.length > 0 && lines[0].trim() === '') {
348
- lines.shift();
349
- }
350
 
351
- // 3. Remove trailing empty lines
352
- while (lines.length > 0 && lines[lines.length - 1].trim() === '') {
353
- lines.pop();
354
  }
355
 
 
 
 
 
 
356
  if (lines.length === 0) return '';
357
 
358
- // 4. Find min indent
359
- const minIndent = lines.reduce((min, line) => {
360
- if (!line.trim()) return min; // Ignore empty lines
361
- const match = line.match(/^ */);
362
- const indent = match ? match[0].length : 0;
363
- return Math.min(min, indent);
364
- }, Infinity);
 
 
365
 
366
- if (minIndent === Infinity) return str.trim();
367
 
368
- // 5. Strip indent
369
  return lines.map(line => {
370
- if (line.length >= minIndent) {
371
- return line.slice(minIndent);
372
- }
373
- return line;
374
  }).join('\n');
375
  }
376
 
 
340
  // Utility for cleaning prompt indentation
341
  function stripIndent(str) {
342
  if (!str) return '';
 
 
343
 
344
+ // 1. Normalize line endings
345
+ str = str.replace(/\r\n/g, '\n');
 
 
346
 
347
+ // 2. Remove initial empty lines
348
+ while (str.startsWith('\n')) {
349
+ str = str.slice(1);
350
  }
351
 
352
+ // 3. Remove trailing whitespaces
353
+ str = str.trimEnd();
354
+
355
+ // 4. Split
356
+ const lines = str.split('\n');
357
  if (lines.length === 0) return '';
358
 
359
+ // 5. Find common indent
360
+ let minIndent = null;
361
+ for (const line of lines) {
362
+ if (line.trim().length === 0) continue; // Skip empty lines
363
+ const currentIndent = line.match(/^\s*/)[0].length;
364
+ if (minIndent === null || currentIndent < minIndent) {
365
+ minIndent = currentIndent;
366
+ }
367
+ }
368
 
369
+ if (minIndent === null) return str; // All lines empty
370
 
371
+ // 6. Build result
372
  return lines.map(line => {
373
+ if (line.trim().length === 0) return '';
374
+ return line.slice(minIndent);
 
 
375
  }).join('\n');
376
  }
377