-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1133 lines (1022 loc) · 46.8 KB
/
index.html
File metadata and controls
1133 lines (1022 loc) · 46.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timer App</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Fonts - Manrope -->
<link href="https://fonts.googleapis.com/css2?family=Manrope:wght@400;700;800&display=swap" rel="stylesheet">
<style>
/* Custom styles for Manrope font and general body styling */
body {
font-family: 'Manrope', sans-serif;
background-color: #ffffff; /* White background */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh; /* Full viewport height */
margin: 0;
padding: 20px; /* Add some padding around the content */
box-sizing: border-box; /* Include padding in element's total width and height */
}
/* Responsive adjustments for smaller screens */
@media (max-width: 640px) {
.container {
width: 100%; /* Full width on small screens */
padding: 15px; /* Reduce padding */
}
.timer-display {
font-size: 4rem; /* Smaller font for timer on small screens */
}
.control-buttons button,
.timer-adjust-button {
width: 60px;
height: 60px;
}
.control-buttons button svg,
.timer-adjust-button svg {
width: 28px;
height: 28px;
}
.add-task-button {
padding: 0.75rem 1.5rem;
font-size: 1rem;
}
.tab-button {
font-size: 0.9rem;
padding: 0.75rem 1.25rem;
}
.control-circle-button-small {
width: 56px; /* 30% smaller */
height: 56px; /* 30% smaller */
}
.control-circle-button-small svg {
width: 25px; /* Adjusted icon size */
height: 25px; /* Adjusted icon size */
}
}
/* Modal styles */
.modal {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
.modal-content {
background-color: #fff;
padding: 32px;
border-radius: 0; /* No rounded corners */
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
width: 90%;
max-width: 500px;
position: relative;
animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
/* Close button container outside modal content */
.close-button-container {
position: absolute;
top: 20px; /* Position outside the modal content */
right: 20px; /* Position outside the modal content */
width: 40px; /* Circular area size */
height: 40px;
border-radius: 50%;
background-color: white; /* Background for the circular area */
border: 1px solid black; /* Border for the circular area */
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
z-index: 1001; /* Ensure it's above modal content */
transition: all 0.2s ease;
}
.close-button-container:hover {
transform: scale(1.1);
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.close-button {
/* Reset original close button styles */
position: static; /* No absolute positioning within its container */
font-size: 1.5rem; /* Adjust icon size */
color: black; /* Icon color */
background: none;
border: none;
padding: 0;
margin: 0;
line-height: 1; /* Ensure proper vertical alignment */
}
/* Circular control buttons (Play, Pause, Reset) */
.control-circle-button {
width: 80px; /* Large size */
height: 80px; /* Large size */
border-radius: 50%; /* Circular shape */
border: 1px solid #000; /* Black border */
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
background-color: white; /* Fill white */
}
.control-circle-button:hover {
transform: scale(1.08);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}
.control-circle-button svg {
width: 36px; /* Icon size */
height: 36px; /* Icon size */
fill: black; /* Black icon color */
}
.control-circle-button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
/* Smaller control buttons for Pause and Reset */
.control-circle-button-small {
width: 56px; /* 30% smaller than 80px */
height: 56px; /* 30% smaller than 80px */
border-radius: 50%;
border: 1px solid #000;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
background-color: white;
}
.control-circle-button-small:hover {
transform: scale(1.08);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}
.control-circle-button-small svg {
width: 25px; /* Adjusted icon size for smaller buttons */
height: 25px; /* Adjusted icon size for smaller buttons */
fill: black;
}
.control-circle-button-small:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
/* Timer adjustment buttons (+/-) */
.timer-adjust-button {
width: 40px; /* Smaller size */
height: 40px; /* Smaller size */
border-radius: 50%;
border: 1px solid #000;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
background-color: white;
transition: all 0.3s ease;
}
.timer-adjust-button:hover {
transform: scale(1.1);
}
.timer-adjust-button svg {
width: 20px;
height: 20px;
fill: black;
}
.timer-adjust-button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
/* Tab styles */
.tab-button {
padding: 0.75rem 1.5rem;
font-weight: normal; /* Default to normal */
border-bottom: 2px solid transparent;
cursor: pointer;
transition: border-color 0.3s, color 0.3s, font-weight 0.3s; /* Add font-weight transition */
}
.tab-button.active {
border-color: #000; /* Black border for active tab */
color: #000;
font-weight: bold; /* Bold for active tab */
}
.tab-button:not(.active):hover {
color: #666;
}
/* Task list item styles */
.task-list-item {
background-color: #fff;
padding: 0.75rem 1.5rem; /* Adjusted padding to match Add Task button */
margin-bottom: 0px; /* Closer spacing */
border: none; /* No border for list items */
border-radius: 0; /* No rounded corners */
box-shadow: none; /* No shadow */
display: flex;
align-items: center; /* Align items vertically in the center */
cursor: pointer;
transition: background-color 0.2s;
width: 100%; /* Ensure full width */
box-sizing: border-box; /* Include padding and border in width */
position: relative; /* For divider */
}
.task-list-item:hover {
background-color: #f5f5f5;
}
/* Divider style */
.task-list-item:not(:last-child)::after {
content: '';
position: absolute;
bottom: 0;
left: 0; /* Match left edge of the list item */
right: 0; /* Match right edge of the list item */
height: 1px;
background-color: #e5e7eb; /* Light gray divider */
}
/* Add Task Button specific styles */
.add-task-button-bottom {
width: 100%; /* Full width */
border-radius: 0; /* No rounded corners */
background-color: white; /* White fill */
color: black; /* Black text */
border: 1px solid #000; /* Black border */
box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05); /* Subtle shadow for hanging effect */
position: sticky; /* Make it stick to the bottom */
bottom: 0; /* Position at the bottom */
z-index: 999; /* Ensure it's above other content */
margin-top: auto; /* Push to bottom in flex container */
}
/* General input field style */
.input-field-style {
border: 1px solid black;
padding: 0.75rem;
border-radius: 0; /* No rounded corners */
box-shadow: none; /* No shadow */
outline: none; /* Remove default outline on focus */
width: 100%; /* Ensure it takes full width */
}
.input-field-style:focus {
border-color: #333; /* Slightly darker border on focus */
}
/* Modal Timer Adjust Buttons */
.modal-timer-adjust-button {
width: 30px; /* Smaller icon size */
height: 30px; /* Smaller icon size */
border-radius: 50%;
border: 1px solid #000;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
background-color: white;
transition: all 0.2s ease;
}
.modal-timer-adjust-button:hover {
transform: scale(1.1);
}
.modal-timer-adjust-button svg {
width: 12px; /* Smaller icon size */
height: 12px; /* Smaller icon size */
fill: black;
}
/* Breakdown Task as icon and text */
.breakdown-task-area {
display: flex;
align-items: center;
gap: 0.5rem; /* Use gap for spacing instead of space-x */
cursor: pointer;
transition: opacity 0.2s;
}
.breakdown-task-area:hover {
opacity: 0.8;
}
.breakdown-task-area .icon {
color: #8B5CF6; /* Purple color for the sparkle icon */
}
.breakdown-task-area .text {
color: black;
font-weight: bold;
font-size: 0.875rem; /* text-sm */
}
/* Container for tabs and lists to fill remaining space */
.main-content-area {
flex-grow: 1; /* Allows this div to take up available vertical space */
display: flex; /* Make it a flex container */
flex-direction: column; /* Stack children vertically */
margin-bottom: 20px; /* Add 20px gap before the Add Task button */
}
/* Tab content containers to fill vertical space and be scrollable */
#taskTabContent, #completedTabContent {
padding: 0; /* Remove padding from these containers */
flex-grow: 1; /* Make them grow to fill space within main-content-area */
overflow-y: auto; /* Add scroll if content overflows */
display: flex; /* Make them flex containers for their ul children */
flex-direction: column; /* Stack ul vertically */
}
/* Ensure ul takes full width and has no default list padding */
#pendingTasksList, #completedTasksList {
list-style: none; /* Remove bullet points */
padding: 0; /* Remove padding from UL */
margin: 0; /* Remove default margin */
flex-grow: 1; /* Allow UL to grow within its parent tab content */
}
/* Style for the "no tasks" message with icon */
.no-tasks-message-style {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 2rem 0;
color: #6b7280; /* Secondary text color */
font-style: italic;
height: 100%; /* Ensure it fills the available height */
text-align: center; /* Center text */
}
.no-tasks-message-style svg {
width: 40px;
height: 40px;
fill: #6b7280; /* Match text color */
margin-bottom: 0.5rem;
}
/* Modal Save Button Style */
#setTaskButton {
background-color: black;
color: white;
border-radius: 0; /* No rounded corners */
}
#setTaskButton:hover {
background-color: #333; /* Slightly darker on hover */
}
/* Modal Timer Controls Alignment */
.modal .flex.items-center.justify-start {
justify-content: flex-start; /* Align to left */
}
/* Task List Item Hover/Active States */
.task-list-item .task-number {
display: block; /* Number visible by default */
width: 20px; /* Give it a fixed width for alignment */
text-align: right; /* Align number to right within its space */
}
.task-list-item .task-checkbox-container {
display: none; /* Hide checkbox container by default */
width: 20px; /* Fixed width for alignment */
height: 20px;
display: flex; /* Use flex to center the SVG */
justify-content: center;
align-items: center;
cursor: pointer;
}
.task-list-item .task-checkbox-container svg {
width: 18px; /* Size of the checkbox icon */
height: 18px;
fill: none; /* No fill for the square */
stroke: black; /* Black stroke for the square */
stroke-width: 2; /* Thickness of the stroke */
border: none; /* No border on the SVG itself, the stroke acts as border */
}
/* Show checkbox and hide number on hover */
.task-list-item:hover .task-number {
display: none;
}
.task-list-item:hover .task-checkbox-container {
display: flex;
}
/* Active task styling (only visual highlight, no change to number/checkbox visibility) */
.task-list-item.active-task {
background-color: #f5f5f5; /* A light grey to signify active, like hover */
}
/* Ensure active task also shows checkbox on hover */
.task-list-item.active-task .task-number { /* Active task shows number by default */
display: block;
}
.task-list-item.active-task .task-checkbox-container { /* Active task hides checkbox by default */
display: none;
}
.task-list-item.active-task:hover .task-number { /* Active task hides number on hover */
display: none;
}
.task-list-item.active-task:hover .task-checkbox-container { /* Active task shows checkbox on hover */
display: flex;
}
</style>
</head>
<body>
<!-- Main container for the To-Do Timer App -->
<div class="container w-full max-w-md flex flex-col min-h-[calc(100vh-40px)]">
<!-- Timer Display and Adjust Buttons -->
<div class="flex items-center justify-center mb-4">
<button id="minusButton" class="timer-adjust-button mr-4">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M19 13H5v-2h14v2z"/>
</svg>
</button>
<div id="timerDisplay" class="timer-display text-8xl font-bold text-gray-900">
25:00
</div>
<button id="plusButton" class="timer-adjust-button ml-4">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</svg>
</button>
</div>
<p id="currentTaskDisplay" class="text-xl text-gray-600 truncate text-center mb-8">No task set</p>
<!-- Control Buttons (Play, Pause, Reset) -->
<div class="control-buttons flex justify-center items-center space-x-4 mb-8">
<button
id="pauseButton"
class="control-circle-button-small"
>
<!-- Pause Icon SVG -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/>
</svg>
</button>
<button
id="startButton"
class="control-circle-button"
>
<!-- Play Icon SVG -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M8 5v14l11-7z"/>
</svg>
</button>
<button
id="resetButton"
class="control-circle-button-small"
>
<!-- Reset Icon SVG (Reload/Refresh) -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M12 5V2L7 7l5 5V9c3.31 0 6 2.69 6 6s-2.69 6-6 6-6-2.69-6-6H4c0 4.42 3.58 8 8 8s8-3.58 8-8-3.58-8-8-8z"/>
</svg>
</button>
</div>
<!-- Tabbed Interface -->
<div class="main-content-area">
<div class="flex border-b border-gray-200">
<button id="taskTabButton" class="tab-button flex-1 text-center py-3 px-4 active">Tasks</button>
<button id="completedTabButton" class="tab-button flex-1 text-center py-3 px-4">Completed Tasks</button>
</div>
<div id="taskTabContent">
<ul id="pendingTasksList">
<!-- Pending tasks will be added here by JS -->
</ul>
<div id="noPendingTasksMessage" class="no-tasks-message-style"> <!-- Placeholder for no pending tasks -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</svg>
<span>Add your first task first</span>
</div>
</div>
<div id="completedTabContent" class="hidden">
<ul id="completedTasksList">
<!-- Completed tasks will be added here by JS -->
</ul>
<div id="noCompletedTasksMessage" class="no-tasks-message-style"> <!-- Placeholder for no completed tasks -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z"/>
</svg>
<span>No tasks completed yet.</span>
</div>
</div>
</div>
<!-- Add Task Button (Moved to bottom, full width, no rounded, white fill, black text) -->
<button
id="addTaskButton"
class="add-task-button-bottom font-bold py-3 px-6 shadow-md transition duration-300 transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-gray-500"
>
Add Task
</button>
</div>
<!-- Task Management Modal -->
<div id="taskModal" class="modal hidden">
<div class="close-button-container">
<button class="close-button" id="closeTaskModalButton">×</button>
</div>
<div class="modal-content">
<h2 class="text-xl font-bold text-gray-800 mb-6 text-left">Set Your Task</h2>
<!-- Task Input Section inside modal -->
<div class="mb-6">
<label for="modalTaskInput" class="block text-gray-700 text-sm font-semibold mb-2">Task Name:</label>
<input
type="text"
id="modalTaskInput"
placeholder="Enter your task"
class="input-field-style"
/>
<div id="modalBreakdownTaskArea" class="breakdown-task-area mt-4">
<span class="icon">✨</span>
<span class="text">Break Down Task</span>
</div>
<div id="modalBreakdownSuggestions" class="mt-4 p-3 bg-blue-50 text-sm text-gray-700 hidden">
<h3 class="font-semibold mb-2">Suggested Sub-tasks:</h3>
<ul id="modalSubtaskList" class="list-disc list-inside">
<!-- Sub-tasks will be inserted here -->
</ul>
</div>
</div>
<!-- Timer Input Section inside modal (Custom control) -->
<div class="mb-6">
<label for="modalTimerDisplay" class="block text-gray-700 text-sm font-semibold mb-2">Set Timer (minutes):</label>
<div class="flex items-center justify-start"> <!-- Changed to justify-start for left alignment -->
<button id="modalMinusButton" class="modal-timer-adjust-button mr-4">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M19 13H5v-2h14v2z"/>
</svg>
</button>
<div id="modalTimerDisplay" class="text-4xl font-bold text-gray-900">
25
</div>
<button id="modalPlusButton" class="modal-timer-adjust-button ml-4">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</svg>
</button>
</div>
</div>
<button
id="setTaskButton"
class="w-full bg-black text-white font-bold py-3 px-6 shadow-md transition duration-300 transform hover:scale-105 focus:outline-none focus:ring-2 focus:ring-blue-500"
>
Save
</button>
</div>
</div>
<script>
// Get references to main DOM elements
const timerDisplay = document.getElementById('timerDisplay');
const currentTaskDisplay = document.getElementById('currentTaskDisplay');
const startButton = document.getElementById('startButton');
const pauseButton = document.getElementById('pauseButton');
const resetButton = document.getElementById('resetButton');
const minusButton = document.getElementById('minusButton');
const plusButton = document.getElementById('plusButton');
const addTaskButton = document.getElementById('addTaskButton');
// Tab elements
const taskTabButton = document.getElementById('taskTabButton');
const completedTabButton = document.getElementById('completedTabButton');
const taskTabContent = document.getElementById('taskTabContent');
const completedTabContent = document.getElementById('completedTabContent');
// Get references to Task Modal elements
const taskModal = document.getElementById('taskModal');
const closeTaskModalButton = document.getElementById('closeTaskModalButton');
const modalTaskInput = document.getElementById('modalTaskInput');
const modalBreakdownTaskArea = document.getElementById('modalBreakdownTaskArea');
const modalBreakdownSuggestions = document.getElementById('modalBreakdownSuggestions');
const modalSubtaskList = document.getElementById('modalSubtaskList');
const modalTimerDisplay = document.getElementById('modalTimerDisplay');
const modalMinusButton = document.getElementById('modalMinusButton');
const modalPlusButton = document.getElementById('modalPlusButton');
const setTaskButton = document.getElementById('setTaskButton');
// Get references to Completed Tasks List (now in a tab)
const pendingTasksList = document.getElementById('pendingTasksList');
const completedTasksList = document.getElementById('completedTasksList');
// Get references to the new placeholder elements
const noPendingTasksMessage = document.getElementById('noPendingTasksMessage');
const noCompletedTasksMessage = document.getElementById('noCompletedTasksMessage');
let countdown; // Variable to hold the setInterval ID
let timeRemaining; // Time remaining in seconds
let isPaused = false; // Flag to track pause state
let initialTimeInSeconds; // Store the initial time set by the user
let currentActiveTask = null; // Stores the task currently being timed
let pendingTasks = []; // Array to store pending tasks
let completedTasks = []; // Array to store completed tasks
/**
* Formats seconds into a MM:SS string.
* @param {number} seconds - The total number of seconds.
* @returns {string} Formatted time string (MM:SS).
*/
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes < 10 ? '0' : ''}${minutes}:${remainingSeconds < 10 ? '0' : ''}${remainingSeconds}`;
}
/**
* Updates the timer display.
*/
function updateDisplay() {
timerDisplay.textContent = formatTime(timeRemaining);
}
/**
* Adjusts the timer duration.
* @param {number} deltaMinutes - The number of minutes to add or subtract.
*/
function adjustTimer(deltaMinutes) {
const currentMinutes = Math.floor(timeRemaining / 60);
let newMinutes = currentMinutes + deltaMinutes;
if (newMinutes < 1) {
newMinutes = 1; // Minimum 1 minute
}
// Update both the display and the modal input
timeRemaining = newMinutes * 60;
modalTimerDisplay.textContent = newMinutes; // Update modal timer display
updateDisplay();
}
/**
* Starts the timer countdown.
*/
function startTimer() {
// If no task is set, open the task modal
if (!currentActiveTask) {
openTaskModal();
return; // Stop function execution until task is set
}
clearInterval(countdown); // Clear any existing interval
if (!isPaused) {
// If not paused, set initial time based on input from modal or use previous remaining time
const minutes = parseInt(modalTimerDisplay.textContent, 10); // Get from modal display
if (isNaN(minutes) || minutes <= 0) {
showMessageBox('Please enter a valid number of minutes (greater than 0).');
return;
}
initialTimeInSeconds = minutes * 60;
timeRemaining = initialTimeInSeconds;
}
isPaused = false;
updateDisplay();
countdown = setInterval(() => {
timeRemaining--;
updateDisplay();
if (timeRemaining <= 0) {
clearInterval(countdown);
timerDisplay.textContent = "00:00";
showMessageBox('Time is up!');
completeTask(currentActiveTask); // Call completeTask when timer finishes
resetTimer(); // Automatically reset after time is up
}
}, 1000);
// Disable task setting and enable control buttons
addTaskButton.disabled = true;
startButton.disabled = true;
pauseButton.disabled = false;
resetButton.disabled = false;
// Plus/Minus buttons remain enabled as requested
}
/**
* Pauses the timer.
*/
function pauseTimer() {
clearInterval(countdown);
isPaused = true;
startButton.disabled = false;
pauseButton.disabled = true;
}
/**
* Resets the timer to its initial state.
*/
function resetTimer() {
clearInterval(countdown);
isPaused = false;
const minutes = parseInt(modalTimerDisplay.textContent, 10); // Get from modal display
timeRemaining = (isNaN(minutes) || minutes <= 0) ? 25 * 60 : minutes * 60;
updateDisplay();
addTaskButton.disabled = false; // Enable task setting button
startButton.disabled = false;
pauseButton.disabled = true;
resetButton.disabled = true;
// Plus/Minus buttons remain enabled
currentActiveTask = null; // Clear active task
currentTaskDisplay.textContent = 'No task set';
modalTaskInput.value = ''; // Clear task input in modal
modalBreakdownSuggestions.classList.add('hidden'); // Hide breakdown suggestions
modalSubtaskList.innerHTML = ''; // Clear sub-task list
modalTimerDisplay.textContent = '25'; // Reset modal timer display to default
renderPendingTasks(); // Re-render to clear active state
}
/**
* Adds a task to the pending list.
* @param {string} taskName - The name of the task.
*/
function addPendingTask(taskName) {
if (taskName.trim() === '') {
return;
}
// Check if task already exists to prevent duplicates
if (!pendingTasks.includes(taskName) && !completedTasks.some(t => t.name === taskName)) {
pendingTasks.push(taskName);
renderPendingTasks();
}
}
/**
* Completes a task and moves it to the completed list.
* @param {string} taskName - The name of the task to complete.
*/
function completeTask(taskName) {
const index = pendingTasks.indexOf(taskName);
if (index > -1) {
pendingTasks.splice(index, 1); // Remove from pending
}
completedTasks.push({ name: taskName, time: new Date().toLocaleTimeString() }); // Add to completed
// If the completed task was the current active task, reset current active task
if (currentActiveTask === taskName) {
currentActiveTask = null;
currentTaskDisplay.textContent = 'No task set';
}
renderPendingTasks(); // Re-render both lists after modification
renderCompletedTasks();
}
/**
* Renders the list of pending tasks.
*/
function renderPendingTasks() {
pendingTasksList.innerHTML = ''; // Clear existing tasks
if (pendingTasks.length === 0) {
noPendingTasksMessage.classList.remove('hidden'); // Show placeholder
} else {
noPendingTasksMessage.classList.add('hidden'); // Hide placeholder
pendingTasks.forEach((task, index) => {
const listItem = document.createElement('li');
listItem.className = 'task-list-item'; // Use new class for styling
listItem.setAttribute('data-task-name', task); // Add data attribute for selection
const taskNumberSpan = document.createElement('span');
taskNumberSpan.className = 'task-number font-semibold mr-2';
taskNumberSpan.textContent = `${index + 1}.`;
const taskCheckboxContainer = document.createElement('div');
taskCheckboxContainer.className = 'task-checkbox-container mr-2';
// Simple square SVG for the checkbox
taskCheckboxContainer.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<rect x="3" y="3" width="18" height="18" fill="none" stroke="black" stroke-width="2"/>
</svg>
`;
const taskTextSpan = document.createElement('span');
taskTextSpan.className = 'task-text text-gray-600';
taskTextSpan.textContent = task;
listItem.appendChild(taskNumberSpan);
listItem.appendChild(taskCheckboxContainer);
listItem.appendChild(taskTextSpan);
// Event listener for completing the task when checkbox area is clicked
taskCheckboxContainer.addEventListener('click', (event) => {
event.stopPropagation(); // Prevent the listItem click from also firing
completeTask(task);
});
// Event listener for selecting the task (clicking anywhere else on the list item)
listItem.addEventListener('click', () => {
selectTask(task);
});
// Apply active state if it's the current active task
if (currentActiveTask === task) {
listItem.classList.add('active-task');
}
pendingTasksList.appendChild(listItem);
});
}
}
/**
* Renders the list of completed tasks.
*/
function renderCompletedTasks() {
completedTasksList.innerHTML = ''; // Clear existing tasks
if (completedTasks.length === 0) {
noCompletedTasksMessage.classList.remove('hidden'); // Show placeholder
} else {
noCompletedTasksMessage.classList.add('hidden'); // Hide placeholder
completedTasks.forEach((task, index) => {
const listItem = document.createElement('li');
listItem.className = 'task-list-item'; // Use new class for styling
listItem.innerHTML = `
<span class="font-semibold mr-2">${index + 1}.</span>
<span class="text-gray-600">${task.name}</span>
<span class="text-gray-500 text-sm ml-auto">${task.time}</span>
`; // Add numbering and secondary color
completedTasksList.appendChild(listItem);
});
}
}
/**
* Selects a task from the pending list to be the current active task.
* @param {string} taskName - The name of the task to select.
*/
function selectTask(taskName) {
// Remove active class from previously active task
if (currentActiveTask) {
const prevActiveItem = document.querySelector(`.task-list-item[data-task-name="${currentActiveTask}"]`);
if (prevActiveItem) {
prevActiveItem.classList.remove('active-task');
}
}
currentActiveTask = taskName;
currentTaskDisplay.textContent = taskName;
// Add active class to newly selected task
const newActiveItem = document.querySelector(`.task-list-item[data-task-name="${currentActiveTask}"]`);
if (newActiveItem) {
newActiveItem.classList.add('active-task');
}
showMessageBox(`Task "${taskName}" is set as current task.`);
}
/**
* Displays a custom message box.
* @param {string} message - The message to display.
*/
function showMessageBox(message) {
const modalBackground = document.createElement('div');
modalBackground.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50';
const modalContent = document.createElement('div');
modalContent.className = 'bg-white p-6 rounded-lg shadow-xl max-w-sm w-full text-center';
const messageText = document.createElement('p');
messageText.className = 'text-lg font-semibold text-gray-800 mb-4';
messageText.textContent = message;
const closeButton = document.createElement('button');
closeButton.className = 'bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded-lg transition duration-300';
closeButton.textContent = 'OK';
closeButton.onclick = () => {
document.body.removeChild(modalBackground);
};
modalContent.appendChild(messageText);
modalContent.appendChild(closeButton);
modalBackground.appendChild(modalContent);
document.body.appendChild(modalBackground);
}
/**
* Opens the task management modal.
*/
function openTaskModal() {
taskModal.classList.remove('hidden');
// Clear inputs when opening for a new task
modalTaskInput.value = '';
modalTimerDisplay.textContent = Math.floor(timeRemaining / 60); // Set modal timer display to current timer value
modalBreakdownSuggestions.classList.add('hidden');
modalSubtaskList.innerHTML = '';
}
/**
* Closes the task management modal.
*/
function closeTaskModal() {
taskModal.classList.add('hidden');
modalBreakdownSuggestions.classList.add('hidden'); // Hide breakdown suggestions when closing
modalSubtaskList.innerHTML = ''; // Clear sub-task list
}
/**
* Sets the task and timer from the modal and closes it.
*/
function setTaskAndCloseModal() {
const taskName = modalTaskInput.value.trim();
const minutes = parseInt(modalTimerDisplay.textContent, 10); // Get from modal display
if (!taskName) {
closeTaskModal(); // Close modal if no task name and Enter is pressed
return;
}
if (isNaN(minutes) || minutes <= 0) {
showMessageBox('Please enter a valid number of minutes (greater than 0).');
return;
}
addPendingTask(taskName); // Add to pending tasks list
selectTask(taskName); // Set this task as the current active task
timeRemaining = minutes * 60;
updateDisplay();
closeTaskModal();
}
/**
* Adjusts the timer duration in the modal.
* @param {number} deltaMinutes - The number of minutes to add or subtract.
*/
function adjustModalTimer(deltaMinutes) {
let currentMinutes = parseInt(modalTimerDisplay.textContent, 10);
let newMinutes = currentMinutes + deltaMinutes;
if (newMinutes < 1) {
newMinutes = 1; // Minimum 1 minute
}
modalTimerDisplay.textContent = newMinutes; // Update modal timer display
}
/**
* Calls the Gemini API to break down a task into sub-tasks.
*/
async function breakDownTask() {
const task = modalTaskInput.value.trim();
if (!task) {
showMessageBox('Please enter a task to break down.');
return;
}
// Disable interaction during API call
modalBreakdownTaskArea.style.pointerEvents = 'none';
modalBreakdownTaskArea.style.opacity = '0.6';
modalBreakdownTaskArea.querySelector('.text').textContent = 'Breaking Down...';
modalSubtaskList.innerHTML = ''; // Clear previous suggestions
modalBreakdownSuggestions.classList.add('hidden'); // Hide the suggestions container initially