forked from dat-lequoc/focus-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1638 lines (1550 loc) · 77 KB
/
index.html
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" class="dark">
<head>
<meta charset="UTF-8">
<title>Focus Flow</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<script>
tailwind.config = {
darkMode: 'class',
}
</script>
</head>
<body class="bg-gray-100 text-black dark:bg-gray-900 dark:text-white">
<div id="app" class="flex h-screen">
<div id="sidebar" class="w-64 border-r p-4 bg-white shadow-lg dark:bg-gray-800 dark:border-gray-700">
<div class="flex flex-col space-y-4">
<h2 id="projects-heading" class="text-xl font-bold text-gray-800 cursor-pointer dark:text-gray-200"
onclick="showDashboard()">
Projects</h2>
</div>
<div id="project-list" class="mt-4 h-[calc(100vh-10rem)] overflow-y-auto">
</div>
<div class="mt-4">
<input id="new-project-name" type="text" placeholder="New project name"
class="mb-2 p-2 border rounded-lg w-full focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all dark:bg-gray-700 dark:border-gray-600 dark:text-gray-200 dark:placeholder-gray-400">
<button id="add-project-btn"
class="w-full bg-blue-500 hover:bg-blue-600 text-white p-2 rounded-lg shadow-sm transition-all duration-200">Add
Project</button>
</div>
</div>
<div id="main-panel" class="flex-1 p-6 bg-gray-50 dark:bg-gray-900 overflow-y-auto">
<div class="flex justify-between items-center mb-6">
<h1 id="project-title" class="text-2xl font-bold"></h1>
<div class="flex items-center space-x-4">
<button id="home-btn" class="p-2 border rounded dark:border-gray-700" title="Home"
onclick="showDashboard()">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
</svg>
</button>
<div class="flex items-center gap-2">
<div class="relative">
<input id="search-input" type="text" placeholder="Search tasks"
class="pl-8 p-2 border rounded dark:bg-gray-700 dark:border-gray-600 dark:text-gray-200 dark:placeholder-gray-400">
<svg class="absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 transform text-gray-500 dark:text-gray-400"
fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M21 21l-4.35-4.35M17 10a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</div>
<button id="export-btn" class="p-2 border rounded dark:border-gray-700" title="Export Data">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
</svg>
</button>
<button id="import-btn" class="p-2 border rounded dark:border-gray-700" title="Import Data">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L7 8m4-4v12" />
</svg>
</button>
<input type="file" id="import-file" accept=".json" class="hidden">
<button id="hide-completed-btn" class="p-2 border rounded dark:border-gray-700"
title="Toggle completed tasks">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
</svg>
</button>
</div>
<div class="flex gap-2">
<button id="dark-mode-toggle" class="p-2 border rounded dark:border-gray-700"
title="Toggle Dark Mode">
<i id="dark-mode-icon" class="fas fa-moon text-gray-700 dark:text-gray-200"></i>
</button>
<button id="report-btn" class="p-2 border rounded dark:border-gray-700" title="Project Report">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 17v-6a1 1 0 112 0v6a1 1 0 11-2 0zM13 13v4a1 1 0 102 0v-4a1 1 0 10-2 0zM17 9v8a1 1 0 102 0V9a1 1 0 10-2 0z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M5 21h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2z" />
</svg>
</button>
<button id="settings-btn" class="p-2 border rounded dark:border-gray-700" title="Settings">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor"
viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
</button>
</div>
</div>
</div>
<div id="dashboard-view">
</div>
<div id="project-view" class="hidden">
<div id="task-input" class="mb-4">
<input id="new-task-title" type="text" placeholder="+ task "
class="mb-4 p-3 border rounded-lg w-full shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-all dark:bg-gray-700 dark:border-gray-600 dark:text-gray-200 dark:placeholder-gray-400">
</div>
<div id="task-list" class="h-[calc(100vh-20rem)] overflow-y-auto">
</div>
</div>
<div id="pomodoro-display"
class="fixed bottom-0 left-0 right-0 bg-white border-t p-4 hidden dark:bg-gray-800 dark:border-gray-700">
<div class="container mx-auto flex justify-between items-center">
<div class="flex items-center">
<span class="font-bold mr-2">Current Task:</span>
<span id="current-task-title">None</span>
</div>
<div class="flex items-center">
<span id="pomodoro-timer" class="text-2xl font-mono">25:00</span>
<button id="stop-pomodoro" class="ml-4 bg-red-500 text-white px-4 py-2 rounded">Stop</button>
</div>
</div>
</div>
</div>
</div>
<div id="time-entry-modal"
class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 hidden z-40">
<div id="time-entry-modal-content"
class="bg-white p-6 rounded-lg shadow-lg dark:bg-gray-800 dark:text-gray-200 z-50">
<h2 class="text-xl font-bold mb-4">Add Time Entry</h2>
<div class="space-y-4">
<div>
<label class="block mb-1">Duration (minutes)</label>
<input type="number" id="manual-time-minutes" min="1"
class="w-full p-2 border rounded dark:bg-gray-700 dark:border-gray-600">
</div>
<div>
<label class="block mb-1">Date</label>
<input type="date" id="manual-time-date"
class="w-full p-2 border rounded dark:bg-gray-700 dark:border-gray-600">
</div>
</div>
<div class="mt-6 flex justify-end space-x-3">
<button id="cancel-time-entry"
class="px-4 py-2 border rounded hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-700">
Cancel
</button>
<button id="save-time-entry" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Save
</button>
</div>
</div>
</div>
<audio id="timer-sound" src="https://www.soundjay.com/buttons/sounds/beep-07a.mp3" preload="auto" loop></audio>
<div id="report-modal" class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 hidden">
<div class="bg-white p-6 rounded dark:bg-gray-800 dark:text-gray-200">
<h2 class="text-xl font-bold mb-4">Project Report</h2>
<div id="report-content">
</div>
<button id="close-report-btn" class="mt-4 bg-blue-500 text-white p-2 rounded">Close</button>
</div>
</div>
<div id="settings-modal" class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 hidden">
<div class="bg-white p-6 rounded-lg shadow-lg dark:bg-gray-800 dark:text-gray-200">
<h2 class="text-xl font-bold mb-4">Settings</h2>
<div class="space-y-4">
<div>
<label class="block mb-2">Pomodoro Duration (minutes)</label>
<input type="number" id="pomodoro-duration" min="1" max="60" value="25"
class="w-full p-2 border rounded dark:bg-gray-700 dark:border-gray-600 dark:text-gray-200">
</div>
<div class="mt-4">
<label class="block mb-2">Timer Sound</label>
<select id="sound-select" class="w-full p-2 border rounded dark:bg-gray-700 dark:border-gray-600">
<option value="default">Default Beep</option>
<option value="custom">Custom Sound</option>
</select>
</div>
<div id="custom-sound-input" class="hidden">
<input type="file" accept="audio/*" id="custom-sound-file"
class="w-full p-2 border rounded dark:bg-gray-700 dark:border-gray-600">
</div>
<div class="mt-4">
<button id="test-sound-btn" class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Test Sound
</button>
</div>
</div>
<div class="mt-6 flex justify-end space-x-3">
<button id="close-settings"
class="px-4 py-2 border rounded hover:bg-gray-100 dark:border-gray-600 dark:hover:bg-gray-700">
Close
</button>
</div>
</div>
</div>
<div id="timer-complete-modal" class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 hidden">
<div class="bg-white p-6 rounded-lg shadow-lg dark:bg-gray-800 dark:text-gray-200">
<h2 class="text-xl font-bold mb-4">Time's Up!</h2>
<p class="mb-4">Your pomodoro session is complete.</p>
<button id="close-timer-complete" class="w-full px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
Close
</button>
</div>
</div>
<script>
let projects = [];
let selectedProject = null;
let isDarkMode = true;
let searchTerm = '';
let hideCompleted = false;
let currentPomodoroTask = null;
let pomodoroTimer = null;
let pomodoroDuration = 25;
let pomodoroTimeLeft = pomodoroDuration * 60;
let pomodoroStartTime = null;
let timerSound = document.getElementById('timer-sound');
let projectDropdowns = [];
function createElement(tag, options = {}) {
const element = document.createElement(tag);
for (let [key, value] of Object.entries(options)) {
if (key === 'className') {
element.className = value;
} else if (key === 'innerHTML') {
element.innerHTML = value;
} else if (key.startsWith('on')) {
element.addEventListener(key.substring(2).toLowerCase(), value);
} else {
element.setAttribute(key, value);
}
}
return element;
}
function createButton(options = {}) {
return createElement('button', options);
}
function createSVGIcon(pathData, className = '') {
const svg = createElement('svg', {
className: `h-5 w-5 ${className}`,
fill: 'none',
stroke: 'currentColor',
viewBox: '0 0 24 24'
});
const path = createElement('path', {
d: pathData,
'stroke-linecap': 'round',
'stroke-linejoin': 'round',
'stroke-width': '2'
});
svg.appendChild(path);
return svg;
}
function loadInitialData() {
const savedData = localStorage.getItem('taskManagerData');
if (savedData) {
projects = JSON.parse(savedData);
} else {
projects = [
{
id: generateId(),
name: "Learning AI",
tasks: [
{
id: generateId(),
title: "Hugging Face Course",
timeSpent: 0,
isTimerRunning: false,
isExpanded: true,
isCompleted: false,
inToday: true,
dailyGoal: 2,
subtasks: [
{
id: generateId(),
title: "NLP with Transformers",
timeSpent: 2300,
isTimerRunning: false,
isExpanded: false,
isCompleted: true,
subtasks: []
},
{
id: generateId(),
title: "Audio Processing Course https://huggingface.co/learn/audio-course",
timeSpent: 1500,
isTimerRunning: false,
isExpanded: false,
isCompleted: false,
inToday: true,
dailyGoal: 3,
subtasks: []
}
]
},
{
id: generateId(),
title: "Practice Projects",
timeSpent: 0,
isTimerRunning: false,
isExpanded: true,
isCompleted: false,
subtasks: [
{
id: generateId(),
title: "Build a Chatbot using Transformers",
timeSpent: 0,
isTimerRunning: false,
isExpanded: false,
isCompleted: false,
subtasks: []
},
{
id: generateId(),
title: "Image Generation with Stable Diffusion",
timeSpent: 0,
isTimerRunning: false,
isExpanded: false,
isCompleted: true,
subtasks: []
}
]
}
]
},
{
id: generateId(),
name: "Reading Book",
tasks: [
{
id: generateId(),
title: "Read Chapter 1",
timeSpent: 0,
isTimerRunning: false,
isExpanded: false,
isCompleted: false,
inToday: false,
dailyGoal: 0,
subtasks: []
},
{
id: generateId(),
title: "Take Notes",
timeSpent: 0,
isTimerRunning: false,
isExpanded: false,
isCompleted: false,
inToday: false,
dailyGoal: 0,
subtasks: []
}
]
}
];
}
projects.forEach(project => {
project.tasks.forEach(task => {
initializeTaskProperties(task);
});
});
// Add single global event listener for dropdowns
if (!window.dropdownClickListenerAdded) {
document.addEventListener('click', () => {
// Always use global projectDropdowns array
projectDropdowns.forEach(dropdown => {
dropdown.classList.add('hidden');
});
});
window.dropdownClickListenerAdded = true;
}
}
function initializeTaskProperties(task) {
if (task.inToday === undefined) task.inToday = false;
if (task.dailyGoal === undefined) task.dailyGoal = 0;
if (task.dailyProgress === undefined) task.dailyProgress = 0;
if (task.isExpanded === undefined) task.isExpanded = false;
if (task.isTimerRunning === undefined) task.isTimerRunning = false;
if (task.isCompleted === undefined) task.isCompleted = false;
if (task.timeSpent === undefined) task.timeSpent = 0;
if (task.subtasks === undefined) task.subtasks = [];
task.subtasks.forEach(subtask => initializeTaskProperties(subtask));
}
function saveData() {
localStorage.setItem('taskManagerData', JSON.stringify(projects));
}
function generateId() {
return Math.random().toString(36).substr(2, 9);
}
function getWeeklyTimeData() {
const today = new Date();
today.setHours(0, 0, 0, 0);
const days = [];
for (let i = 6; i >= 0; i--) {
const date = new Date(today);
date.setDate(date.getDate() - i);
days.push({
date: date,
timeSpent: 0
});
}
projects.forEach(project => {
const processTask = (task) => {
if (task.timeEntries) {
task.timeEntries.forEach(entry => {
const entryDate = new Date(entry.start);
entryDate.setHours(0, 0, 0, 0);
const dayData = days.find(d =>
d.date.getTime() === entryDate.getTime()
);
if (dayData) {
dayData.timeSpent += entry.duration;
}
});
}
task.subtasks.forEach(processTask);
};
project.tasks.forEach(processTask);
});
return days;
}
function renderWeeklyChart() {
const ctx = document.getElementById('weeklyChart');
if (!ctx) return;
const weekData = getWeeklyTimeData();
const labels = weekData.map(d => d.date.toLocaleDateString('en-US', { weekday: 'short' }));
const data = weekData.map(d => (d.timeSpent / 3600).toFixed(2));
if (window.weeklyChart instanceof Chart) {
window.weeklyChart.destroy();
}
window.weeklyChart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Time Spent (hours)',
data: data,
backgroundColor: isDarkMode ? 'rgba(59, 130, 246, 0.5)' : 'rgba(59, 130, 246, 0.8)',
borderColor: isDarkMode ? 'rgba(59, 130, 246, 0.8)' : 'rgba(59, 130, 246, 1)',
borderWidth: 2,
pointRadius: 5,
pointBackgroundColor: isDarkMode ? 'rgba(59, 130, 246, 0.8)' : 'rgba(59, 130, 246, 1)',
tension: 0.4,
fill: false
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
suggestedMax: Math.max(...data) * 1.1,
ticks: {
color: isDarkMode ? '#e5e7eb' : '#374151'
},
grid: {
color: isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)'
}
},
x: {
ticks: {
color: isDarkMode ? '#e5e7eb' : '#374151'
},
grid: {
color: isDarkMode ? 'rgba(255, 255, 255, 0.1)' : 'rgba(0, 0, 0, 0.1)'
}
}
},
plugins: {
legend: {
labels: {
color: isDarkMode ? '#e5e7eb' : '#374151'
}
}
}
}
});
}
function resetTodayTasks() {
if (confirm('Are you sure you want to reset all today\'s tasks? This will clear all goals and remove tasks from today\'s list.')) {
projects.forEach(project => {
traverseTasks(project.tasks, task => {
if (task.inToday) {
task.inToday = false;
task.dailyGoal = 0;
task.dailyProgress = 0;
}
});
});
saveData();
renderDashboard();
renderTaskList();
renderProjectList();
}
}
let currentTimeEntryTask = null;
function init() {
loadInitialData();
renderProjectList();
showDashboard();
setupEventListeners();
setupTimeEntryModal();
// Handle page unload
window.addEventListener('beforeunload', () => {
if (currentPomodoroTask && pomodoroStartTime) {
stopPomodoro();
}
});
// Setup settings modal listeners
document.getElementById('settings-btn').addEventListener('click', showSettings);
document.getElementById('close-settings').addEventListener('click', hideSettings);
document.getElementById('sound-select').addEventListener('change', handleSoundSelection);
document.getElementById('test-sound-btn').addEventListener('click', testSound);
document.getElementById('close-timer-complete').addEventListener('click', closeTimerComplete);
isDarkMode = document.documentElement.classList.contains('dark');
const icon = document.getElementById('dark-mode-icon');
if (isDarkMode) {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
} else {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
}
}
function exportData() {
const data = JSON.stringify(projects, null, 2);
const blob = new Blob([data], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `focus-flow-backup-${new Date().toISOString().split('T')[0]}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
function importData(file) {
const reader = new FileReader();
reader.onload = function (e) {
try {
const importedData = JSON.parse(e.target.result);
if (Array.isArray(importedData)) {
if (confirm('This will replace all existing data. Are you sure?')) {
projects = importedData;
saveData();
renderProjectList();
renderTaskList();
renderDashboard();
alert('Data imported successfully!');
}
} else {
alert('Invalid data format');
}
} catch (error) {
alert('Error importing data: ' + error.message);
}
};
reader.readAsText(file);
}
function setupEventListeners() {
document.getElementById('export-btn').addEventListener('click', exportData);
document.getElementById('import-btn').addEventListener('click', () => {
document.getElementById('import-file').click();
});
document.getElementById('import-file').addEventListener('change', (e) => {
if (e.target.files.length > 0) {
importData(e.target.files[0]);
e.target.value = ''; // Reset file input
}
});
document.getElementById('reset-today-btn').addEventListener('click', resetTodayTasks);
document.getElementById('add-project-btn').addEventListener('click', addProject);
document.getElementById('new-project-name').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
addProject();
}
});
document.getElementById('new-task-title').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
const title = e.target.value.trim();
if (title) {
addTask(null, title);
e.target.value = '';
}
}
});
document.getElementById('dark-mode-toggle').addEventListener('click', toggleDarkMode);
document.getElementById('report-btn').addEventListener('click', showReport);
document.getElementById('close-report-btn').addEventListener('click', hideReport);
document.getElementById('search-input').addEventListener('input', (e) => {
searchTerm = e.target.value.toLowerCase();
renderTaskList();
});
document.getElementById('hide-completed-btn').addEventListener('click', () => {
hideCompleted = !hideCompleted;
document.getElementById('hide-completed-btn').classList.toggle('bg-gray-200');
renderTaskList();
});
document.addEventListener('keydown', handleKeyDown);
}
function setupTimeEntryModal() {
document.getElementById('cancel-time-entry').addEventListener('click', () => {
closeTimeEntryModal();
});
document.getElementById('save-time-entry').addEventListener('click', () => {
saveTimeEntry();
});
// Close modal when clicking outside the content
document.getElementById('time-entry-modal').addEventListener('click', function () {
closeTimeEntryModal();
});
// Prevent clicks inside the content from closing the modal
document.getElementById('time-entry-modal-content').addEventListener('click', function (e) {
e.stopPropagation();
});
}
function openTimeEntryModal(task) {
currentTimeEntryTask = task;
document.getElementById('time-entry-modal').classList.remove('hidden');
document.getElementById('manual-time-minutes').value = '';
// Set today as default date when opening modal
const today = new Date().toISOString().split('T')[0];
document.getElementById('manual-time-date').value = today;
document.getElementById('manual-time-minutes').focus();
}
function closeTimeEntryModal() {
document.getElementById('time-entry-modal').classList.add('hidden');
currentTimeEntryTask = null;
}
function saveTimeEntry() {
const minutes = parseInt(document.getElementById('manual-time-minutes').value);
const dateStr = document.getElementById('manual-time-date').value;
if (!minutes || minutes <= 0 || !dateStr) {
alert('Please enter valid duration and date');
return;
}
const date = new Date(dateStr);
date.setHours(12, 0, 0, 0); // Set to noon to avoid timezone issues
// Create start date from input date at current time
const now = new Date();
date.setHours(now.getHours(), now.getMinutes(), now.getSeconds());
const timeEntry = {
start: date.toISOString(),
end: new Date(date.getTime() + minutes * 60000).toISOString(),
duration: minutes * 60
};
const task = findTaskByIdGlobal(currentTimeEntryTask.id);
if (task) {
if (!task.timeEntries) {
task.timeEntries = [];
}
task.timeEntries.push(timeEntry);
task.timeSpent += timeEntry.duration;
if (task.inToday) {
const today = new Date();
today.setHours(0, 0, 0, 0);
let todayTimeSpent = 0;
task.timeEntries.forEach(entry => {
const entryDate = new Date(entry.start);
if (entryDate >= today) {
todayTimeSpent += entry.duration;
}
});
task.dailyProgress = Math.floor(todayTimeSpent / 60 / 25);
}
saveData();
renderTaskList();
renderProjectList();
renderDashboard();
closeTimeEntryModal();
}
}
function handleKeyDown(e) {
if (e.ctrlKey || e.metaKey) {
switch (e.key) {
case 'n':
e.preventDefault();
document.getElementById('new-task-title').focus();
break;
case 'p':
e.preventDefault();
document.getElementById('new-project-name').focus();
break;
case '/':
e.preventDefault();
document.getElementById('search-input').focus();
break;
}
}
}
function addProject() {
const projectNameInput = document.getElementById('new-project-name');
const name = projectNameInput.value.trim();
if (name) {
const newProject = {
id: generateId(),
name: name,
tasks: []
};
projects.push(newProject);
saveData();
renderProjectList();
projectNameInput.value = '';
}
}
function renderProjectList() {
const projectList = document.getElementById('project-list');
projectList.innerHTML = '';
projectDropdowns = []; // Reset global array
projects.forEach(project => {
const projectDiv = document.createElement('div');
projectDiv.className = 'mb-4';
const headerDiv = document.createElement('div');
headerDiv.className = 'flex items-center justify-between mb-1';
const btn = document.createElement('button');
btn.textContent = project.name;
btn.className = `flex-grow text-left p-2 rounded mr-2 ${selectedProject && selectedProject.id === project.id ? "bg-blue-500 text-white" : "bg-gray-100 text-black dark:bg-gray-700 dark:text-gray-200"}`;
btn.addEventListener('click', () => selectProject(project.id));
const statsDiv = document.createElement('div');
statsDiv.className = 'mt-1 px-2';
const progressContainer = document.createElement('div');
progressContainer.className = 'flex items-center gap-2';
const progress = calculateProjectProgress(project.tasks);
const totalTime = calculateProjectTotalTime(project.tasks);
const progressBar = document.createElement('div');
progressBar.className = 'flex-grow h-2 bg-gray-200 rounded dark:bg-gray-600';
progressBar.innerHTML = `
<div class="h-full bg-green-500 rounded" style="width: ${progress}%"></div>
`;
const progressText = document.createElement('span');
progressText.className = 'text-sm text-gray-600 dark:text-gray-400';
progressText.textContent = `${progress}%`;
const timeText = document.createElement('span');
timeText.className = 'text-sm text-gray-600 ml-4 dark:text-gray-400';
timeText.textContent = `Total: ${(totalTime / 3600).toFixed(1)}h`;
progressContainer.appendChild(progressBar);
progressContainer.appendChild(progressText);
progressContainer.appendChild(timeText);
statsDiv.appendChild(progressContainer);
const menuDiv = document.createElement('div');
menuDiv.className = 'relative';
const menuBtn = document.createElement('button');
menuBtn.className = 'p-1 hover:bg-gray-100 rounded dark:hover:bg-gray-700';
menuBtn.innerHTML = `<i class="fas fa-ellipsis-v text-gray-700 dark:text-gray-200"></i>`;
menuBtn.addEventListener('click', (e) => {
e.stopPropagation();
const dropdown = menuBtn.nextElementSibling;
projectDropdowns.forEach(d => {
if (d !== dropdown) d.classList.add('hidden');
});
dropdown.classList.toggle('hidden');
});
const dropdownDiv = document.createElement('div');
dropdownDiv.className = 'dropdown-content absolute right-0 mt-1 w-32 bg-white border rounded shadow-lg hidden z-10 dark:bg-gray-800 dark:border-gray-700';
const editBtn = document.createElement('button');
editBtn.innerHTML = 'Edit';
editBtn.className = 'w-full text-left px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-700';
editBtn.addEventListener('click', (e) => {
e.stopPropagation();
dropdownDiv.classList.add('hidden');
editProject(project.id);
});
const deleteBtn = document.createElement('button');
deleteBtn.innerHTML = 'Delete';
deleteBtn.className = 'w-full text-left px-4 py-2 hover:bg-gray-100 text-red-500 dark:hover:bg-gray-700';
deleteBtn.addEventListener('click', (e) => {
e.stopPropagation();
dropdownDiv.classList.add('hidden');
deleteProject(project.id);
});
dropdownDiv.appendChild(editBtn);
dropdownDiv.appendChild(deleteBtn);
menuDiv.appendChild(menuBtn);
menuDiv.appendChild(dropdownDiv);
projectDropdowns.push(dropdownDiv);
headerDiv.appendChild(btn);
headerDiv.appendChild(menuDiv);
projectDiv.appendChild(headerDiv);
projectDiv.appendChild(statsDiv);
projectList.appendChild(projectDiv);
});
}
function editProject(projectId) {
const project = projects.find(p => p.id === projectId);
const newName = prompt('Edit project name:', project.name);
if (newName && newName.trim()) {
project.name = newName.trim();
saveData();
renderProjectList();
if (selectedProject && selectedProject.id === projectId) {
document.getElementById('project-title').textContent = newName;
}
}
}
function deleteProject(projectId) {
if (confirm('Are you sure you want to delete this project and all its tasks?')) {
const index = projects.findIndex(p => p.id === projectId);
if (index !== -1) {
projects.splice(index, 1);
saveData();
renderProjectList();
if (selectedProject && selectedProject.id === projectId) {
selectedProject = projects.length > 0 ? projects[0] : null;
if (selectedProject) {
document.getElementById('project-title').textContent = selectedProject.name;
renderTaskList();
} else {
document.getElementById('project-title').textContent = '';
document.getElementById('task-list').innerHTML = '';
}
}
}
}
}
function selectProject(projectId) {
selectedProject = projects.find(p => p.id === projectId);
document.getElementById('project-title').textContent = selectedProject.name;
document.getElementById('dashboard-view').classList.add('hidden');
document.getElementById('project-view').classList.remove('hidden');
renderProjectList();
renderTaskList();
}
function showDashboard() {
selectedProject = null;
document.getElementById('project-title').textContent = 'Focus Flow';
document.getElementById('project-view').classList.add('hidden');
document.getElementById('dashboard-view').classList.remove('hidden');
renderDashboard();
renderProjectList();
renderWeeklyChart();
}
function renderDashboard() {
const dashboardView = document.getElementById('dashboard-view');
let totalProjects = projects.length;
let totalTasks = 0;
let totalCompletedTasks = 0;
let totalTimeSpent = 0;
let todayTimeSpent = 0;
let mostActiveProject = { name: '-', time: 0 };
let highestProgress = { name: '-', progress: 0 };
const today = new Date();
today.setHours(0, 0, 0, 0);
projects.forEach(project => {
const projectTotalTime = calculateProjectTotalTime(project.tasks);
const projectProgress = calculateProjectProgress(project.tasks);
const completedTasks = countTasks(project.tasks, true);
const ongoingTasks = countTasks(project.tasks, false);
totalTasks += completedTasks + ongoingTasks;
totalCompletedTasks += completedTasks;
totalTimeSpent += projectTotalTime;
project.tasks.forEach(task => {
const calculateTodayTime = (task) => {
let time = 0;
if (task.timeEntries) {
task.timeEntries.forEach(entry => {
const entryDate = new Date(entry.start);
if (entryDate >= today) {
time += entry.duration;
}
});
}
task.subtasks.forEach(subtask => {
time += calculateTodayTime(subtask);
});
return time;
};
todayTimeSpent += calculateTodayTime(task);
});
if (projectTotalTime > mostActiveProject.time) {
mostActiveProject = { name: project.name, time: projectTotalTime };
}
if (projectProgress > highestProgress.progress) {
highestProgress = { name: project.name, progress: projectProgress };
}
});
const weekData = getWeeklyTimeData();
dashboardView.innerHTML = `
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="p-6 bg-white rounded-lg shadow dark:bg-gray-800 dark:text-gray-200">
<h3 class="font-bold mb-2 text-lg">Weekly Activity</h3>
<div style="height: 600px;">
<canvas id="weeklyChart"></canvas>
</div>
</div>
<div class="p-6 bg-white rounded-lg shadow dark:bg-gray-800 dark:text-gray-200">
<div class="flex justify-between items-center mb-4">
<h3 class="text-xl font-bold">Today's Tasks</h3>
<button id="reset-today-btn" class="p-2 border rounded dark:border-gray-700 hover:bg-gray-100 dark:hover:bg-gray-700" title="Reset Today's Tasks">
<svg class="h-5 w-5 text-gray-700 dark:text-gray-200" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
</svg>
</button>
</div>
<div id="today-tasks-container" class="space-y-3" style="max-height: 600px; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none;">
<style>
#today-tasks-container::-webkit-scrollbar {
display: none;
}
</style>
</div>
</div>
</div>
`;
const todayTasksContainer = document.getElementById('today-tasks-container');
const todayTasks = getTodayTasks();
// Sort tasks - completed tasks go to the end
const sortedTasks = [...todayTasks].sort((a, b) => {
if (a.isCompleted === b.isCompleted) return 0;
return a.isCompleted ? 1 : -1;
});
todayTasksContainer.innerHTML = '';
sortedTasks.forEach(task => {
const taskDiv = document.createElement('div');
taskDiv.className = 'bg-white rounded-lg shadow-sm hover:shadow-md transition-shadow duration-200 dark:bg-gray-800 overflow-hidden';
const taskHeader = document.createElement('div');
taskHeader.className = 'flex items-center justify-between p-3 border-b dark:border-gray-700';
const leftDiv = document.createElement('div');
leftDiv.className = 'flex items-center space-x-3 flex-grow max-w-[70%]';
const statusDiv = document.createElement('div');
statusDiv.className = `w-2 h-2 rounded-full ${task.isCompleted ? 'bg-green-500' : (task.dailyProgress >= task.dailyGoal && task.dailyGoal > 0 ? 'bg-blue-500' : 'bg-yellow-500')}`;
leftDiv.appendChild(statusDiv);
const taskPath = getTaskPath(task.id);
const labelContainer = document.createElement('div');
labelContainer.className = 'overflow-hidden';
const label = createLabelWithLinks(taskPath.join(' > '), `font-medium dark:text-gray-200 break-words ${task.isCompleted ? 'line-through text-gray-500 dark:text-gray-400' : ''}`);
labelContainer.appendChild(label);
leftDiv.appendChild(labelContainer);
taskHeader.appendChild(leftDiv);
const rightDiv = document.createElement('div');
rightDiv.className = 'flex items-center space-x-2';
const todayBtn = createTodayButton(task, () => {
const originalTask = findTaskByIdGlobal(task.id);
if (originalTask) {
originalTask.inToday = false;
saveData();
renderDashboard();
renderTaskList();
}
});
todayBtn.title = 'Remove from Today\'s Tasks';
rightDiv.appendChild(todayBtn);
const timerBtn = createTimerButton(task, () => {
const currentTask = findTaskByIdGlobal(task.id);
if (currentTask.isTimerRunning) {
stopPomodoro();
} else {
startPomodoro(currentTask);
}