Spaces:
Running

studyspace / index.html
harsh02564's picture
still I can't access setting page it is not responding on clicking on setting and I must be able to delete chapters of any subjects alls - Follow Up Deployment
c972c04 verified
Raw History Blame Contribute Delete
42 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Launchmate Study</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#6366f1',
secondary: '#8b5cf6',
dark: '#0f172a',
darker: '#020617'
}
}
}
}
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #020617;
color: #e2e8f0;
}
.progress-ring__circle {
transition: stroke-dashoffset 0.3s;
transform: rotate(-90deg);
transform-origin: 50% 50%;
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
background: #1e293b;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background-color: #475569;
border-radius: 20px;
}
</style>
</head>
<body class="min-h-screen overflow-x-hidden">
<div class="flex h-screen">
<!-- Sidebar -->
<div class="hidden md:flex flex-col w-64 bg-slate-900 border-r border-slate-800">
<div class="flex items-center justify-between p-4 border-b border-slate-800">
<div class="flex items-center space-x-2">
<div class="w-8 h-8 rounded-full bg-gradient-to-r from-primary to-secondary flex items-center justify-center">
<i class="fas fa-rocket text-white text-sm"></i>
</div>
<span class="text-xl font-bold">Launchmate</span>
</div>
</div>
<div class="flex-1 overflow-y-auto custom-scrollbar p-4">
<div class="space-y-1">
<button id="subjects-btn" class="w-full flex items-center space-x-3 px-3 py-2 rounded-lg bg-slate-800 text-primary">
<i class="fas fa-book"></i>
<span>Subjects</span>
</button>
<button id="progress-btn" class="w-full flex items-center space-x-3 px-3 py-2 rounded-lg hover:bg-slate-800 text-slate-400 hover:text-slate-200">
<i class="fas fa-chart-line"></i>
<span>Progress</span>
</button>
<button id="mobile-settings-btn" class="w-full flex items-center space-x-3 px-3 py-2 rounded-lg hover:bg-slate-800 text-slate-400 hover:text-slate-200">
<i class="fas fa-cog"></i>
<span>Settings</span>
</button>
</div>
</div>
</div>
<!-- Main Content -->
<div class="flex-1 flex flex-col h-screen overflow-hidden bg-slate-950">
<!-- Mobile Header -->
<div class="md:hidden flex items-center justify-between p-4 border-b border-slate-800">
<h1 class="text-xl font-bold flex items-center space-x-2">
<div class="w-8 h-8 rounded-full bg-gradient-to-r from-primary to-secondary flex items-center justify-center">
<i class="fas fa-rocket text-white text-sm"></i>
</div>
<span>Launchmate</span>
</h1>
<button id="mobile-menu-btn" class="p-2 rounded-lg hover:bg-slate-800">
<i class="fas fa-bars"></i>
</button>
</div>
<!-- Mobile Menu -->
<div id="mobile-menu" class="md:hidden hidden absolute top-16 right-2 z-50 w-56 bg-slate-900 rounded-lg shadow-lg border border-slate-800">
<div class="p-2 space-y-1">
<button id="mobile-subjects-btn" class="w-full flex items-center space-x-3 px-3 py-2 rounded-lg bg-slate-800 text-primary">
<i class="fas fa-book"></i>
<span>Subjects</span>
</button>
<button id="mobile-progress-btn" class="w-full flex items-center space-x-3 px-3 py-2 rounded-lg hover:bg-slate-800 text-slate-400 hover:text-slate-200">
<i class="fas fa-chart-line"></i>
<span>Progress</span>
</button>
<button class="w-full flex items-center space-x-3 px-3 py-2 rounded-lg hover:bg-slate-800 text-slate-400 hover:text-slate-200">
<i class="fas fa-cog"></i>
<span>Settings</span>
</button>
</div>
</div>
<!-- Content -->
<div class="flex-1 overflow-y-auto custom-scrollbar">
<!-- Subjects View -->
<div id="subjects-view" class="p-4">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold">Your Subjects</h1>
<button id="add-subject-btn" class="px-3 py-1 bg-primary hover:bg-primary/90 rounded-lg flex items-center space-x-1">
<i class="fas fa-plus text-sm"></i>
<span>Add Subject</span>
</button>
</div>
<div id="subjects-list" class="space-y-4">
<!-- Subjects will be added here dynamically -->
</div>
</div>
<!-- Progress View (Hidden by default) -->
<div id="progress-view" class="hidden p-4">
<h1 class="text-2xl font-bold mb-6">Your Progress</h1>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-4">
<div class="bg-slate-900 p-4 rounded-xl border border-slate-800">
<div class="flex justify-between mb-2">
<span class="text-slate-400">Total Subjects</span>
<span id="total-subjects-count" class="font-semibold">0</span>
</div>
<div class="flex justify-between">
<span class="text-slate-400">Total Chapters</span>
<span id="total-chapters-count" class="font-semibold">0</span>
</div>
</div>
<div class="bg-slate-900 p-4 rounded-xl border border-slate-800">
<div class="flex justify-between mb-2">
<span class="text-slate-400">Completed Chapters</span>
<span id="completed-chapters-count" class="font-semibold">0</span>
</div>
<div class="flex justify-between">
<span class="text-slate-400">Completion %</span>
<span id="completion-percentage" class="font-semibold">0%</span>
</div>
</div>
<div class="bg-slate-900 p-4 rounded-xl border border-slate-800">
<div class="flex items-center justify-between mb-2">
<span class="text-slate-400">Overall Progress</span>
</div>
<div class="w-full bg-slate-800 rounded-full h-2.5">
<div id="overall-progress-bar" class="bg-gradient-to-r from-primary to-secondary h-2.5 rounded-full" style="width: 0%"></div>
</div>
</div>
</div>
<h2 class="text-xl font-semibold mb-4">Subject Breakdown</h2>
<div id="subject-progress-cards" class="grid grid-cols-1 gap-4">
<!-- Progress cards will be added here dynamically -->
</div>
</div>
<!-- Add Subject Modal -->
<div id="add-subject-modal" class="fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center hidden">
<div class="bg-slate-900 rounded-xl border border-slate-800 w-full max-w-md mx-4">
<div class="p-4 border-b border-slate-800">
<h2 class="text-xl font-semibold">Add New Subject</h2>
</div>
<div class="p-4">
<div class="mb-4">
<label class="block text-sm font-medium mb-1">Subject Name</label>
<input id="subject-name-input" type="text" class="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg focus:outline-none focus:ring-1 focus:ring-primary">
</div>
<div class="mb-4">
<label class="block text-sm font-medium mb-1">Or add multiple (comma separated)</label>
<textarea id="batch-subjects-input" class="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg focus:outline-none focus:ring-1 focus:ring-primary h-24" placeholder="Math, Science, History"></textarea>
</div>
</div>
<div class="p-4 border-t border-slate-800 flex justify-end space-x-2">
<button id="cancel-subject-btn" class="px-4 py-2 rounded-lg border border-slate-700 hover:bg-slate-800">Cancel</button>
<button id="save-subject-btn" class="px-4 py-2 rounded-lg bg-primary hover:bg-primary/90">Add Subject</button>
</div>
</div>
</div>
<!-- Add Chapter Modal -->
<div id="add-chapter-modal" class="fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center hidden">
<div class="bg-slate-900 rounded-xl border border-slate-800 w-full max-w-md mx-4">
<div class="p-4 border-b border-slate-800">
<h2 id="add-chapter-modal-title" class="text-xl font-semibold">Add Chapter to <span id="current-subject-title"></span></h2>
</div>
<div class="p-4">
<div class="mb-4">
<label class="block text-sm font-medium mb-1">Chapter Name</label>
<input id="chapter-name-input" type="text" class="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg focus:outline-none focus:ring-1 focus:ring-primary">
</div>
<div class="mb-4">
<label class="block text-sm font-medium mb-1">Or add multiple (comma separated)</label>
<textarea id="batch-chapters-input" class="w-full px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg focus:outline-none focus:ring-1 focus:ring-primary h-24" placeholder="Chapter 1, Chapter 2, Chapter 3"></textarea>
</div>
</div>
<div class="p-4 border-t border-slate-800 flex justify-end space-x-2">
<button id="cancel-chapter-btn" class="px-4 py-2 rounded-lg border border-slate-700 hover:bg-slate-800">Cancel</button>
<button id="save-chapter-btn" class="px-4 py-2 rounded-lg bg-primary hover:bg-primary/90">Add Chapter</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Data structure to store all subjects and chapters
let studyData = JSON.parse(localStorage.getItem('studyData')) || {
subjects: []
};
// Current selected subject for adding chapters
let currentSubjectId = null;
// DOM Elements
const subjectsView = document.getElementById('subjects-view');
const progressView = document.getElementById('progress-view');
const subjectsBtn = document.getElementById('subjects-btn');
const progressBtn = document.getElementById('progress-btn');
const mobileSubjectsBtn = document.getElementById('mobile-subjects-btn');
const mobileProgressBtn = document.getElementById('mobile-progress-btn');
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
const addSubjectBtn = document.getElementById('add-subject-btn');
const addSubjectModal = document.getElementById('add-subject-modal');
const cancelSubjectBtn = document.getElementById('cancel-subject-btn');
const saveSubjectBtn = document.getElementById('save-subject-btn');
const subjectNameInput = document.getElementById('subject-name-input');
const batchSubjectsInput = document.getElementById('batch-subjects-input');
const addChapterModal = document.getElementById('add-chapter-modal');
const chapterNameInput = document.getElementById('chapter-name-input');
const batchChaptersInput = document.getElementById('batch-chapters-input');
const cancelChapterBtn = document.getElementById('cancel-chapter-btn');
const saveChapterBtn = document.getElementById('save-chapter-btn');
const currentSubjectTitle = document.getElementById('current-subject-title');
const subjectsList = document.getElementById('subjects-list');
const subjectProgressCards = document.getElementById('subject-progress-cards');
const totalSubjectsCount = document.getElementById('total-subjects-count');
const totalChaptersCount = document.getElementById('total-chapters-count');
const completedChaptersCount = document.getElementById('completed-chapters-count');
const completionPercentage = document.getElementById('completion-percentage');
const overallProgressBar = document.getElementById('overall-progress-bar');
// Edit chapter name
function editChapter(chapterId) {
const newName = prompt('Enter new chapter name:');
if (newName && newName.trim()) {
for (const subject of studyData.subjects) {
const chapter = subject.chapters.find(c => c.id === chapterId);
if (chapter) {
chapter.name = newName.trim();
saveData();
renderSubjects();
break;
}
}
}
}
// Delete chapter
function deleteChapter(chapterId) {
if (confirm('Are you sure you want to delete this chapter?')) {
for (const subject of studyData.subjects) {
const chapterIndex = subject.chapters.findIndex(c => c.id === chapterId);
if (chapterIndex !== -1) {
subject.chapters.splice(chapterIndex, 1);
saveData();
renderSubjects();
updateProgressMetrics();
break;
}
}
}
}
// Delete subject
function deleteSubject(subjectId) {
if (confirm('Are you sure you want to delete this subject and all its chapters?')) {
const subjectIndex = studyData.subjects.findIndex(s => s.id === subjectId);
if (subjectIndex !== -1) {
studyData.subjects.splice(subjectIndex, 1);
saveData();
renderSubjects();
updateProgressMetrics();
}
}
}
// Initialize the app
function initApp() {
renderSubjects();
updateProgressMetrics();
// Load subjects view by default
showSubjectsView();
}
// Render all subjects
function renderSubjects() {
subjectsList.innerHTML = '';
if (studyData.subjects.length === 0) {
subjectsList.innerHTML = `
<div class="text-center py-10">
<i class="fas fa-book-open text-5xl text-slate-600 mb-4"></i>
<h3 class="text-lg font-semibold text-slate-400 mb-1">No subjects yet</h3>
<p class="text-sm text-slate-500">Add your first subject to get started</p>
</div>
`;
return;
}
studyData.subjects.forEach((subject, subjectIndex) => {
const subjectElement = document.createElement('div');
subjectElement.className = 'bg-slate-900 rounded-xl border border-slate-800 overflow-hidden';
// Count completed chapters in this subject
const completedChapters = subject.chapters.filter(chapter =>
chapter.completion.theory && chapter.completion.revision && chapter.completion.pyq
).length;
const completionPercentage = subject.chapters.length > 0
? Math.round((completedChapters / subject.chapters.length) * 100)
: 0;
subjectElement.innerHTML = `
<div class="p-4">
<div class="flex justify-between items-center mb-2">
<h2 class="font-semibold text-lg">${subject.name}</h2>
<div class="flex items-center space-x-2">
<span class="text-xs text-slate-400">${completedChapters}/${subject.chapters.length} chapters</span>
<button data-subject-id="${subject.id}" class="add-chapter-btn px-2 py-1 text-xs rounded bg-slate-800 hover:bg-slate-700">
<i class="fas fa-plus mr-1"></i> Add Chapter
</button>
<button data-subject-id="${subject.id}" class="delete-subject-btn px-2 py-1 text-xs rounded bg-red-900/50 hover:bg-red-900 text-red-400">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
<div class="flex items-center space-x-2">
<div class="w-full bg-slate-800 rounded-full h-2">
<div class="bg-gradient-to-r from-primary to-secondary h-2 rounded-full" style="width: ${completionPercentage}%"></div>
</div>
<span class="text-xs text-slate-400">${completionPercentage}%</span>
</div>
</div>
<div class="border-t border-slate-800">
<div class="p-4 chapters-list-${subject.id}">
${subject.chapters.length === 0 ? `
<div class="text-center py-4 text-slate-500">
No chapters yet. Add your first chapter to start tracking.
</div>
` : renderChaptersList(subject.chapters)}
</div>
</div>
`;
subjectsList.appendChild(subjectElement);
});
// Add event listeners to all add chapter buttons
document.querySelectorAll('.add-chapter-btn').forEach(btn => {
btn.addEventListener('click', function() {
const subjectId = this.getAttribute('data-subject-id');
openAddChapterModal(subjectId);
});
});
}
// Render chapters list for a subject
function renderChaptersList(chapters) {
return chapters.map(chapter => {
// Calculate completion percentage (0 to 100)
const completedCount = [chapter.completion.theory, chapter.completion.revision, chapter.completion.pyq].filter(Boolean).length;
const completionPercentage = Math.round((completedCount / 3) * 100);
// Calculate stroke dashoffset for circular progress
const circumference = 2 * Math.PI * 14;
const strokeDashoffset = circumference - (completionPercentage / 100) * circumference;
return `
<div class="chapter-item mb-3 last:mb-0" data-chapter-id="${chapter.id}">
<div class="flex items-start">
<div class="relative mr-3 mt-1">
<svg class="w-8 h-8">
<circle
class="progress-ring__circle"
stroke="url(#gradient-${chapter.id})"
stroke-width="3"
fill="transparent"
r="14"
cx="16"
cy="16"
stroke-dasharray="${circumference}"
stroke-dashoffset="${strokeDashoffset}"
/>
<defs>
<linearGradient id="gradient-${chapter.id}" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" stop-color="#6366f1" />
<stop offset="100%" stop-color="#8b5cf6" />
</linearGradient>
</defs>
</svg>
<div class="absolute inset-0 flex items-center justify-center">
${completedCount === 3 ? `
<i class="fas fa-check text-xs text-white"></i>
` : `
<span class="text-xs font-medium">${completedCount}/3</span>
`}
</div>
</div>
<div class="flex-1">
<h3 class="font-medium">${chapter.name}</h3>
<div class="flex flex-wrap gap-2 mt-1">
<button data-check-type="theory" class="checkpoint-btn text-xs px-2 py-1 rounded-md ${chapter.completion.theory ? 'bg-primary/20 text-primary' : 'bg-slate-800 text-slate-400'}">
Theory ${chapter.completion.theory ? '<i class="fas fa-check ml-1"></i>' : ''}
</button>
<button data-check-type="revision" class="checkpoint-btn text-xs px-2 py-1 rounded-md ${chapter.completion.revision ? 'bg-primary/20 text-primary' : 'bg-slate-800 text-slate-400'}">
Revision ${chapter.completion.revision ? '<i class="fas fa-check ml-1"></i>' : ''}
</button>
<button data-check-type="pyq" class="checkpoint-btn text-xs px-2 py-1 rounded-md ${chapter.completion.pyq ? 'bg-primary/20 text-primary' : 'bg-slate-800 text-slate-400'}">
PYQ ${chapter.completion.pyq ? '<i class="fas fa-check ml-1"></i>' : ''}
</button>
</div>
</div>
<div class="ml-2 flex space-x-2">
<button data-chapter-id="${chapter.id}" class="delete-chapter-btn p-1 text-slate-500 hover:text-red-400">
<i class="fas fa-trash text-xs"></i>
</button>
</div>
</div>
</div>
`;
}).join('');
}
// Render progress view
function renderProgressView() {
subjectProgressCards.innerHTML = '';
if (studyData.subjects.length === 0) {
subjectProgressCards.innerHTML = `
<div class="text-center py-10">
<i class="fas fa-chart-pie text-5xl text-slate-600 mb-4"></i>
<h3 class="text-lg font-semibold text-slate-400 mb-1">No data to display</h3>
<p class="text-sm text-slate-500">Add subjects and chapters to track your progress</p>
</div>
`;
return;
}
studyData.subjects.forEach(subject => {
const completedChapters = subject.chapters.filter(chapter =>
chapter.completion.theory && chapter.completion.revision && chapter.completion.pyq
).length;
const completionPercentage = subject.chapters.length > 0
? Math.round((completedChapters / subject.chapters.length) * 100)
: 0;
const card = document.createElement('div');
card.className = 'bg-slate-900 rounded-xl border border-slate-800 p-4';
card.innerHTML = `
<div class="flex justify-between items-start mb-2">
<h3 class="font-semibold">${subject.name}</h3>
<span class="text-sm ${completionPercentage === 100 ? 'text-emerald-400' : completionPercentage > 50 ? 'text-primary' : 'text-amber-400'}">${completionPercentage}%</span>
</div>
<div class="flex items-center space-x-2 mb-3">
<div class="w-full bg-slate-800 rounded-full h-2">
<div class="bg-gradient-to-r from-primary to-secondary h-2 rounded-full" style="width: ${completionPercentage}%"></div>
</div>
</div>
<div class="flex justify-between text-sm text-slate-400">
<span>${completedChapters}/${subject.chapters.length} chapters</span>
<span>${subject.chapters.filter(c => c.completion.theory).length} theory</span>
<span>${subject.chapters.filter(c => c.completion.revision).length} revision</span>
<span>${subject.chapters.filter(c => c.completion.pyq).length} PYQ</span>
</div>
`;
subjectProgressCards.appendChild(card);
});
}
// Update progress metrics
function updateProgressMetrics() {
const totalSubjects = studyData.subjects.length;
let totalChapters = 0;
let completedChapters = 0;
studyData.subjects.forEach(subject => {
totalChapters += subject.chapters.length;
completedChapters += subject.chapters.filter(chapter =>
chapter.completion.theory && chapter.completion.revision && chapter.completion.pyq
).length;
});
const overallCompletion = totalChapters > 0 ? Math.round((completedChapters / totalChapters) * 100) : 0;
totalSubjectsCount.textContent = totalSubjects;
totalChaptersCount.textContent = totalChapters;
completedChaptersCount.textContent = completedChapters;
completionPercentage.textContent = `${overallCompletion}%`;
overallProgressBar.style.width = `${overallCompletion}%`;
}
// Show subjects view
function showSubjectsView() {
subjectsView.classList.remove('hidden');
progressView.classList.add('hidden');
subjectsBtn.classList.add('bg-slate-800', 'text-primary');
subjectsBtn.classList.remove('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
progressBtn.classList.remove('bg-slate-800', 'text-primary');
progressBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
mobileSubjectsBtn.classList.add('bg-slate-800', 'text-primary');
mobileSubjectsBtn.classList.remove('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
mobileProgressBtn.classList.remove('bg-slate-800', 'text-primary');
mobileProgressBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
}
// Show settings view
function showSettingsView() {
subjectsView.classList.add('hidden');
progressView.classList.add('hidden');
document.getElementById('settings-view').classList.remove('hidden');
// Update button states
subjectsBtn.classList.remove('bg-slate-800', 'text-primary');
subjectsBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
progressBtn.classList.remove('bg-slate-800', 'text-primary');
progressBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
mobileSubjectsBtn.classList.remove('bg-slate-800', 'text-primary');
mobileSubjectsBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
mobileProgressBtn.classList.remove('bg-slate-800', 'text-primary');
mobileProgressBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
// Close mobile menu if open
mobileMenu.classList.add('hidden');
}
// Show progress view
function showProgressView() {
subjectsView.classList.add('hidden');
progressView.classList.remove('hidden');
settingsView.classList.add('hidden');
subjectsView.classList.add('hidden');
progressView.classList.remove('hidden');
progressBtn.classList.add('bg-slate-800', 'text-primary');
progressBtn.classList.remove('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
subjectsBtn.classList.remove('bg-slate-800', 'text-primary');
subjectsBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
mobileProgressBtn.classList.add('bg-slate-800', 'text-primary');
mobileProgressBtn.classList.remove('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
mobileSubjectsBtn.classList.remove('bg-slate-800', 'text-primary');
mobileSubjectsBtn.classList.add('text-slate-400', 'hover:bg-slate-800', 'hover:text-slate-200');
renderProgressView();
}
// Open add subject modal
function openAddSubjectModal() {
addSubjectModal.classList.remove('hidden');
subjectNameInput.focus();
}
// Close add subject modal
function closeAddSubjectModal() {
addSubjectModal.classList.add('hidden');
subjectNameInput.value = '';
batchSubjectsInput.value = '';
}
// Open add chapter modal
function openAddChapterModal(subjectId) {
currentSubjectId = subjectId;
const subject = studyData.subjects.find(s => s.id === subjectId);
currentSubjectTitle.textContent = subject.name;
addChapterModal.classList.remove('hidden');
chapterNameInput.focus();
}
// Close add chapter modal
function closeAddChapterModal() {
addChapterModal.classList.add('hidden');
chapterNameInput.value = '';
batchChaptersInput.value = '';
currentSubjectId = null;
}
// Save subject to data
function saveSubject() {
const singleSubject = subjectNameInput.value.trim();
const batchSubjects = batchSubjectsInput.value.trim();
if (singleSubject || batchSubjects) {
if (singleSubject) {
const newSubject = {
id: generateId(),
name: singleSubject,
chapters: []
};
studyData.subjects.push(newSubject);
}
if (batchSubjects) {
const subjectsArray = batchSubjects.split(',')
.map(s => s.trim())
.filter(s => s.length > 0);
subjectsArray.forEach(subjectName => {
const newSubject = {
id: generateId(),
name: subjectName,
chapters: []
};
studyData.subjects.push(newSubject);
});
}
saveData();
renderSubjects();
updateProgressMetrics();
closeAddSubjectModal();
}
}
// Save chapter to data
function saveChapter() {
const singleChapter = chapterNameInput.value.trim();
const batchChapters = batchChaptersInput.value.trim();
if ((singleChapter || batchChapters) && currentSubjectId) {
const subjectIndex = studyData.subjects.findIndex(s => s.id === currentSubjectId);
if (subjectIndex !== -1) {
if (singleChapter) {
const newChapter = {
id: generateId(),
name: singleChapter,
completion: {
theory: false,
revision: false,
pyq: false
}
};
studyData.subjects[subjectIndex].chapters.push(newChapter);
}
if (batchChapters) {
const chaptersArray = batchChapters.split(',')
.map(c => c.trim())
.filter(c => c.length > 0);
chaptersArray.forEach(chapterName => {
const newChapter = {
id: generateId(),
name: chapterName,
completion: {
theory: false,
revision: false,
pyq: false
}
};
studyData.subjects[subjectIndex].chapters.push(newChapter);
});
}
saveData();
renderSubjects();
updateProgressMetrics();
closeAddChapterModal();
}
}
}
// Toggle chapter checkpoint
function toggleChapterCheckpoint(chapterId, checkType) {
for (const subject of studyData.subjects) {
const chapter = subject.chapters.find(c => c.id === chapterId);
if (chapter) {
chapter.completion[checkType] = !chapter.completion[checkType];
saveData();
renderSubjects();
updateProgressMetrics();
// If we're on the progress view, update it too
if (!progressView.classList.contains('hidden')) {
renderProgressView();
}
break;
}
}
}
// Generate unique ID
function generateId() {
return Date.now().toString(36) + Math.random().toString(36).substring(2);
}
// Save data to localStorage
function saveData() {
localStorage.setItem('studyData', JSON.stringify(studyData));
}
// Event Listeners
subjectsBtn.addEventListener('click', showSubjectsView);
progressBtn.addEventListener('click', showProgressView);
mobileSubjectsBtn.addEventListener('click', () => {
showSubjectsView();
mobileMenu.classList.add('hidden');
});
mobileProgressBtn.addEventListener('click', () => {
showProgressView();
mobileMenu.classList.add('hidden');
});
mobileMenuBtn.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
});
addSubjectBtn.addEventListener('click', openAddSubjectModal);
cancelSubjectBtn.addEventListener('click', closeAddSubjectModal);
saveSubjectBtn.addEventListener('click', saveSubject);
cancelChapterBtn.addEventListener('click', closeAddChapterModal);
saveChapterBtn.addEventListener('click', saveChapter);
// Close modals when clicking outside
window.addEventListener('click', (e) => {
if (e.target === addSubjectModal) {
closeAddSubjectModal();
}
if (e.target === addChapterModal) {
closeAddChapterModal();
}
if (!mobileMenu.contains(e.target) && e.target !== mobileMenuBtn) {
mobileMenu.classList.add('hidden');
}
});
// Delegated event listener for checkpoint buttons
subjectsList.addEventListener('click', (e) => {
if (e.target.classList.contains('checkpoint-btn') || e.target.closest('.checkpoint-btn')) {
const btn = e.target.classList.contains('checkpoint-btn') ? e.target : e.target.closest('.checkpoint-btn');
const chapterItem = btn.closest('.chapter-item');
const chapterId = chapterItem.getAttribute('data-chapter-id');
const checkType = btn.getAttribute('data-check-type');
toggleChapterCheckpoint(chapterId, checkType);
}
else if (e.target.classList.contains('edit-chapter-btn') || e.target.closest('.edit-chapter-btn')) {
const btn = e.target.classList.contains('edit-chapter-btn') ? e.target : e.target.closest('.edit-chapter-btn');
const chapterId = btn.getAttribute('data-chapter-id');
editChapter(chapterId);
}
else if (e.target.classList.contains('delete-chapter-btn') || e.target.closest('.delete-chapter-btn')) {
const btn = e.target.classList.contains('delete-chapter-btn') ? e.target : e.target.closest('.delete-chapter-btn');
const chapterId = btn.getAttribute('data-chapter-id');
deleteChapter(chapterId);
}
else if (e.target.classList.contains('delete-subject-btn') || e.target.closest('.delete-subject-btn')) {
const btn = e.target.classList.contains('delete-subject-btn') ? e.target : e.target.closest('.delete-subject-btn');
const subjectId = btn.getAttribute('data-subject-id');
deleteSubject(subjectId);
}
});
// Settings buttons
document.getElementById('settings-btn').addEventListener('click', showSettingsView);
document.getElementById('mobile-settings-btn').addEventListener('click', showSettingsView);
// Initialize the app
document.addEventListener('DOMContentLoaded', initApp);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=harsh02564/studyspace" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>