Skip to content

Commit 02233c4

Browse files
committed
feat: add button to export student names to clipboard as CSV
1 parent 5e3c331 commit 02233c4

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

my-space/my-class/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ <h2 id="classNameDisplay" class="font-heading font-bold text-3xl text-slate-900
286286

287287
<!-- Tabs Content -->
288288
<div id="content-students" class="tab-content space-y-6">
289+
<div class="flex items-center justify-between">
290+
<h3 class="font-heading font-bold text-xl text-slate-900 dark:text-white uppercase tracking-tight">Student Roster</h3>
291+
<button onclick="StudentManager.copyToClipboard()" class="btn-chunky bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300 px-4 py-2 rounded-xl border-[3px] border-slate-800 dark:border-slate-500 text-[10px] font-black uppercase shadow-hard-sm flex items-center gap-2">
292+
<i data-lucide="copy" class="w-4 h-4"></i> Copy Class
293+
</button>
294+
</div>
289295
<div id="noStudentsState" class="hidden glass-panel border-4 border-dashed border-slate-200 dark:border-slate-800 rounded-[2.5rem] p-12 text-center bg-slate-50/30">
290296
<div class="w-16 h-16 bg-blue/10 dark:bg-blue/5 rounded-2xl flex items-center justify-center mx-auto mb-4 text-blue">
291297
<i data-lucide="user-plus" class="w-8 h-8"></i>

my-space/my-class/script.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,26 @@ const TabManager = {
346346
const StudentManager = {
347347
entryMode: 'single',
348348

349+
copyToClipboard() {
350+
const classData = ClassManager.data.classes[ClassManager.activeClass];
351+
if (!classData || !classData.students || classData.students.length === 0) {
352+
UI.showToast('No students to copy', 'warning');
353+
return;
354+
}
355+
356+
const namesString = classData.students
357+
.map(s => s.name || '')
358+
.filter(name => name.trim() !== '')
359+
.join(',');
360+
361+
navigator.clipboard.writeText(namesString).then(() => {
362+
UI.showToast('Student names copied as CSV!', 'success');
363+
}).catch(err => {
364+
console.error('Failed to copy text: ', err);
365+
UI.showToast('Failed to copy to clipboard', 'error');
366+
});
367+
},
368+
349369
render() {
350370
const grid = document.getElementById('studentGrid');
351371
const empty = document.getElementById('noStudentsState');

0 commit comments

Comments
 (0)