Repository navigation
Expand file tree
/
Copy pathapp.js
More file actions
1668 lines (1505 loc) · 56.4 KB
/
Copy pathapp.js
File metadata and controls
1668 lines (1505 loc) · 56.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DeskOS V1 - Main application JavaScript
// Storage helper
const Storage = {
// Settings
getSettings() {
const settings = localStorage.getItem('deskosSettings');
return settings ? JSON.parse(settings) : {
theme: 'dark', // dark, light, auto
showWeather: true,
showTodo: true,
showSchool: true,
showMovies: true,
showGaming: true,
clockFormat: '12', // 12 or 24
displayName: '',
location: '',
greeting: '',
nightMode: false
};
},
saveSettings(settings) {
localStorage.setItem('deskosSettings', JSON.stringify(settings));
},
// Tasks
getTasks() {
try {
const tasks = localStorage.getItem('deskosTasks');
return tasks ? JSON.parse(tasks) : [];
} catch (e) {
console.error('Error parsing tasks from localStorage:', e);
return [];
}
},
saveTasks(tasks) {
try {
localStorage.setItem('deskosTasks', JSON.stringify(tasks));
} catch (e) {
console.error('Error saving tasks to localStorage:', e);
}
},
// School
getSchool() {
try {
const school = localStorage.getItem('deskosSchool');
return school ? JSON.parse(school) : {
currentClass: {
subject: '',
time: '',
room: '',
notes: ''
},
upcoming: [],
timetable: [] // Added timetable for storing all classes
};
} catch (e) {
console.error('Error parsing school from localStorage:', e);
return {
currentClass: {
subject: '',
time: '',
room: '',
notes: ''
},
upcoming: [],
timetable: []
};
}
},
saveSchool(school) {
try {
localStorage.setItem('deskosSchool', JSON.stringify(school));
} catch (e) {
console.error('Error saving school to localStorage:', e);
}
},
// Movie
getMovie() {
try {
const movie = localStorage.getItem('deskosMovie');
return movie ? JSON.parse(movie) : {
title: '',
rating: 0,
poster: '',
runtime: '',
notes: ''
};
} catch (e) {
console.error('Error parsing movie from localStorage:', e);
return {
title: '',
rating: 0,
poster: '',
runtime: '',
notes: ''
};
}
},
saveMovie(movie) {
try {
localStorage.setItem('deskosMovie', JSON.stringify(movie));
} catch (e) {
console.error('Error saving movie to localStorage:', e);
}
},
// Gaming
getGaming() {
try {
const gaming = localStorage.getItem('deskosGaming');
return gaming ? JSON.parse(gaming) : {
game: '',
goal: '',
progress: 0
};
} catch (e) {
console.error('Error parsing gaming from localStorage:', e);
return {
game: '',
goal: '',
progress: 0
};
}
},
saveGaming(gaming) {
try {
localStorage.setItem('deskosGaming', JSON.stringify(gaming));
} catch (e) {
console.error('Error saving gaming to localStorage:', e);
}
},
// Weather (we'll store last fetched data and timestamp)
getWeather() {
try {
const weather = localStorage.getItem('deskosWeather');
return weather ? JSON.parse(weather) : {
temperature: '--',
condition: '--',
icon: '',
timestamp: 0
};
} catch (e) {
console.error('Error parsing weather from localStorage:', e);
return {
temperature: '--',
condition: '--',
icon: '',
timestamp: 0
};
}
},
saveWeather(weather) {
try {
localStorage.setItem('deskosWeather', JSON.stringify(weather));
} catch (e) {
console.error('Error saving weather to localStorage:', e);
}
}
};
// App state
let state = {
settings: Storage.getSettings(),
tasks: Storage.getTasks(),
school: Storage.getSchool(),
movie: Storage.getMovie(),
gaming: Storage.getGaming(),
weather: Storage.getWeather(),
currentSection: 'home' // home, school, movie, gaming, settings
};
// DOM elements
let elements = {};
// Initialize the app
function initApp() {
// Cache DOM elements
cacheElements();
// Render the app
render();
// Start clock update
startClock();
// Load initial data (if any)
loadInitialData();
}
// Cache DOM elements
function cacheElements() {
elements.app = document.getElementById('app');
// We'll populate more as we build components
}
// Render the entire app
function render() {
// Based on settings, show the appropriate layout
const appElement = document.getElementById('app');
if (!appElement) return;
appElement.innerHTML = `
<div class="app-container">
<!-- Header -->
<header class="app-header">
<div class="header-content">
<h1 class="app-title">DeskOS</h1>
</div>
</header>
<!-- Main content -->
<main class="app-main">
<!-- Content will be rendered here based on currentSection -->
<div id="section-content"></div>
</main>
<!-- Navigation bar -->
<nav class="app-nav">
<button class="nav-btn" data-section="home">
<span class="nav-icon">🏠</span>
<span class="nav-label">Home</span>
</button>
<button class="nav-btn" data-section="school">
<span class="nav-icon">📚</span>
<span class="nav-label">School</span>
</button>
<button class="nav-btn" data-section="movie">
<span class="nav-icon">🎬</span>
<span class="nav-label">Movies</span>
</button>
<button class="nav-btn" data-section="gaming">
<span class="nav-icon">🎮</span>
<span class="nav-label">Gaming</span>
</button>
<button class="nav-btn" data-section="settings">
<span class="nav-icon">⚙️</span>
<span class="nav-label">Settings</span>
</button>
</nav>
</div>
`;
// Render the current section
renderSection();
// Apply theme
applyTheme();
// Attach navigation event listeners
attachNavigationListeners();
}
// Render the current section
function renderSection() {
const content = document.getElementById('section-content');
if (!content) return;
switch (state.currentSection) {
case 'home':
renderHomeSection();
break;
case 'school':
renderSchoolSection();
break;
case 'movie':
renderMovieSection();
break;
case 'gaming':
renderGamingSection();
break;
case 'settings':
renderSettingsSection();
break;
default:
renderHomeSection();
}
}
// Render the home section (dashboard with cards)
function renderHomeSection() {
const content = document.getElementById('section-content');
content.innerHTML = `
<div class="dashboard">
<!-- We'll build the dashboard here -->
<div class="clock-container">
<div id="clock" class="clock">--:--</div>
<div id="date" class="date">--/--/----</div>
</div>
<div id="cards-container" class="cards-container">
<!-- Cards will be injected here -->
</div>
</div>
`;
// Render the cards
renderCards();
// Apply theme
applyTheme();
// Attach event listeners for cards
attachEventListeners();
}
// Render the cards based on settings (for home section)
function renderCards() {
const container = document.getElementById('cards-container');
if (!container) return; // Not in home section
container.innerHTML = ''; // Clear
// We'll create a card for each enabled section
const fragments = [];
if (state.settings.showWeather) {
fragments.push(renderWeatherCard());
}
if (state.settings.showTodo) {
fragments.push(renderTodoCard());
}
if (state.settings.showSchool) {
fragments.push(renderSchoolCard());
}
if (state.settings.showMovies) {
fragments.push(renderMovieCard());
}
if (state.settings.showGaming) {
fragments.push(renderGamingCard());
}
// Append all fragments
fragments.forEach(fragment => {
container.appendChild(fragment);
});
}
// Create a card element with a given title and content
function createCard(title, content) {
const card = document.createElement('div');
card.className = 'card';
card.innerHTML = `
<div class="card-header">
<h2>${title}</h2>
</div>
<div class="card-content">
${content}
</div>
`;
return card;
}
// Weather card
function renderWeatherCard() {
const weather = state.weather;
const content = `
<div class="weather-info">
<div class="weather-temperature">${weather.temperature}</div>
<div class="weather-condition">${weather.condition}</div>
<div class="weather-icon">${weather.icon}</div>
</div>
`;
return createCard('Weather', content);
}
// To-Do card
function renderTodoCard() {
// We'll build a simple list for now
const tasks = state.tasks;
const incompleteTasks = tasks.filter(t => !t.completed);
const completeTasks = tasks.filter(t => t.completed);
const remainingCount = incompleteTasks.length;
let tasksHTML = '';
// Incomplete tasks
incompleteTasks.forEach(task => {
const priorityColor = task.priority === 'high' ? '#ff5252' : task.priority === 'medium' ? '#ffb74d' : '#81c784';
tasksHTML += `
<div class="todo-item" data-id="${task.id}">
<div class="todo-left">
<input type="checkbox" ${task.completed ? 'checked' : ''}>
<span class="todo-text">${task.text}</span>
</div>
<div class="todo-right">
<span class="priority" style="background-color: ${priorityColor};"></span>
${task.dueDate ? `<span class="due-date">${task.dueDate}</span>` : ''}
<button class="todo-edit-btn" data-id="${task.id}" title="Edit">✏️</button>
<button class="todo-delete-btn" data-id="${task.id}" title="Delete">🗑️</button>
</div>
</div>
`;
});
// Completed tasks (we'll show them below, maybe collapsed)
if (completeTasks.length > 0) {
tasksHTML += `<div class="divider"></div>`;
tasksHTML += `<div class="completed-section"><h3>Completed (${completeTasks.length})</h3>`;
completeTasks.forEach(task => {
tasksHTML += `
<div class="todo-item completed" data-id="${task.id}">
<div class="todo-left">
<input type="checkbox" checked>
<span class="todo-text completed-text">${task.text}</span>
</div>
<div class="todo-right">
<span class="priority" style="background-color: #81c784;"></span>
<button class="todo-edit-btn" data-id="${task.id}" title="Edit">✏️</button>
<button class="todo-delete-btn" data-id="${task.id}" title="Delete">🗑️</button>
</div>
</div>
`;
});
tasksHTML += `</div>`;
}
// Add task button
tasksHTML += `<div class="add-task-container"><button id="add-task-btn">+ Add Task</button></div>`;
// Remaining tasks count
tasksHTML += `<div class="todo-count">${remainingCount} ${remainingCount === 1 ? 'task' : 'tasks'} remaining</div>`;
const content = `<div class="todo-list">${tasksHTML}</div>`;
const card = createCard('To-Do List', content);
// We'll add event listeners later
return card;
}
// School card (for home section - shows current/next class)
function renderSchoolCard() {
const school = state.school;
const current = getCurrentClass();
const nextClass = getNextClass();
let content = '';
if (current) {
content += `
<div class="current-class">
<div class="current-label">NOW</div>
<div class="class-subject">${current.subject}</div>
<div class="class-time">${current.time}</div>
<div class="class-room">${current.room}</div>
${current.notes ? `<div class="class-notes">${current.notes}</div>` : ''}
</div>
`;
} else {
content += `<div class="empty-state">No current class</div>`;
}
if (nextClass && nextClass !== current) {
content += `<div class="divider"></div><div class="upcoming-label">UP NEXT</div>`;
content += `
<div class="upcoming-item">
<div class="upcoming-subject">${nextClass.subject}</div>
<div class="upcoming-time">${nextClass.time}</div>
<div class="upcoming-room">${nextClass.room}</div>
</div>
`;
} else if (!current) {
// If no current class, show next class as the main item
if (nextClass) {
content += `
<div class="current-class">
<div class="current-label">UP NEXT</div>
<div class="class-subject">${nextClass.subject}</div>
<div class="class-time">${nextClass.time}</div>
<div class="class-room">${nextClass.room}</div>
${nextClass.notes ? `<div class="class-notes">${nextClass.notes}</div>` : ''}
</div>
`;
} else {
content += `<div class="empty-state">No classes scheduled</div>`;
}
}
const card = createCard('School', content);
return card;
}
// Movie card
function renderMovieCard() {
const movie = state.movie;
const content = `
<div class="movie-info">
${movie.poster ? `<img src="${movie.poster}" alt="Poster" class="movie-poster">` : ''}
<div class="movie-details">
<div class="movie-title">${movie.title}</div>
<div class="movie-rating">★ ${movie.rating}</div>
${movie.runtime ? `<div class="movie-runtime">${movie.runtime}</div>` : ''}
${movie.notes ? `<div class="movie-notes">${movie.notes}</div>` : ''}
</div>
</div>
`;
// Add edit button
const card = createCard('Currently Watching', content);
// We'll add event listener for editing after card is created
return card;
}
// Gaming card
function renderGamingCard() {
const gaming = state.gaming;
const progressPercent = gaming.progress ? parseInt(gaming.progress) : 0;
const content = `
<div class="gaming-info">
<div class="game-title">${gaming.game}</div>
<div class="game-goal">Current goal: ${gaming.goal}</div>
<div class="game-progress">
<div class="progress-bar">
<div class="progress-fill" style="width: ${progressPercent}%;"></div>
</div>
<div class="progress-text">${progressPercent}%</div>
</div>
</div>
`;
// Add edit button
const card = createCard('Gaming', content);
// We'll add event listener for editing after card is created
return card;
}
// Get current class based on time
function getCurrentClass() {
const now = new Date();
const currentTime = now.getHours() * 60 + now.getMinutes(); // Minutes since midnight
// Check timetable for current class
for (const cls of state.school.timetable) {
if (!cls.startTime || !cls.endTime) continue;
const [startHours, startMinutes] = cls.startTime.split(':').map(Number);
const [endHours, endMinutes] = cls.endTime.split(':').map(Number);
const startTime = startHours * 60 + startMinutes;
const endTime = endHours * 60 + endMinutes;
if (currentTime >= startTime && currentTime <= endTime) {
return cls;
}
}
// Fallback to currentClass if timetable is empty
if (state.school.currentClass.subject) {
return state.school.currentClass;
}
return null;
}
// Get next class based on time
function getNextClass() {
const now = new Date();
const currentTime = now.getHours() * 60 + now.getMinutes(); // Minutes since midnight
let nextClass = null;
let minTimeDiff = Infinity;
// Check timetable for next class
for (const cls of state.school.timetable) {
if (!cls.startTime) continue;
const [startHours, startMinutes] = cls.startTime.split(':').map(Number);
const startTime = startHours * 60 + startMinutes;
if (startTime > currentTime) {
const timeDiff = startTime - currentTime;
if (timeDiff < minTimeDiff) {
minTimeDiff = timeDiff;
nextClass = cls;
}
}
}
return nextClass;
}
// Apply theme based on settings
function applyTheme() {
const root = document.documentElement;
if (state.settings.theme === 'dark') {
root.setAttribute('data-theme', 'dark');
} else if (state.settings.theme === 'light') {
root.setAttribute('data-theme', 'light');
} else {
// auto - follow system preference
root.removeAttribute('data-theme');
}
}
// Start the clock update
function startClock() {
updateClock();
setInterval(updateClock, 1000);
}
function updateClock() {
const now = new Date();
let hours = now.getHours();
const minutes = now.getMinutes().toString().padStart(2, '0');
if (state.settings.clockFormat === '12') {
const suffix = hours >= 12 ? ' PM' : ' AM';
hours = hours % 12;
hours = hours === 0 ? 12 : hours;
hours = hours.toString().padStart(2, '0');
document.getElementById('clock').textContent = `${hours}:${minutes}${suffix}`;
} else {
hours = hours.toString().padStart(2, '0');
document.getElementById('clock').textContent = `${hours}:${minutes}`;
}
// Date
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
const dateString = now.toLocaleDateString(undefined, options);
document.getElementById('date').textContent = dateString;
}
// Load initial data (sample data if no user data exists)
function loadInitialData() {
// If no tasks, add sample tasks
if (state.tasks.length === 0) {
state.tasks = [
{ id: 1, text: 'Finish Technology project', completed: false, priority: 'high', dueDate: '' },
{ id: 2, text: 'Pack school bag', completed: false, priority: 'medium', dueDate: '' },
{ id: 3, text: 'Do Maths homework', completed: false, priority: 'low', dueDate: '' }
];
Storage.saveTasks(state.tasks);
}
// If no school data, add sample
if (!state.school.currentClass.subject && state.school.timetable.length === 0) {
// Create a sample timetable
const now = new Date();
const tomorrow = new Date(now);
tomorrow.setDate(tomorrow.getDate() + 1);
state.school = {
currentClass: {
subject: 'Science',
time: '10:45 AM',
room: 'Room 23',
notes: ''
},
upcoming: [],
timetable: [
{
id: 1,
subject: 'Mathematics',
startTime: '09:00',
endTime: '10:00',
room: 'Room 101',
notes: 'Chapter 5: Algebra'
},
{
id: 2,
subject: 'Science',
startTime: '10:45',
endTime: '11:45',
room: 'Room 23',
notes: 'Experiment day'
},
{
id: 3,
subject: 'English Literature',
startTime: '13:00',
endTime: '14:00',
room: 'Room 15',
notes: 'Read Shakespeare'
}
]
};
Storage.saveSchool(state.school);
}
// If no movie data, add sample
if (!state.movie.title) {
state.movie = {
title: 'Dune',
rating: 8.7,
poster: '',
runtime: '155 min',
notes: 'Epic sci-fi masterpiece'
};
Storage.saveMovie(state.movie);
}
// If no gaming data, add sample
if (!state.gaming.game) {
state.gaming = {
game: 'Stardew Valley',
goal: 'Make 170 Starfruit Wine',
progress: 45
};
Storage.saveGaming(state.gaming);
}
// If no weather data, we'll leave it as default (--). In a real app, we might fetch or set a demo.
// For now, we'll set a demo weather if empty
const weather = Storage.getWeather();
if (weather.temperature === '--' && weather.condition === '--') {
state.weather = {
temperature: '72°F',
condition: 'Sunny',
icon: '☀️',
timestamp: Date.now()
};
Storage.saveWeather(state.weather);
}
// Reload state from storage (in case we updated it)
state = {
settings: Storage.getSettings(),
tasks: Storage.getTasks(),
school: Storage.getSchool(),
movie: Storage.getMovie(),
gaming: Storage.getGaming(),
weather: Storage.getWeather(),
currentSection: state.currentSection || 'home'
};
}
// We'll add event listeners after rendering
function attachEventListeners() {
// Add task button
const addTaskBtn = document.getElementById('add-task-btn');
if (addTaskBtn) {
addTaskBtn.addEventListener('click', showAddTaskForm);
}
// Todo item clicks (for toggling completion)
const todoItems = document.querySelectorAll('.todo-item');
todoItems.forEach(item => {
item.addEventListener('click', function(e) {
// Prevent toggling if clicking on the priority or due date? We'll handle checkbox separately
const checkbox = this.querySelector('input[type="checkbox"]');
if (e.target !== checkbox) {
checkbox.checked = !checkbox.checked;
toggleTaskCompletion(this.dataset.id);
}
});
});
// Todo edit buttons
const editBtns = document.querySelectorAll('.todo-edit-btn');
editBtns.forEach(btn => {
btn.addEventListener('click', function(e) {
e.stopPropagation(); // Prevent toggling completion
editTask(this.dataset.id);
});
});
// Todo delete buttons
const deleteBtns = document.querySelectorAll('.todo-delete-btn');
deleteBtns.forEach(btn => {
btn.addEventListener('click', function(e) {
e.stopPropagation(); // Prevent toggling completion
deleteTask(this.dataset.id);
});
});
// Movie card edit
const movieCard = document.querySelector('.card-header h2');
if (movieCard && movieCard.textContent === 'Currently Watching') {
const movieCardElement = movieCard.closest('.card');
if (movieCardElement) {
movieCardElement.addEventListener('click', showMovieEditForm);
}
}
// Gaming card edit
const gamingCard = document.querySelector('.card-header h2');
if (gamingCard && gamingCard.textContent === 'Gaming') {
const gamingCardElement = gamingCard.closest('.card');
if (gamingCardElement) {
gamingCardElement.addEventListener('click', showGamingEditForm);
}
}
// We'll add more listeners as we build
}
// Show form to add a new task
function showAddTaskForm() {
// We'll create a simple form overlay
const overlay = document.createElement('div');
overlay.className = 'overlay';
overlay.innerHTML = `
<div class="form-container">
<h3>Add New Task</h3>
<form id="add-task-form">
<div class="form-group">
<label for="task-text">Task*</label>
<input type="text" id="task-text" required>
</div>
<div class="form-group">
<label for="task-priority">Priority</label>
<select id="task-priority">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>
</div>
<div class="form-group">
<label for="task-due">Due Date (optional)</label>
<input type="date" id="task-due">
</div>
<div class="form-actions">
<button type="button" id="cancel-task-btn">Cancel</button>
<button type="submit">Add Task</button>
</div>
</form>
</div>
`;
document.body.appendChild(overlay);
// Form submit
const form = overlay.querySelector('#add-task-form');
form.addEventListener('submit', function(e) {
e.preventDefault();
const text = this.querySelector('#task-text').value;
const priority = this.querySelector('#task-priority').value;
const dueDate = this.querySelector('#task-due').value;
addTask(text, priority, dueDate);
overlay.remove();
});
// Cancel button
const cancelBtn = overlay.querySelector('#cancel-task-btn');
cancelBtn.addEventListener('click', () => {
overlay.remove();
});
}
// Add a new task
function addTask(text, priority, dueDate) {
const newTask = {
id: Date.now(), // Simple ID generation
text: text,
completed: false,
priority: priority,
dueDate: dueDate
};
state.tasks.push(newTask);
Storage.saveTasks(state.tasks);
// Re-render the todo card
renderCards(); // This will re-render all cards, but we can optimize later
// Re-attach event listeners for the new todo items
attachEventListeners();
}
// Toggle task completion
function toggleTaskCompletion(id) {
const task = state.tasks.find(t => t.id == id);
if (task) {
task.completed = !task.completed;
Storage.saveTasks(state.tasks);
// Re-render the todo card
renderCards();
attachEventListeners();
}
}
// Edit a task
function editTask(id) {
const task = state.tasks.find(t => t.id == id);
if (!task) return;
// We'll create a simple form overlay
const overlay = document.createElement('div');
overlay.className = 'overlay';
overlay.innerHTML = `
<div class="form-container">
<h3>Edit Task</h3>
<form id="edit-task-form">
<div class="form-group">
<label for="edit-task-text">Task*</label>
<input type="text" id="edit-task-text" value="${task.text}" required>
</div>
<div class="form-group">
<label for="edit-task-priority">Priority</label>
<select id="edit-task-priority">
<option value="low" ${task.priority === 'low' ? 'selected' : ''}>Low</option>
<option value="medium" ${task.priority === 'medium' ? 'selected' : ''}>Medium</option>
<option value="high" ${task.priority === 'high' ? 'selected' : ''}>High</option>
</select>
</div>
<div class="form-group">
<label for="edit-task-due">Due Date (optional)</label>
<input type="date" id="edit-task-due" value="${task.dueDate || ''}">
</div>
<div class="form-actions">
<button type="button" id="cancel-edit-task-btn">Cancel</button>
<button type="submit">Save Changes</button>
</div>
</form>
</div>
`;
document.body.appendChild(overlay);
// Form submit
const form = overlay.querySelector('#edit-task-form');
form.addEventListener('submit', function(e) {
e.preventDefault();
const text = this.querySelector('#edit-task-text').value;
const priority = this.querySelector('#edit-task-priority').value;
const dueDate = this.querySelector('#edit-task-due').value;
// Update task
task.text = text;
task.priority = priority;
task.dueDate = dueDate;
Storage.saveTasks(state.tasks);
// Re-render the todo card
renderCards();
attachEventListeners();
overlay.remove();
});
// Cancel button
const cancelBtn = overlay.querySelector('#cancel-edit-task-btn');
cancelBtn.addEventListener('click', () => {
overlay.remove();
});
}
// Delete a task
function deleteTask(id) {
if (!confirm('Are you sure you want to delete this task?')) return;
state.tasks = state.tasks.filter(t => t.id != id);
Storage.saveTasks(state.tasks);
// Re-render the todo card
renderCards();
attachEventListeners();
}
// Show form to edit movie
function showMovieEditForm() {
// We'll create a simple form overlay
const overlay = document.createElement('div');
overlay.className = 'overlay';
overlay.innerHTML = `
<div class="form-container">
<h3>Edit Currently Watching</h3>
<form id="edit-movie-form">
<div class="form-group">
<label for="edit-movie-title">Title*</label>
<input type="text" id="edit-movie-title" value="${state.movie.title}" required>
</div>
<div class="form-group">
<label for="edit-movie-rating">Rating (0-10)</label>
<input type="number" id="edit-movie-rating" value="${state.movie.rating}" min="0" max="10" step="0.1">
</div>
<div class="form-group">
<label for="edit-movie-runtime">Runtime (e.g., "155 min")</label>
<input type="text" id="edit-movie-runtime" value="${state.movie.runtime}">
</div>
<div class="form-group">
<label for="edit-movie-poster">Poster URL (optional)</label>
<input type="text" id="edit-movie-poster" value="${state.movie.poster}">
</div>
<div class="form-group">
<label for="edit-movie-notes">Notes</label>
<textarea id="edit-movie-notes">${state.movie.notes}</textarea>
</div>
<div class="form-actions">
<button type="button" id="cancel-edit-movie-btn">Cancel</button>
<button type="submit">Save Changes</button>
</div>
</form>
</div>
`;
document.body.appendChild(overlay);
// Form submit
const form = overlay.querySelector('#edit-movie-form');
form.addEventListener('submit', function(e) {
e.preventDefault();
const title = this.querySelector('#edit-movie-title').value;
const rating = parseFloat(this.querySelector('#edit-movie-rating').value) || 0;
const runtime = this.querySelector('#edit-movie-runtime').value;
const poster = this.querySelector('#edit-movie-poster').value;
const notes = this.querySelector('#edit-movie-notes').value;
// Update movie
state.movie.title = title;
state.movie.rating = rating;
state.movie.runtime = runtime;
state.movie.poster = poster;
state.movie.notes = notes;
Storage.saveMovie(state.movie);
// Re-render the movie card
renderSection();
overlay.remove();
});
// Cancel button
const cancelBtn = overlay.querySelector('#cancel-edit-movie-btn');
cancelBtn.addEventListener('click', () => {
overlay.remove();
});
}
// Show form to edit gaming