This commit is contained in:
nate@necloud.us committed 2025-07-14 14:39:38 -04:00
1 parent 364284553b
commit 462c7908a1
7 files changed
+906 -254

No files matched your search

+197 -188
View File
@@ -1,201 +1,210 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spelling App with Roles</title>
<link rel="stylesheet" href="styles.css" />
<!-- 🔧 Script Load Order -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsSHA/2.4.2/sha.js" defer></script>
<script src="js/auth.js" defer></script>
<script src="js/ui.js" defer></script>
<script src="js/themes.js" defer></script>
<script src="js/admin.js" defer></script>
<script src="js/game.js" defer></script>
<script src="js/main.js" defer></script>
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>Spelling App with Roles</title>
<link href="styles.css" rel="stylesheet"/>
<!-- 🔧 Script Load Order -->
<script defer="" src="https://cdnjs.cloudflare.com/ajax/libs/jsSHA/2.4.2/sha.js"></script>
<script defer="" src="js/auth.js"></script>
<script defer="" src="js/ui.js"></script>
<script defer="" src="js/themes.js"></script>
<script src="js/game.js"></script>
<script defer="" src="js/admin.js"></script>
<script defer="" src="js/main.js"></script>
<script defer="" src="js/typing.js"></script>
</head>
<body>
<h1>Spelling Practice</h1>
<!-- 🏳️ Role Banner -->
<div id="roleBanner" class="banner hidden"></div>
<!-- 👤 Login Panel -->
<div id="loginPanel">
<h2>User Login</h2>
<form onsubmit="event.preventDefault(); verifyLogin();">
<input type="text" id="username" placeholder="Username" required />
<input type="password" id="password" placeholder="Password" required />
<button type="submit">Login</button>
</form>
<p id="loginMessage"></p>
</div>
<!-- 🔀 Role-Based Navigation -->
<div id="nav" class="hidden">
<p><strong id="userInfo"></strong></p>
<button onclick="showAdmin()" id="adminBtn" class="hidden">Admin Panel</button>
<button onclick="showStudent()" id="studentBtn" class="hidden">Student Panel</button>
<button onclick="logoutUser()" id="logoutBtn">Log Out</button>
</div>
<!-- 👨‍🏫 Admin Panel -->
<div id="adminPanel" class="hidden">
<h2>👨‍🏫 Admin Panel</h2>
<!-- 🔘 Tabs -->
<div id="adminTabs">
<button onclick="switchTab('tabUsers')" class="active">👤 Manage Users</button>
<button onclick="switchTab('tabWords')">📝 Word Lists</button>
<button onclick="switchTab('tabAnalytics')">📊 Analytics</button>
<button onclick="switchTab('tabResults')">📊 Results</button>
<button onclick="switchTab('tabReports')">📘 Reports</button>
<button onclick="switchTab('tabSessions')">📆 Sessions</button>
<button onclick="switchTab('tabBadges')">🎖 Badges</button>
<button onclick="switchTab('tabTheme')">🎨 Theme</button>
</div>
<!-- 👥 Users Tab -->
<div id="tabUsers" class="adminTab">
<h3>Add New User</h3>
<form onsubmit="event.preventDefault(); addNewUser();">
<input type="text" id="newUsername" placeholder="Username" required />
<input type="password" id="newPassword" placeholder="Password" required />
<select id="newRole">
<option value="student">Student</option>
<option value="admin">Admin</option>
</select>
<button type="submit">Add User</button>
</form>
<h3>Delete Users</h3>
<select id="userDropdown" onchange="selectUserAction(this.value)">
<option value="">-- Select a user --</option>
</select>
</div>
<!-- 📝 Word List Tab -->
<div id="tabWords" class="adminTab hidden">
<h3>Edit Word List for:</h3>
<select id="wordUserSelect" class="word-user-dropdown" onchange="loadWordsForSelectedUser()">
<option value="">-- Select a user --</option>
</select>
<h2>Enter Spelling Words</h2>
<textarea id="wordInput" placeholder="Enter one word per line..."></textarea><br/>
<button onclick="saveWords()">Save Word List</button>
<button onclick="clearWords()">Clear Saved Words</button>
<h3>Upload a Word File</h3>
<input type="file" accept=".txt,.csv" onchange="handleFileUpload(event)" />
<p><strong>Current Word List:</strong></p>
<ul id="wordListDisplay"></ul>
<h3>📋 View Word List by User:</h3>
<select id="viewUserSelect" class="word-user-dropdown" onchange="displayWordListForSelectedUser()">
<option value="">-- Select a user --</option>
</select>
<ul id="userWordListDisplay"></ul>
</div>
<!-- 📊 Results Tab -->
<div id="tabResults" class="adminTab hidden">
<h3>🧾 Student Results Overview</h3>
<button onclick="loadStudentResults()">Refresh Results</button>
<ul id="resultsList"></ul>
</div>
<h1>Spelling Practice</h1>
<!-- 🏳️ Role Banner -->
<div class="banner hidden" id="roleBanner"></div>
<!-- 👤 Login Panel -->
<div id="loginPanel">
<h2>User Login</h2>
<form onsubmit="event.preventDefault(); verifyLogin();">
<input id="username" placeholder="Username" required="" type="text"/>
<input id="password" placeholder="Password" required="" type="password"/>
<button type="submit">Login</button>
</form>
<p id="loginMessage"></p>
</div>
<!-- 🔀 Role-Based Navigation -->
<div class="hidden" id="nav">
<p><strong id="userInfo"></strong></p>
<button class="hidden" id="adminBtn" onclick="showAdmin()">Admin Panel</button>
<button class="hidden" id="studentBtn" onclick="showStudent()">Student Panel</button>
<button id="logoutBtn" onclick="logoutUser()">Log Out</button>
</div>
<!-- 👨‍🏫 Admin Panel -->
<div class="hidden" id="adminPanel">
<h2>👨‍🏫 Admin Panel</h2>
<!-- 🔘 Tabs -->
<div id="adminTabs">
<button class="active" onclick="switchTab('tabUsers')">👤 Manage Users</button>
<button onclick="switchTab('tabWords')">📝 Word Lists</button>
<button onclick="switchTab('tabAnalytics')">📊 Analytics</button>
<button onclick="switchTab('tabResults')">📊 Results</button>
<button onclick="switchTab('tabReports')">📘 Reports</button>
<button onclick="switchTab('tabSessions')">📆 Sessions</button>
<button onclick="switchTab('tabBadges')">🎖 Badges</button>
<button onclick="switchTab('tabTheme')">🎨 Theme</button>
<button onclick="switchTab('tabTyping')">⌨️ Typing Practice</button>
</div>
<!-- 👥 Users Tab -->
<div class="adminTab" id="tabUsers">
<h3>Add New User</h3>
<form onsubmit="event.preventDefault(); addNewUser();">
<input id="newUsername" placeholder="Username" required="" type="text"/>
<input id="newPassword" placeholder="Password" required="" type="password"/>
<select id="newRole">
<option value="student">Student</option>
<option value="admin">Admin</option>
</select>
<button type="submit">Add User</button>
</form>
<h3>Delete Users</h3>
<select id="userDropdown" onchange="selectUserAction(this.value)">
<option value="">-- Select a user --</option>
</select>
</div>
<!-- 📝 Word List Tab -->
<div class="adminTab hidden" id="tabWords">
<h3>Edit Word List for:</h3>
<select class="word-user-dropdown" id="wordUserSelect" onchange="loadWordsForSelectedUser()">
<option value="">-- Select a user --</option>
</select>
<h2>Enter Spelling Words</h2>
<textarea id="wordInput" placeholder="Enter one word per line..."></textarea><br/>
<button onclick="saveWords()">Save Word List</button>
<button onclick="clearWords()">Clear Saved Words</button>
<h3>Upload a Word File</h3>
<input accept=".txt,.csv" onchange="handleFileUpload(event)" type="file"/>
<p><strong>Current Word List:</strong></p>
<ul id="wordListDisplay"></ul>
<h3>📋 View Word List by User:</h3>
<select class="word-user-dropdown" id="viewUserSelect" onchange="displayWordListForSelectedUser()">
<option value="">-- Select a user --</option>
</select>
<ul id="userWordListDisplay"></ul>
</div>
<!-- 📊 Results Tab -->
<div class="adminTab hidden" id="tabResults">
<h3>🧾 Student Results Overview</h3>
<button onclick="loadStudentResults()">Refresh Results</button>
<ul id="resultsList"></ul>
</div>
<!-- 📊 Analytics Tab -->
<div id="tabAnalytics" class="adminTab hidden">
<h3>Smart Analytics Overview</h3>
<ul id="analyticsSummary">
<li><strong>Average Score:</strong> –</li>
<li><strong>Total Completed Sessions:</strong> –</li>
<li><strong>Most Missed Word:</strong> –</li>
</ul>
<h4>Per-Student Breakdown</h4>
<ul id="studentBreakdown"></ul>
<button onclick="refreshAnalytics()">🔄 Refresh</button>
<div class="adminTab hidden" id="tabAnalytics">
<h3>Smart Analytics Overview</h3>
<ul id="analyticsSummary">
<li><strong>Average Score:</strong> –</li>
<li><strong>Total Completed Sessions:</strong> –</li>
<li><strong>Most Missed Word:</strong> –</li>
</ul>
<h4>Per-Student Breakdown</h4>
<ul id="studentBreakdown"></ul>
<button onclick="refreshAnalytics()">🔄 Refresh</button>
</div>
<!-- 🎖 Badges -->
<div id="tabBadges" class="adminTab hidden">
<h3>🎖 Badge Viewer</h3>
<ul id="badgeUserList"></ul>
<div id="badgeDetails" class="hidden">
<h4 id="badgeUserTitle"></h4>
<ul id="badgeUserBadges"></ul>
</div>
<div class="adminTab hidden" id="tabBadges">
<h3>🎖 Badge Viewer</h3>
<ul id="badgeUserList"></ul>
<div class="hidden" id="badgeDetails">
<h4 id="badgeUserTitle"></h4>
<ul id="badgeUserBadges"></ul>
</div>
<!-- 🎨 Theme Tab -->
<div id="tabTheme" class="adminTab hidden">
<h3>🎨 Select Theme</h3>
<select id="themeSelect" onchange="changeTheme(this.value)">
<option value="playground">Playground</option>
<option value="chalkboard">Chalkboard</option>
<option value="galaxy">Galaxy</option>
<option value="nature">Nature</option>
</select>
</div>
</div>
<!-- 🧾 Student Report Viewer -->
<div id="tabReports" class="adminTab hidden">
<h3>📘 Student Progress Report</h3>
<label for="reportUser">Select Student:</label>
<select id="reportUser" onchange="loadStudentReport(this.value)">
<option value="">-- Select --</option>
</select>
<div id="reportContent" class="hidden">
<h4 id="reportTitle"></h4>
<p><strong>Last Score:</strong> <span id="reportScore"></span></p>
<p><strong>Words Attempted:</strong></p>
<ul id="reportWords"></ul>
<p><strong>Badges Earned:</strong></p>
<ul id="reportBadges"></ul>
<button onclick="window.print()">🖨️ Print Report</button>
<button onclick="copyReportToClipboard()">📋 Copy to Clipboard</button>
</div>
</div>
<div id="tabSessions" class="adminTab hidden">
<h3>📘 Archived Sessions</h3>
<label for="sessionUserSelect">Select Student:</label>
<select id="sessionUserSelect" onchange="loadUserSessions(this.value)">
<option value="">-- Select --</option>
</select>
<ul id="userSessionList"></ul>
<!-- 🎨 Theme Tab -->
<div class="adminTab hidden" id="tabTheme">
<h3>🎨 Select Theme</h3>
<select id="themeSelect" onchange="changeTheme(this.value)">
<option value="playground">Playground</option>
<option value="chalkboard">Chalkboard</option>
<option value="galaxy">Galaxy</option>
<option value="nature">Nature</option>
</select>
</div>
<!-- 👩‍🎓 Student Panel -->
<div id="studentPanel" class="hidden">
<div id="toast" class="toast">Welcome, student!</div>
<button id="startGameBtn" class="hidden" onclick="startGame()">Start Game</button>
<div id="wordBox" class="hidden">
<div id="word" class="word-box"></div>
</div>
<div id="inputSection" class="hidden">
<input type="text" id="userInput" placeholder="Type your answer" autocomplete="off" />
<button onclick="submitAnswer()">Submit</button>
</div>
<div id="badgeDisplay" class="badgeSection hidden">
<h3>🎖 Badges Earned</h3>
<ul id="badgeList"></ul>
</div>
<div id="summary" class="hidden"></div>
</div>
</body>
<!-- ⌨️ Typing Practice Tab -->
<div class="adminTab hidden" id="tabTyping">
<h3>⌨️ Typing Challenge Preview</h3>
<label for="typingUserSelect">Select Student:</label>
<select class="word-user-dropdown" id="typingUserSelect" onchange="loadTypingWords(this.value)">
<option value="">-- Select a user --</option>
</select>
<button onclick="startTypingTest()">Start Typing Test</button>
<div class="hidden" id="typingTestArea">
<p><strong>Practice Sentence:</strong></p>
<p class="typing-sentence" id="typingPrompt"></p>
<input autocomplete="off" id="typingInput" placeholder="Type the spelling word here..." type="text"/>
<button onclick="submitTyping()">Submit</button>
<p id="typingFeedback"></p>
</div>
</div>
<!-- 🧾 Student Report Viewer -->
<div class="adminTab hidden" id="tabReports">
<h3>📘 Student Progress Report</h3>
<label for="reportUser">Select Student:</label>
<select id="reportUser" onchange="loadStudentReport(this.value)">
<option value="">-- Select --</option>
</select>
<div class="hidden" id="reportContent">
<h4 id="reportTitle"></h4>
<p><strong>Last Score:</strong> <span id="reportScore"></span></p>
<p><strong>Words Attempted:</strong></p>
<ul id="reportWords"></ul>
<p><strong>Badges Earned:</strong></p>
<ul id="reportBadges"></ul>
<button onclick="window.print()">🖨️ Print Report</button>
<button onclick="copyReportToClipboard()">📋 Copy to Clipboard</button>
</div>
</div>
<div class="adminTab hidden" id="tabSessions">
<h3>📘 Archived Sessions</h3>
<label for="sessionUserSelect">Select Student:</label>
<select id="sessionUserSelect" onchange="loadUserSessions(this.value)">
<option value="">-- Select --</option>
</select>
<ul id="userSessionList"></ul>
</div>
<!-- 👩‍🎓 Student Panel -->
<div class="hidden" id="studentPanel">
<h2>Student Dashboard</h2>
<div class="student-controls">
<button id="startGameBtn" onclick="startGame()">Start Spelling Game</button>
<button id="startTypingBtn" onclick="startTypingPractice()">Start Typing Practice</button>
</div>
<!-- Game Section -->
<div class="hidden" id="gameSection">
<h3>🎮 Spelling Game</h3>
<div class="word-box" id="wordBox"></div>
<div class="hidden" id="inputSection">
<input id="userInput" placeholder="Type the word you saw..." type="text"/>
<button onclick="submitAnswer()">Submit</button>
</div>
</div>
<!-- Typing Practice Section -->
<div class="hidden" id="typingSection">
<h3>Typing Practice</h3>
<p id="typingPrompt">Type the word...</p>
<input id="typingInput" type="text"/>
<button onclick="submitTyping()">Submit</button>
<p id="typingFeedback"></p>
</div>
</div>
<script>
window.addEventListener('DOMContentLoaded', () => {
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (user) {
if (user.role === 'admin') {
showAdmin();
} else {
showStudent();
}
}
});
</script>
<div id="spellingSection"><h3>Spelling Game</h3><p id="spellingPrompt">Word will appear here...</p></div></body>
</html>
+245
View File
@@ -0,0 +1,245 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spelling App with Roles</title>
<link rel="stylesheet" href="styles.css" />
<!-- 🔧 Script Load Order -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsSHA/2.4.2/sha.js" defer></script>
<script src="js/auth.js" defer></script>
<script src="js/ui.js" defer></script>
<script src="js/themes.js" defer></script>
<script src="js/game.js"></script>
<script src="js/admin.js" defer></script>
<script src="js/main.js" defer></script>
<script src="js/typing.js" defer></script>
</head>
<body>
<h1>Spelling Practice</h1>
<!-- 🏳️ Role Banner -->
<div id="roleBanner" class="banner hidden"></div>
<!-- 👤 Login Panel -->
<div id="loginPanel">
<h2>User Login</h2>
<form onsubmit="event.preventDefault(); verifyLogin();">
<input type="text" id="username" placeholder="Username" required />
<input type="password" id="password" placeholder="Password" required />
<button type="submit">Login</button>
</form>
<p id="loginMessage"></p>
</div>
<!-- 🔀 Role-Based Navigation -->
<div id="nav" class="hidden">
<p><strong id="userInfo"></strong></p>
<button onclick="showAdmin()" id="adminBtn" class="hidden">Admin Panel</button>
<button onclick="showStudent()" id="studentBtn" class="hidden">Student Panel</button>
<button onclick="logoutUser()" id="logoutBtn">Log Out</button>
</div>
<!-- 👨‍🏫 Admin Panel -->
<div id="adminPanel" class="hidden">
<h2>👨‍🏫 Admin Panel</h2>
<!-- 🔘 Tabs -->
<div id="adminTabs">
<button onclick="switchTab('tabUsers')" class="active">👤 Manage Users</button>
<button onclick="switchTab('tabWords')">📝 Word Lists</button>
<button onclick="switchTab('tabAnalytics')">📊 Analytics</button>
<button onclick="switchTab('tabResults')">📊 Results</button>
<button onclick="switchTab('tabReports')">📘 Reports</button>
<button onclick="switchTab('tabSessions')">📆 Sessions</button>
<button onclick="switchTab('tabBadges')">🎖 Badges</button>
<button onclick="switchTab('tabTheme')">🎨 Theme</button>
<button onclick="switchTab('tabTyping')">⌨️ Typing Practice</button>
</div>
<!-- 👥 Users Tab -->
<div id="tabUsers" class="adminTab">
<h3>Add New User</h3>
<form onsubmit="event.preventDefault(); addNewUser();">
<input type="text" id="newUsername" placeholder="Username" required />
<input type="password" id="newPassword" placeholder="Password" required />
<select id="newRole">
<option value="student">Student</option>
<option value="admin">Admin</option>
</select>
<button type="submit">Add User</button>
</form>
<h3>Delete Users</h3>
<select id="userDropdown" onchange="selectUserAction(this.value)">
<option value="">-- Select a user --</option>
</select>
</div>
<!-- 📝 Word List Tab -->
<div id="tabWords" class="adminTab hidden">
<h3>Edit Word List for:</h3>
<select id="wordUserSelect" class="word-user-dropdown" onchange="loadWordsForSelectedUser()">
<option value="">-- Select a user --</option>
</select>
<h2>Enter Spelling Words</h2>
<textarea id="wordInput" placeholder="Enter one word per line..."></textarea><br/>
<button onclick="saveWords()">Save Word List</button>
<button onclick="clearWords()">Clear Saved Words</button>
<h3>Upload a Word File</h3>
<input type="file" accept=".txt,.csv" onchange="handleFileUpload(event)" />
<p><strong>Current Word List:</strong></p>
<ul id="wordListDisplay"></ul>
<h3>📋 View Word List by User:</h3>
<select id="viewUserSelect" class="word-user-dropdown" onchange="displayWordListForSelectedUser()">
<option value="">-- Select a user --</option>
</select>
<ul id="userWordListDisplay"></ul>
</div>
<!-- 📊 Results Tab -->
<div id="tabResults" class="adminTab hidden">
<h3>🧾 Student Results Overview</h3>
<button onclick="loadStudentResults()">Refresh Results</button>
<ul id="resultsList"></ul>
</div>
<!-- 📊 Analytics Tab -->
<div id="tabAnalytics" class="adminTab hidden">
<h3>Smart Analytics Overview</h3>
<ul id="analyticsSummary">
<li><strong>Average Score:</strong> –</li>
<li><strong>Total Completed Sessions:</strong> –</li>
<li><strong>Most Missed Word:</strong> –</li>
</ul>
<h4>Per-Student Breakdown</h4>
<ul id="studentBreakdown"></ul>
<button onclick="refreshAnalytics()">🔄 Refresh</button>
</div>
<!-- 🎖 Badges -->
<div id="tabBadges" class="adminTab hidden">
<h3>🎖 Badge Viewer</h3>
<ul id="badgeUserList"></ul>
<div id="badgeDetails" class="hidden">
<h4 id="badgeUserTitle"></h4>
<ul id="badgeUserBadges"></ul>
</div>
</div>
<!-- 🎨 Theme Tab -->
<div id="tabTheme" class="adminTab hidden">
<h3>🎨 Select Theme</h3>
<select id="themeSelect" onchange="changeTheme(this.value)">
<option value="playground">Playground</option>
<option value="chalkboard">Chalkboard</option>
<option value="galaxy">Galaxy</option>
<option value="nature">Nature</option>
</select>
</div>
</div>
<!-- ⌨️ Typing Practice Tab -->
<div id="tabTyping" class="adminTab hidden">
<h3>⌨️ Typing Challenge Preview</h3>
<label for="typingUserSelect">Select Student:</label>
<select id="typingUserSelect" class="word-user-dropdown" onchange="loadTypingWords(this.value)">
<option value="">-- Select a user --</option>
</select>
<button onclick="startTypingTest()">Start Typing Test</button>
<div id="typingTestArea" class="hidden">
<p><strong>Practice Sentence:</strong></p>
<p id="typingPrompt" class="typing-sentence"></p>
<input type="text" id="typingInput" placeholder="Type the spelling word here..." autocomplete="off" />
<button onclick="submitTyping()">Submit</button>
<p id="typingFeedback"></p>
</div>
</div>
<!-- 🧾 Student Report Viewer -->
<div id="tabReports" class="adminTab hidden">
<h3>📘 Student Progress Report</h3>
<label for="reportUser">Select Student:</label>
<select id="reportUser" onchange="loadStudentReport(this.value)">
<option value="">-- Select --</option>
</select>
<div id="reportContent" class="hidden">
<h4 id="reportTitle"></h4>
<p><strong>Last Score:</strong> <span id="reportScore"></span></p>
<p><strong>Words Attempted:</strong></p>
<ul id="reportWords"></ul>
<p><strong>Badges Earned:</strong></p>
<ul id="reportBadges"></ul>
<button onclick="window.print()">🖨️ Print Report</button>
<button onclick="copyReportToClipboard()">📋 Copy to Clipboard</button>
</div>
</div>
<div id="tabSessions" class="adminTab hidden">
<h3>📘 Archived Sessions</h3>
<label for="sessionUserSelect">Select Student:</label>
<select id="sessionUserSelect" onchange="loadUserSessions(this.value)">
<option value="">-- Select --</option>
</select>
<ul id="userSessionList"></ul>
</div>
<!-- 👩‍🎓 Student Panel -->
<div id="studentPanel" class="hidden">
<h2>Student Dashboard</h2>
<div class="student-controls">
<button id="startGameBtn" onclick="startGame()">Start Spelling Game</button>
<button id="startTypingBtn" onclick="startTypingPractice()">Start Typing Practice</button>
</div>
<!-- Game Section -->
<div id="gameSection" class="hidden">
<h3>🎮 Spelling Game</h3>
<div id="wordBox" class="word-box"></div>
<div id="inputSection" class="hidden">
<input type="text" id="userInput" placeholder="Type the word you saw..." />
<button onclick="submitAnswer()">Submit</button>
</div>
</div>
<!-- Typing Practice Section -->
<div id="typingSection" class="hidden">
<h3>Typing Practice</h3>
<p id="typingPrompt">Type the word...</p>
<input type="text" id="typingInput" />
<button onclick="submitTyping()">Submit</button>
<p id="typingFeedback"></p>
</div>
</div>
<script>
window.addEventListener('DOMContentLoaded', () => {
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (user) {
if (user.role === 'admin') {
showAdmin();
} else {
showStudent();
}
}
});
</script>
</body>
</html>
+168 -55
View File
@@ -1,82 +1,118 @@
// 🌍 Game state
let allWords = [], words = [], current = 0, results = [];
let words = [];
let currentWord = '';
let currentIndex = 0;
let results = [];
let typingWords = [];
// 👩‍🎓 Show student interface
function showStudent() {
console.log("🔊 showStudent() executed");
const studentPanel = document.getElementById('studentPanel');
const adminPanel = document.getElementById('adminPanel');
studentPanel?.classList.remove('hidden');
adminPanel?.classList.add('hidden');
setTimeout(() => {
const btn = document.getElementById('startGameBtn');
if (btn) {
console.log("🎯 Button found in delayed reveal");
btn.classList.remove('hidden');
btn.style.display = 'inline-block';
console.log("🔊 Showing student panel");
// Hide admin panel
document.getElementById('adminPanel')?.classList.add('hidden');
// Show student panel and its components
const studentPanel = document.getElementById('studentPanel');
studentPanel?.classList.remove('hidden');
// Get the buttons and explicitly set their properties
const gameBtn = document.getElementById('startGameBtn');
const typingBtn = document.getElementById('startTypingBtn');
if (gameBtn && typingBtn) {
console.log("Found buttons, making visible");
// Remove all possible hiding classes/styles
gameBtn.classList.remove('hidden');
typingBtn.classList.remove('hidden');
// Explicitly set display style
gameBtn.style.cssText = 'display: inline-block !important; visibility: visible !important;';
typingBtn.style.cssText = 'display: inline-block !important; visibility: visible !important;';
} else {
console.warn("⚠️ Button still missing after timeout");
console.error("Could not find game buttons");
}
}, 100);
}
// 🚀 Begin game session
async function startGame() {
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (!user) return;
console.log('🎮 Starting spelling game');
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (!user) {
alert('Please log in first');
return;
}
const res = await fetch(`/getWordList?user=${encodeURIComponent(user.username)}`);
allWords = await res.json();
try {
// Show game section
document.getElementById('gameSection').classList.remove('hidden');
document.getElementById('wordBox').textContent = 'Loading...';
document.getElementById('summary')?.classList.add('hidden');
document.getElementById('badgeDisplay')?.classList.add('hidden');
if (!allWords.length) {
alert("No words found. Please add words in Admin Panel.");
return;
}
// Fetch words
const response = await fetch(`/getWordList?username=${user.username}`);
const data = await response.json();
console.log('Received words:', data);
words = [...allWords];
current = 0;
results = [];
if (!data.words || data.words.length === 0) {
alert('No words found for practice');
return;
}
document.getElementById('summary')?.classList.add('hidden');
document.getElementById('badgeDisplay')?.classList.add('hidden');
showWord();
// Start game
words = [...data.words];
currentIndex = 0;
results = []; // Reset results array
showWord();
} catch (error) {
console.error('Error:', error);
alert('Failed to load words');
}
}
// 🔤 Show a word, then hide after timeout
function showWord() {
const wordBox = document.getElementById('wordBox');
const wordEl = document.getElementById('word');
if (currentIndex >= words.length) {
showSummary();
return;
}
if (!words[current]) {
endGame(); return;
}
currentWord = words[currentIndex];
console.log('Current word:', currentWord);
wordEl.textContent = words[current];
wordBox.classList.remove('hidden');
// Show word briefly then hide
const wordBox = document.getElementById('wordBox');
const inputSection = document.getElementById('inputSection');
wordBox.textContent = currentWord;
inputSection.classList.add('hidden');
setTimeout(() => {
wordBox.classList.add('hidden');
document.getElementById('inputSection').classList.remove('hidden');
document.getElementById('userInput').value = '';
document.getElementById('userInput').focus();
}, 2000);
setTimeout(() => {
wordBox.textContent = '';
inputSection.classList.remove('hidden');
document.getElementById('userInput').value = '';
document.getElementById('userInput').focus();
}, 2000);
}
// 📝 Check user’s answer and move to next
function submitAnswer() {
const input = document.getElementById('userInput').value.trim();
results.push({ word: words[current], attempt: input });
current++;
const input = document.getElementById('userInput').value.trim();
// Record the attempt
results.push({
word: currentWord,
attempt: input
});
document.getElementById('inputSection').classList.add('hidden');
if (current < words.length) {
showWord();
} else {
showSummary();
}
if (input.toLowerCase() === currentWord.toLowerCase()) {
currentIndex++;
document.getElementById('inputSection').classList.add('hidden');
showWord();
} else {
alert('Try again!');
}
}
// 📊 Show results summary
@@ -163,4 +199,81 @@ function retryMissed(missedWords) {
document.getElementById('summary')?.classList.add('hidden');
document.getElementById('badgeDisplay')?.classList.add('hidden');
showWord();
}
// New function to start typing practice
async function startTypingPractice() {
console.log("⌨️ Starting typing practice...");
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (!user) {
console.error("No user logged in");
return;
}
try {
const res = await fetch(`/getWordList?username=${encodeURIComponent(user.username)}`);
const data = await res.json();
const words = data.words || [];
if (!words.length) {
alert("No words found for practice. Please contact your teacher.");
return;
}
// Hide game section, show typing section
document.getElementById('gameSection')?.classList.add('hidden');
document.getElementById('typingSection').classList.remove('hidden');
// Initialize typing practice
localStorage.setItem('typingWords', JSON.stringify(words));
showNextTypingSentence();
} catch (error) {
console.error('Error starting typing practice:', error);
alert('Error loading typing practice. Please try again.');
}
}
function createSentenceWithWord(word) {
const templates = [
`The word to spell is "${word}."`,
`Please spell the word "${word}."`,
`Type the word "${word}" carefully.`,
`Practice spelling "${word}" in this sentence.`
];
return templates[Math.floor(Math.random() * templates.length)];
}
function showNextTypingSentence() {
console.log('Showing next sentence...'); // Debug log
if (!typingWords.length) {
document.getElementById('typingPrompt').textContent = '🎉 All done! Great job!';
document.getElementById('typingInput').disabled = true;
return;
}
const word = typingWords[0];
currentSentence = createSentenceWithWord(word);
console.log('Current sentence:', currentSentence); // Debug log
document.getElementById('typingPrompt').textContent = currentSentence;
document.getElementById('typingInput').value = '';
document.getElementById('typingInput').disabled = false;
document.getElementById('typingInput').focus();
document.getElementById('typingFeedback').textContent = '';
}
function submitTyping() {
const input = document.getElementById('typingInput').value.trim();
const feedback = document.getElementById('typingFeedback');
if (input.toLowerCase() === currentSentence.toLowerCase()) {
feedback.textContent = '✅ Perfect!';
feedback.style.color = 'green';
typingWords.shift(); // Remove completed word
setTimeout(showNextTypingSentence, 1500);
} else {
feedback.textContent = '❌ Try again. Type the exact sentence as shown.';
feedback.style.color = 'red';
}
}
+92
View File
@@ -0,0 +1,92 @@
// js/typing.js
// Global state
const typingState = {
words: [],
currentWord: ''
};
async function startTypingPractice() {
console.log('Starting typing practice');
const user = JSON.parse(localStorage.getItem('loggedInUser'));
if (!user) return;
document.getElementById('gameSection').classList.add('hidden');
document.getElementById('typingSection').classList.remove('hidden');
const typingPrompt = document.getElementById('typingPrompt');
typingPrompt.textContent = 'Loading...';
try {
const response = await fetch(`/getWordList?username=${encodeURIComponent(user.username)}`);
const data = await response.json();
console.log('Words received:', data);
if (data.words?.length) {
typingState.words = [...data.words];
showNextWord();
} else {
typingPrompt.textContent = 'No words available';
}
} catch (error) {
console.error('Error:', error);
typingPrompt.textContent = 'Error loading words';
}
}
function showNextWord() {
const promptEl = document.getElementById('typingPrompt');
const inputEl = document.getElementById('typingInput');
if (!promptEl || !inputEl) return;
if (!typingState.words.length) {
promptEl.textContent = '🎉 Practice complete!';
inputEl.disabled = true;
return;
}
// Handle both string and object formats
const wordObj = typingState.words[0];
typingState.currentWord = typeof wordObj === 'string' ? wordObj : wordObj.word;
console.log('Showing word:', typingState.currentWord);
promptEl.textContent = typingState.currentWord;
promptEl.style.display = 'block';
inputEl.value = '';
inputEl.disabled = false;
inputEl.focus();
}
// Reset input
inputEl.value = '';
inputEl.disabled = false;
inputEl.focus();
function submitTyping() {
const input = document.getElementById('typingInput')?.value.trim() || '';
const feedback = document.getElementById('typingFeedback');
if (!feedback) return;
if (input.toLowerCase() === typingState.currentWord.toLowerCase()) {
feedback.textContent = '✅ Correct!';
feedback.style.color = 'green';
typingState.words.shift();
setTimeout(showNextWord, 1500);
} else {
feedback.textContent = '❌ Try again';
feedback.style.color = 'red';
}
}
// Add event listener for Enter key
document.addEventListener('DOMContentLoaded', () => {
const input = document.getElementById('typingInput');
if (input) {
input.addEventListener('keypress', (e) => {
if (e.key === 'Enter') submitTyping();
});
}
});
+168 -1
View File
@@ -77,7 +77,13 @@ body.nature button {
display: none;
}
#wordBox {
margin-top: 5rem;
font-size: 2em;
margin: 20px;
min-height: 60px;
padding: 20px;
background-color: #f5f5f5;
border-radius: 8px;
transition: opacity 0.3s ease;
}
.word-box {
font-size: 3rem;
@@ -150,3 +156,164 @@ body.nature button {
.adminTab:not(.hidden) {
display: block;
}
.typing-sentence {
font-size: 1.5em;
margin: 20px 0;
padding: 15px;
background-color: #f5f5f5;
border-radius: 8px;
border: 1px solid #ddd;
min-height: 50px;
display: block !important;
visibility: visible !important;
}
/* Remove these style classes if they exist */
.typing-section
.typing-container
.typing-prompt
.input-container
#typingInput
#typingFeedback
/* Fix for start buttons visibility */
#startGameBtn, #startTypingBtn {
display: inline-block;
margin: 10px;
padding: 12px 24px;
font-size: 1.1em;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
#startGameBtn:hover, #startTypingBtn:hover {
transform: scale(1.05);
background-color: #45a049;
}
/* Override any hidden class for these buttons */
#startGameBtn.hidden, #startTypingBtn.hidden {
display: none !important;
}
/* Button container for better spacing */
.button-container {
margin: 20px 0;
padding: 10px;
text-align: center;
}
.student-controls {
display: block !important;
margin: 20px auto;
padding: 15px;
text-align: center;
visibility: visible !important;
}
.student-btn {
display: inline-block !important;
visibility: visible !important;
background-color: #4CAF50;
color: white;
padding: 12px 24px;
margin: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
opacity: 1 !important;
}
/* Override any hiding classes for these specific buttons */
#startGameBtn:not(.hidden),
#startTypingBtn:not(.hidden) {
display: inline-block !important;
visibility: visible !important;
opacity: 1 !important;
}
/* Remove this if it exists as it might conflict */
.hidden {
display: none !important;
}
/* Add this to ensure student panel shows properly */
#studentPanel:not(.hidden) {
display: block !important;
}
/* 📝 Typing Practice Styles */
.typing-section {
max-width: 800px;
margin: 20px auto;
padding: 20px;
}
#typingPrompt {
font-size: 2em;
font-weight: bold;
text-align: center;
margin: 20px 0;
padding: 20px;
background: #f5f5f5;
border-radius: 8px;
min-height: 60px;
display: block !important;
visibility: visible !important;
}
#typingInput {
width: 300px;
padding: 10px;
font-size: 18px;
margin-right: 10px;
}
.typing-word {
font-size: 32px;
font-weight: bold;
text-align: center;
padding: 20px;
margin: 20px 0;
background: #f5f5f5;
border-radius: 8px;
min-height: 50px;
display: block !important;
visibility: visible !important;
}
.typing-input-container {
text-align: center;
margin: 20px 0;
}
/* Fix student panel buttons */
#startGameBtn, #startTypingBtn {
display: inline-block;
margin: 10px;
padding: 12px 24px;
font-size: 1.1em;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
visibility: visible !important;
}
/* Ensure student panel visibility */
#studentPanel:not(.hidden) {
display: block !important;
}
/* Remove any conflicting hidden styles */
#startGameBtn:not(.hidden),
#startTypingBtn:not(.hidden) {
display: inline-block !important;
visibility: visible !important;
}