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

Upload 9 files

Browse files
Files changed (1) hide show
  1. src/views/InstructorView.js +39 -31
src/views/InstructorView.js CHANGED
@@ -338,41 +338,46 @@ export async function renderInstructorView() {
338
  export function setupInstructorEvents() {
339
  // Utility for cleaning prompt indentation
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
 
378
  let roomUnsubscribe = null;
@@ -1278,7 +1283,7 @@ export function setupInstructorEvents() {
1278
  document.getElementById('broadcast-content').classList.add('hidden');
1279
  const stage = document.getElementById('stage-view');
1280
  stage.classList.remove('hidden');
1281
- document.getElementById('stage-prompt').textContent = stripIndent(prompt || '');
1282
  document.getElementById('stage-author').textContent = author;
1283
  };
1284
 
@@ -1392,7 +1397,7 @@ export function setupInstructorEvents() {
1392
  onchange="handlePromptSelection(this)">
1393
  </div>
1394
  <!-- Prompt Content -->
1395
- <div class="bg-black/30 rounded p-2 flex-1 overflow-y-auto font-mono text-green-300 whitespace-pre-wrap custom-scrollbar text-base leading-snug group-hover:text-green-200 transaction-colors mb-2">${stripIndent(p.prompt)}</div>
1396
 
1397
  <!-- Footer: Time + Actions -->
1398
  <div class="flex justify-between items-center text-[10px] text-gray-500 mt-auto">
@@ -1570,8 +1575,8 @@ export function setupInstructorEvents() {
1570
  <p class="text-md text-gray-400 truncate" title="${item.title}">${item.title}</p>
1571
  </div>
1572
  <!-- Prompt Content: Larger Text (text-4xl) -->
1573
- <div class="flex-1 overflow-y-auto font-mono text-green-300 text-3xl leading-relaxed whitespace-pre-wrap p-2 hover:bg-white/5 transition-colors rounded custom-scrollbar text-left">
1574
- ${stripIndent(item.prompt)}
1575
  </div>
1576
  `;
1577
  grid.appendChild(col);
@@ -1887,7 +1892,10 @@ export function setupInstructorEvents() {
1887
  document.getElementById('broadcast-author').textContent = student.nickname;
1888
  document.getElementById('broadcast-challenge').textContent = title;
1889
  // content is already just text, but let's be safe
1890
- document.getElementById('broadcast-prompt').textContent = stripIndent(p.prompt || p.code || ''); // robust fallback
 
 
 
1891
 
1892
  // Store IDs for actions
1893
  modal.dataset.userId = userId;
 
338
  export function setupInstructorEvents() {
339
  // Utility for cleaning prompt indentation
340
  // Utility for cleaning prompt indentation
341
+ // Utility for cleaning text for display
342
+ function cleanText(str, isCode = false) {
343
  if (!str) return '';
344
 
345
  // 1. Normalize line endings
346
  str = str.replace(/\r\n/g, '\n');
347
 
348
+ if (isCode) {
349
+ // Smart Dedent for Code (Preserve relative indent)
350
+ while (str.startsWith('\n')) str = str.slice(1);
351
+ str = str.trimEnd();
 
 
 
352
 
353
+ const lines = str.split('\n');
354
+ if (lines.length === 0) return '';
 
355
 
356
+ let minIndent = null;
357
+ for (const line of lines) {
358
+ if (line.trim().length === 0) continue;
359
+ const currentIndent = line.match(/^\s*/)[0].length;
360
+ if (minIndent === null || currentIndent < minIndent) {
361
+ minIndent = currentIndent;
362
+ }
363
  }
364
+ if (minIndent === null) return str;
365
+ return lines.map(line => {
366
+ if (line.trim().length === 0) return '';
367
+ return line.slice(minIndent);
368
+ }).join('\n');
369
+ } else {
370
+ // Aggressive Flatten for Text Prompts (Force Left Align)
371
+ return str.split('\n')
372
+ .map(line => line.trimStart()) // Remove ALL leading space from every line
373
+ .filter((line, index, arr) => {
374
+ // Remove leading/trailing empty lines
375
+ if (line.trim() === '' && (index === 0 || index === arr.length - 1)) return false;
376
+ return true;
377
+ })
378
+ .join('\n')
379
+ .trim();
380
  }
 
 
 
 
 
 
 
 
381
  }
382
 
383
  let roomUnsubscribe = null;
 
1283
  document.getElementById('broadcast-content').classList.add('hidden');
1284
  const stage = document.getElementById('stage-view');
1285
  stage.classList.remove('hidden');
1286
+ document.getElementById('stage-prompt').textContent = cleanText(prompt || '');
1287
  document.getElementById('stage-author').textContent = author;
1288
  };
1289
 
 
1397
  onchange="handlePromptSelection(this)">
1398
  </div>
1399
  <!-- Prompt Content -->
1400
+ <div class="bg-black/30 rounded p-2 flex-1 overflow-y-auto font-mono text-green-300 whitespace-pre-wrap custom-scrollbar text-base leading-snug group-hover:text-green-200 transaction-colors mb-2" style="text-align: left;">${cleanText(p.prompt)}</div>
1401
 
1402
  <!-- Footer: Time + Actions -->
1403
  <div class="flex justify-between items-center text-[10px] text-gray-500 mt-auto">
 
1575
  <p class="text-md text-gray-400 truncate" title="${item.title}">${item.title}</p>
1576
  </div>
1577
  <!-- Prompt Content: Larger Text (text-4xl) -->
1578
+ <div class="flex-1 overflow-y-auto font-mono text-green-300 text-3xl leading-relaxed whitespace-pre-wrap p-2 hover:bg-white/5 transition-colors rounded custom-scrollbar text-left" style="text-align: left !important;">
1579
+ ${cleanText(item.prompt)}
1580
  </div>
1581
  `;
1582
  grid.appendChild(col);
 
1892
  document.getElementById('broadcast-author').textContent = student.nickname;
1893
  document.getElementById('broadcast-challenge').textContent = title;
1894
  // content is already just text, but let's be safe
1895
+ const rawText = p.prompt || p.code || '';
1896
+ const isCode = !p.prompt && !!p.code; // If only code exists, treat as code
1897
+ document.getElementById('broadcast-prompt').textContent = cleanText(rawText, isCode);
1898
+ document.getElementById('broadcast-prompt').style.textAlign = isCode ? 'left' : 'left'; // Always left, but explicit
1899
 
1900
  // Store IDs for actions
1901
  modal.dataset.userId = userId;