Приложение для заметок, с целями и с ии чатом · VibeGit
Приложение для заметок, с целями и с ии чатом Это приложение для заметок с ии(свои ключи), есть поддерживание целей, их отслеживание по %
prilozhenie-dlya-zametok-s-tselyami-i-s-ii-chato / src / components / screens / goals.tsx 1020 строк · изменён 5 нояб., 15:46
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
"use client" ;
import { useRef, useState } from "react" ;
import {
Check ,
ChevronLeft ,
ChevronRight ,
Flag ,
GripVertical ,
Plus ,
Repeat ,
Trash2 ,
} from "lucide-react" ;
import { useStore } from "@/lib/store" ;
import type { Goal , GoalHorizon , GoalWeek , StarterTask } from "@/lib/types" ;
import {
cap1
cn
dayProgress
fmtDayMon
fmtDayShort
fromISODate
goalCounts
goalProgress
monthChoices
monthLabel
pct
repeatLabel
repeatShort
uid
weekProgress
level
level goalId
level goalId weekId
day
days
week
month
value
onChange
suffix
value
v
suffix
opt
active value opt
opt opt
suffix value
suffix
tasks
onChange
tasks
t
rowRefs
dragIdx setDragIdx
dragDy
e i
e
e e
i
dragDy
e i
dragIdx i
row rowRefs i
h row row
dragDy e
from dragIdx
shift dragDy h
to tasks from shift
to from
next tasks
moved next from
next to moved
next
to
dragDy
tasks t i
t t
t
open onClose open
dispatch
title setTitle
description setDescription
horizon setHorizon
daysCount setDaysCount
tasks setTasks
taskInput setTaskInput
every setEvery
monthISO setMonthISO
choices
t taskInput
t
prev
prev
title t horizon every repeat every
horizon
n
n
tasks
horizon
every
horizon
choices c
c
horizon
horizon
horizon
title
type title description horizon monthISO daysCount tasks
title
crumbs onBack crumbs
crumbs c i
i c
onOpen id
state dispatch
sheetOpen setSheetOpen
state
state g i
p g
done total g
complete total p
g g g g complete
p
done total g g
goal
week
day
goal
week
day
dispatch
rowRefs
dragId setDragId
dragDy
tasks day
next tasks
type
goalId goal
weekId week
dayId day
tasks next
e id
e
e e
id
dragDy
e id
dragId id
row rowRefs id
h row row
dragDy e
from tasks t t id
shift dragDy h
to tasks from shift
to from
next tasks
moved next from
next to moved
next
dragDy
tasks t
t t e
type
goalId goal
weekId week
dayId day
taskId t
title e
e
e
e
e
t
newId
type
goalId goal
weekId week
dayId day
afterTaskId t
newId
el
el
el block behavior
e t
e
type
goalId goal
weekId week
dayId day
taskId t
t
type
goalId goal
weekId week
dayId day
taskId t
t
t
t
goal
week
onBack
crumbs
goal
week
crumbs
dispatch
addingTo setAddingTo
newTask setNewTask
newRepeat setNewRepeat
wp week
hasTasks week d d
allDone hasTasks wp
multiDay goal n w n w
dayId
t newTask
t
newId
type
goalId goal
weekId week
dayId
title t
newId
newRepeat repeat newRepeat
newRepeat
block behavior
crumbs crumbs
hasTasks wp
allDone
goal
week d
date d
dp d
d
addingTo d
multiDay
goal
onBack
onOpenWeek
goal
weekId
dispatch
confirmDelete setConfirmDelete
p goal
total goal
complete total p
goal goal
goal w
wp w
hasTasks w d d
w hasTasks wp
goal
p
complete
confirmDelete
setConfirmDelete
onDelete
crumbs
onBack
goal
p
complete
confirmDelete
v
crumbs
dispatch
goal goal goal confirmDelete p complete
state
drill setDrill level
goal drill state g g drill
week
drill goal
goal w w drill
drill goal
level
drill
drill goal
drill goal week
REPEAT_STEP_OPTIONS
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
}
from
"@/lib/utils"
;
import
{ Checkbox , EmptyState , ProgressBar , Segmented , Sheet , SwipeToDelete }
from
"../ui"
;
type
Drill
=
|
{
:
"list"
}
|
{
:
"goal"
;
:
string
}
|
{
:
"week"
;
:
string
;
:
string
}
;
const
HORIZON_LABEL
:
Record
<
GoalHorizon
,
string
>
=
{
:
"На сегодня"
,
:
"На пару дней"
,
:
"На неделю"
,
:
"На месяц"
,
}
;
function
RepeatChips
(
{
,
,
,
}
:
{
:
number
|
null
;
onChange
:
(
:
number
|
null
)
=>
void
;
?
:
string
;
}
)
{
return
(
< div>
< div
role = " group"
aria-label = " Ритм повторения задачи"
className = " -mx-1 flex flex-wrap gap-1.5 px-1 py-0.5"
>
{
REPEAT_STEP_OPTIONS
.
map
(
(
)
=>
{
const
=
===
.
value
;
return
(
< button
key = { String ( opt. value ) }
type = " button"
aria-pressed = { active}
onPointerDown = { ( e) => e. preventDefault ( ) }
onClick = { ( ) => onChange ( opt. value ) }
className = { cn (
"flex shrink-0 items-center gap-1 rounded-full border px-2.5 py-1 text-[11px] font-bold transition-all active:scale-95" ,
active
? "border-accent bg-accent-soft text-accent-strong"
: "border-line text-faint hover:text-body"
) }
>
{
.
value
!==
null
&&
< Repeat className = " h-3 w-3" />
}
{
.
label
}
</ button>
)
;
}
)
}
</ div>
{
&&
?
(
< p className = " mt-1 px-1 text-[11px] font-semibold text-faint" >
{
}
</ p>
)
:
null
}
</ div>
)
;
}
function
StarterTaskList
(
{
,
,
}
:
{
:
StarterTask
[
]
;
onChange
:
(
:
StarterTask
[
]
)
=>
void
;
}
)
{
const
=
useRef
(
new
Map< number , HTMLDivElement>
(
)
)
;
const
[
,
]
=
useState < number | null >
(
null
)
;
const
=
useRef
(
0
)
;
const
startDrag
=
(
:
React
.
PointerEvent
,
:
number
)
=>
{
.
preventDefault
(
)
;
(
.
currentTarget
as
HTMLElement
)
.
setPointerCapture
(
.
pointerId
)
;
setDragIdx
(
)
;
.
current
=
0
;
}
;
const
moveDrag
=
(
:
React
.
PointerEvent
,
:
number
)
=>
{
if
(
!==
)
return
;
const
=
.
current
.
get
(
)
;
const
=
?
.
getBoundingClientRect
(
)
.
height
:
40
;
.
current
+=
.
movementY
??
0
;
const
=
;
const
=
Math
.
round
(
.
current
/
)
;
const
=
Math
.
max
(
0
,
Math
.
min
(
.
length
-
1
,
+
)
)
;
if
(
!==
)
{
const
=
[
...
]
;
const
[
]
=
.
splice
(
,
1
)
;
.
splice
(
,
0
,
)
;
onChange
(
)
;
setDragIdx
(
)
;
.
current
=
0
;
}
}
;
const
endDrag
=
(
)
=>
setDragIdx
(
null
)
;
return
(
< ul className = " mb-2 flex flex-col gap-1 select-none" >
{
.
map
(
(
,
)
=>
(
< li key = { ` ${ i} - ${ t. title} ` } >
< div
ref = { ( el) => {
if ( el) rowRefs. current . set ( i, el) ;
} }
className = { cn (
"flex items-center gap-2 rounded-xl border border-line bg-card-2/50 px-2 py-2" ,
dragIdx === i && "z-10 shadow-md"
) }
>
< button
type = " button"
aria-label = { ` Перетащить задачу « ${ t. title} » ` }
onPointerDown = { ( e) => startDrag ( e, i) }
onPointerMove = { ( e) => moveDrag ( e, i) }
onPointerUp = { endDrag}
onPointerCancel = { endDrag}
className = " flex h-7 w-5 shrink-0 cursor-grab touch-none items-center justify-center text-faint/60 hover:text-faint active:cursor-grabbing"
>
< GripVertical className = " h-4 w-4" />
</ button>
< span className = " min-w-0 flex-1 truncate text-sm font-semibold text-body" >
{
.
title
}
</ span>
{
.
repeat
?
(
< span
title = { repeatLabel ( t. repeat ) }
className = " flex shrink-0 items-center gap-1 rounded-full bg-accent-soft px-2 py-0.5 text-[10px] font-bold text-accent-strong"
>
< Repeat className = " h-2.5 w-2.5" />
{
repeatShort
(
.
repeat
)
}
</ span>
)
:
null
}
< button
onClick = { ( ) => onChange ( tasks. filter ( ( _, j) => j !== i) ) }
aria-label = { ` Убрать задачу « ${ t. title} » ` }
className = " flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-faint transition-all hover:bg-danger/10 hover:text-danger active:scale-90"
>
< Trash2 className = " h-3.5 w-3.5" />
</ button>
</ div>
</ li>
)
)
}
</ ul>
)
;
}
function
GoalSheet
(
{
,
}
:
{
:
boolean
;
onClose
:
(
)
=>
void
}
)
{
const
{
}
=
useStore
(
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState < GoalHorizon>
(
"month"
)
;
const
[
,
]
=
useState
(
2
)
;
const
[
,
]
=
useState < StarterTask[ ] >
(
[
]
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState < number | null >
(
null
)
;
const
[
,
]
=
useState
(
(
)
=>
monthChoices
(
1
)
[
0
]
.
iso
)
;
const
=
monthChoices
(
3
)
;
const
reset
=
(
)
=>
{
setTitle
(
""
)
;
setDescription
(
""
)
;
setHorizon
(
"month"
)
;
setDaysCount
(
2
)
;
setTasks
(
[
]
)
;
setTaskInput
(
""
)
;
setEvery
(
null
)
;
}
;
const
addTask
=
(
)
=>
{
const
=
.
trim
(
)
;
if
(
!
)
return
;
setTasks
(
(
)
=>
[
...
,
{
:
,
...
(
!==
"day"
&&
?
{
:
}
:
{
}
)
}
,
]
)
;
setTaskInput
(
""
)
;
}
;
return
(
< Sheet open = { open} onClose = { onClose} title = " Новая цель" >
< div className = " flex flex-col gap-4" >
< Segmented
ariaLabel = " Горизонт цели"
options = { ( [
[ "day" , "День" ] ,
[ "days" , "Дни" ] ,
[ "week" , "Неделя" ] ,
[ "month" , "Месяц" ] ,
] as [ GoalHorizon , string ] [ ] ) . map ( ( [ h, label] ) => ( {
value: h,
label,
} ) ) }
value = { horizon}
onChange = { setHorizon}
/>
{
===
"days"
&&
(
< div>
< p className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Сколько дней
</ p>
< div className = " flex gap-2" >
{
[
2
,
3
,
4
]
.
map
(
(
)
=>
(
< button
key = { n}
onClick = { ( ) => setDaysCount ( n) }
aria-pressed = { daysCount === n}
className = { cn (
"num flex-1 rounded-xl border px-2 py-2.5 text-sm font-bold transition-all active:scale-95" ,
daysCount === n
? "border-accent bg-accent-soft text-accent-strong"
: "border-line text-faint hover:text-body"
) }
>
{
}
</ button>
)
)
}
</ div>
</ div>
)
}
< input
value = { title}
onChange = { ( e) => setTitle ( e. target . value ) }
placeholder = " Название — например: выучить испанский"
aria-label = " Название цели"
className = " h-12 w-full rounded-2xl border border-line bg-card px-4 text-[15px] text-body placeholder:text-faint/60 focus:border-accent focus:outline-none"
/>
< textarea
value = { description}
onChange = { ( e) => setDescription ( e. target . value ) }
placeholder = " Описание (по желанию): зачем, критерий успеха…"
aria-label = " Описание цели"
rows = { 2 }
className = " w-full resize-none rounded-2xl border border-line bg-card px-4 py-3 text-sm leading-relaxed text-body placeholder:text-faint/60 focus:border-accent focus:outline-none"
/>
{
}
< div>
< p className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Задачи сразу (по желанию)
</ p>
{
.
length
>
0
&&
(
< StarterTaskList tasks = { tasks} onChange = { setTasks} />
)
}
< div className = " flex items-center gap-2" >
< input
value = { taskInput}
onChange = { ( e) => setTaskInput ( e. target . value ) }
onKeyDown = { ( e) => {
if ( e. key === "Enter" && ! e. nativeEvent . isComposing ) {
e. preventDefault ( ) ;
addTask ( ) ;
}
} }
placeholder = " Задача — Enter добавит"
aria-label = " Стартовая задача цели"
className = " h-11 flex-1 rounded-xl border border-line bg-card px-3.5 text-sm text-body placeholder:text-faint/60 focus:border-accent focus:outline-none"
/>
< button
onClick = { addTask}
disabled = { ! taskInput. trim ( ) }
aria-label = " Добавить стартовую задачу"
className = " flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-accent text-white transition-all hover:brightness-110 active:scale-90 disabled:opacity-40"
>
< Plus className = " h-4.5 w-4.5" />
</ button>
</ div>
{
!==
"day"
&&
(
< div className = " mt-2" >
< RepeatChips value = { every} onChange = { setEvery} />
< p className = " mt-1 px-1 text-[11px] leading-relaxed text-faint" >
{
?
` Новая задача ляжет ${ repeatLabel ( every) } — от первого дня до конца цели. `
:
"Новая задача попадёт только в первый день — потом её можно раскидать по датам."
}
</ p>
</ div>
)
}
</ div>
{
===
"month"
&&
(
< div>
< p className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Месяц
</ p>
< div className = " flex gap-2" >
{
.
map
(
(
)
=>
(
< button
key = { c. iso }
onClick = { ( ) => setMonthISO ( c. iso ) }
aria-pressed = { monthISO === c. iso }
className = { cn (
"flex-1 rounded-xl border px-2 py-2.5 text-xs font-bold transition-all active:scale-95" ,
monthISO === c. iso
? "border-accent bg-accent-soft text-accent-strong"
: "border-line text-faint hover:text-body"
) }
>
{
.
label
}
</ button>
)
)
}
</ div>
</ div>
)
}
< p className = " text-xs leading-relaxed text-faint" >
{
===
"month"
?
"Период — от сегодня до конца выбранного месяца; недели разметятся автоматически."
:
===
"week"
?
"7 дней от сегодня — распределите задачи по датам."
:
===
"days"
?
` ${ daysCount} дн. от сегодня — короткий спринт. `
:
"Один день — сегодня. Сразу добавляйте задачи и закрывайте."
}
</ p>
<button
onClick=
{
(
)
=>
{
if
(
.
trim
(
)
)
{
dispatch
(
{
:
"goal/add"
,
,
,
,
,
,
}
)
;
reset
(
)
;
onClose
(
)
;
}
}
}
disabled=
{
!
.
trim
(
)
}
className="h-12 rounded-2xl bg-accent text-sm font-bold text-white transition-all hover:brightness-110 active:scale-[0.98] disabled:opacity-40"
>
Создать цель
</ button>
</ div>
</ Sheet >
)
;
}
function
DrillHeader
(
{
,
}
:
{
:
string
[
]
;
onBack
:
(
)
=>
void
}
)
{
return
(
< div className = " mb-4 flex items-center gap-2" >
< button
onClick = { onBack}
aria-label = " Назад"
className = " flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-line bg-card text-faint transition-all hover:text-body active:scale-90"
>
< ChevronLeft className = " h-4.5 w-4.5" />
</ button>
< nav aria-label = " Путь" className = " flex min-w-0 items-center gap-1 text-xs font-semibold text-faint" >
{
.
map
(
(
,
)
=>
(
< span key = { i} className = " flex min-w-0 items-center gap-1" >
{
>
0
&&
< ChevronRight className = " h-3 w-3 shrink-0" />
}
< span className = { cn ( "truncate" , i === crumbs. length - 1 && "text-body" ) } >
{
}
</ span>
</ span>
)
)
}
</ nav>
</ div>
)
;
}
function
GoalList
(
{
}
:
{
onOpen
:
(
:
string
)
=>
void
}
)
{
const
{
,
}
=
useStore
(
)
;
const
[
,
]
=
useState
(
false
)
;
if
(
.
goals
.
length
===
0
)
{
return
(
< >
< EmptyState
image = " empty-goals"
title = " Ни одной цели"
hint = " Цель на день, неделю или месяц — Margin разметит структуру сам."
action = {
< button
onClick = { ( ) => setSheetOpen ( true ) }
className = " flex items-center gap-1.5 rounded-full bg-accent px-4 py-2 text-sm font-bold text-white transition-all hover:brightness-110 active:scale-95"
>
< Plus className = " h-4 w-4" /> Поставить цель
</ button>
}
/>
< GoalSheet open = { sheetOpen} onClose = { ( ) => setSheetOpen ( false ) } />
</ >
)
;
}
return
(
< >
< ul className = " flex flex-col gap-3" >
{
.
goals
.
map
(
(
,
)
=>
{
const
=
goalProgress
(
)
;
const
{
,
}
=
goalCounts
(
)
;
const
=
>
0
&&
===
1
;
return
(
< li key = { g. id } className = " animate-rise" style = { { animationDelay: ` ${ Math. min ( i, 6 ) * 50 } ms ` } } >
< SwipeToDelete
label = { g. title }
onDelete = { ( ) => dispatch ( { type: "goal/delete" , id: g. id } ) }
>
< button
onClick = { ( ) => onOpen ( g. id ) }
className = " w-full rounded-3xl border border-line bg-card p-4.5 text-left transition-all duration-150 hover:border-accent/50 hover:shadow-sm active:scale-[0.98] focus-visible:outline-2 focus-visible:outline-accent"
>
< div className = " flex items-start justify-between gap-3" >
< div className = " min-w-0" >
< p className = " flex items-center gap-1.5 text-[11px] font-bold uppercase tracking-wider text-faint" >
< Flag className = " h-3 w-3" />
{
.
horizon
===
"month"
?
monthLabel
(
.
monthISO
)
:
HORIZON_LABEL
[
.
horizon
]
}
</ p>
< h3
className = { cn (
"mt-1 font-bold leading-snug text-body transition-colors" ,
complete && "text-faint line-through"
) }
>
{
.
title
}
</ h3>
</ div>
{
?
(
< span className = " flex shrink-0 items-center gap-1 rounded-full bg-success/15 px-2.5 py-1 text-xs font-bold text-success" >
< Check className = " h-3.5 w-3.5" strokeWidth = { 3 } />
Готово
</ span>
)
:
(
< span className = " num shrink-0 rounded-full bg-accent-soft px-2.5 py-1 text-xs font-bold text-accent-strong" >
{
pct
(
)
}
</ span>
)
}
</ div>
< div className = " mt-3.5" >
< ProgressBar value = { p} size = " lg" />
</ div>
< div className = " mt-2.5 flex items-center justify-between text-xs text-faint" >
< span className = " num font-semibold" >
{
}
/
{
}
задач
</ span>
< span className = " flex items-center gap-1 font-semibold" >
{
.
horizon
===
"month"
?
` ${ g. weeks. length} нед. `
:
HORIZON_LABEL
[
.
horizon
]
}
< ChevronRight className = " h-3.5 w-3.5" />
</ span>
</ div>
</ button>
</ SwipeToDelete >
</ li>
)
;
}
)
}
</ ul>
< button
onClick = { ( ) => setSheetOpen ( true ) }
className = " mt-3 flex w-full items-center justify-center gap-1.5 rounded-3xl border border-dashed border-line py-3.5 text-sm font-bold text-faint transition-all hover:border-accent hover:text-accent active:scale-[0.98]"
>
< Plus className = " h-4 w-4" />
Новая цель
</ button>
< GoalSheet open = { sheetOpen} onClose = { ( ) => setSheetOpen ( false ) } />
</ >
)
;
}
function
TaskList
(
{
,
,
,
}
:
{
:
Goal
;
:
GoalWeek
;
:
Goal
[
"weeks"
]
[
number
]
[
"days"
]
[
number
]
;
}
)
{
const
{
}
=
useStore
(
)
;
const
=
useRef
(
new
Map< string , HTMLDivElement>
(
)
)
;
const
[
,
]
=
useState < string | null >
(
null
)
;
const
=
useRef
(
0
)
;
const
=
.
tasks
;
const
reorder
=
(
:
typeof
)
=>
dispatch
(
{
:
"goal/reorder-tasks"
,
:
.
id
,
:
.
id
,
:
.
id
,
:
,
}
)
;
const
startDrag
=
(
:
React
.
PointerEvent
,
:
string
)
=>
{
.
preventDefault
(
)
;
(
.
currentTarget
as
HTMLElement
)
.
setPointerCapture
(
.
pointerId
)
;
setDragId
(
)
;
.
current
=
0
;
}
;
const
moveDrag
=
(
:
React
.
PointerEvent
,
:
string
)
=>
{
if
(
!==
)
return
;
const
=
.
current
.
get
(
)
;
const
=
?
.
getBoundingClientRect
(
)
.
height
:
40
;
.
current
+=
.
movementY
??
0
;
const
=
.
findIndex
(
(
)
=>
.
id
===
)
;
const
=
Math
.
round
(
.
current
/
)
;
const
=
Math
.
max
(
0
,
Math
.
min
(
.
length
-
1
,
+
)
)
;
if
(
!==
)
{
const
=
[
...
]
;
const
[
]
=
.
splice
(
,
1
)
;
.
splice
(
,
0
,
)
;
reorder
(
)
;
.
current
=
0
;
}
}
;
const
endDrag
=
(
)
=>
setDragId
(
null
)
;
return
(
< ul className = " flex flex-col gap-1 select-none" >
{
.
map
(
(
)
=>
(
< li key = { t. id } >
< div
ref = { ( el) => {
if ( el) rowRefs. current . set ( t. id , el) ;
} }
className = { cn (
"group flex items-center gap-1.5 rounded-xl px-1 py-1 transition-colors" ,
dragId === t. id ? "z-10 bg-card-2 shadow-md" : "hover:bg-card-2/60"
) }
>
< button
type = " button"
aria-label = { ` Перетащить задачу « ${ t. title} » ` }
onPointerDown = { ( e) => startDrag ( e, t. id ) }
onPointerMove = { ( e) => moveDrag ( e, t. id ) }
onPointerUp = { endDrag}
onPointerCancel = { endDrag}
className = " flex h-7 w-5 shrink-0 cursor-grab touch-none items-center justify-center text-faint/60 transition-colors hover:text-faint active:cursor-grabbing"
>
< GripVertical className = " h-4 w-4" />
</ button>
< Checkbox
checked = { t. done }
onChange = { ( ) =>
dispatch ( {
type: "goal/toggle-task" ,
goalId: goal. id ,
weekId: week. id ,
dayId: day. id ,
taskId: t. id ,
} )
}
label = { t. title }
/>
<input
value=
{
.
title
}
data-task-id=
{
.
id
}
placeholder="Задача…"
onChange=
{
(
)
=>
dispatch
(
{
:
"goal/edit-task"
,
:
.
id
,
:
.
id
,
:
.
id
,
:
.
id
,
:
.
target
.
value
,
}
)
}
onKeyDown=
{
(
)
=>
{
if
(
.
nativeEvent
.
isComposing
)
return
;
if
(
.
key
===
"Enter"
)
{
.
preventDefault
(
)
;
if
(
!
.
title
.
trim
(
)
)
return
;
const
=
uid
(
"t"
)
;
dispatch
(
{
:
"goal/insert-task"
,
:
.
id
,
:
.
id
,
:
.
id
,
:
.
id
,
,
}
)
;
setTimeout
(
(
)
=>
{
const
=
document
.
querySelector
<
HTMLInputElement
>
(
` input[data-task-id=" ${ newId} "] `
)
;
?.
focus
(
)
;
?.
scrollIntoView
(
{
:
"center"
,
:
"smooth"
}
)
;
}
,
30
)
;
}
else
if
(
.
key
===
"Backspace"
&&
!
.
title
)
{
.
preventDefault
(
)
;
dispatch
(
{
:
"goal/delete-task"
,
:
.
id
,
:
.
id
,
:
.
id
,
:
.
id
,
}
)
;
}
}
}
onBlur=
{
(
)
=>
{
if
(
!
.
title
.
trim
(
)
)
dispatch
(
{
:
"goal/delete-task"
,
:
.
id
,
:
.
id
,
:
.
id
,
:
.
id
,
}
)
;
}
}
aria-label="Текст задачи"
className=
{
cn
(
"h-8 min-w-0 flex-1 bg-transparent text-[15px] placeholder:text-faint/50 focus:outline-none"
,
.
done
?
"text-faint line-through"
:
"text-body"
)
}
/>
{
.
repeat
?
(
< span
title = { ` Повтор: ${ repeatLabel ( t. repeat) } ` }
className = " flex shrink-0 items-center gap-0.5 rounded-full bg-accent-soft px-1.5 py-0.5 text-[10px] font-bold text-accent-strong"
>
< Repeat className = " h-2.5 w-2.5" />
{
repeatShort
(
.
repeat
)
}
</ span>
)
:
null
}
< button
onClick = { ( ) =>
dispatch ( {
type: "goal/delete-task" ,
goalId: goal. id ,
weekId: week. id ,
dayId: day. id ,
taskId: t. id ,
} )
}
aria-label = { ` Удалить задачу « ${ t. title} » ` }
className = " flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-faint transition-all hover:bg-danger/10 hover:text-danger active:scale-90"
>
< Trash2 className = " h-3.5 w-3.5" />
</ button>
</ div>
</ li>
)
)
}
</ ul>
)
;
}
function
WeekDetail
(
{
,
,
,
,
}
:
{
:
Goal
;
:
GoalWeek
;
onBack
:
(
)
=>
void
;
?
:
string
[
]
;
}
)
{
const
{
}
=
useStore
(
)
;
const
[
,
]
=
useState < string | null >
(
null
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState < number | null >
(
null
)
;
const
=
weekProgress
(
)
;
const
=
.
days
.
some
(
(
)
=>
.
tasks
.
length
>
0
)
;
const
=
&&
===
1
;
const
=
.
weeks
.
reduce
(
(
,
)
=>
+
.
days
.
length
,
0
)
>
1
;
const
submitTask
=
(
:
string
)
=>
{
const
=
.
trim
(
)
;
if
(
!
)
return
;
const
=
uid
(
"t"
)
;
dispatch
(
{
:
"goal/add-task"
,
:
.
id
,
:
.
id
,
,
:
,
,
...
(
?
{
:
}
:
{
}
)
,
}
)
;
setNewTask
(
""
)
;
if
(
)
return
;
setTimeout
(
(
)
=>
{
document
.
querySelector
(
` input[data-task-id=" ${ newId} "] `
)
?.
scrollIntoView
(
{
:
"center"
,
:
"smooth"
}
)
;
}
,
60
)
;
}
;
return
(
< div className = " animate-rise" >
{
&&
< DrillHeader crumbs = { crumbs} onBack = { onBack} />
}
{
&&
(
< div className = " flex items-center gap-3 rounded-2xl border border-line bg-card p-4" >
< ProgressBar value = { wp} className = " flex-1" />
< span className = " num text-sm font-bold text-accent-strong" >
{
?
pct
(
)
:
"—"
}
</ span>
</ div>
)
}
{
&&
(
< div className = " mt-3 flex items-center gap-2.5 rounded-2xl border border-success/30 bg-success/10 p-3.5 animate-pop" >
< span className = " flex h-8 w-8 items-center justify-center rounded-full bg-success text-white" >
< Check className = " h-4.5 w-4.5" strokeWidth = { 3 } />
</ span>
< p className = " text-sm font-bold text-body" >
{
.
horizon
===
"day"
?
"День закрыт."
:
"Неделя закрыта."
}
Так держать, сэр.
</ p>
</ div>
)
}
< div className = " mt-4 flex flex-col gap-3" >
{
.
days
.
map
(
(
)
=>
{
const
=
fromISODate
(
.
date
)
;
const
=
dayProgress
(
)
;
return
(
< section key = { d. id } className = " rounded-2xl border border-line bg-card p-4" >
< div className = " mb-2.5 flex items-center justify-between" >
< h4 className = " text-sm font-bold text-body" >
{
cap1
(
` ${ fmtDayShort ( date) } , ${ fmtDayMon ( date) } `
)
}
</ h4>
< span className = " num text-xs font-semibold text-faint" >
{
.
tasks
.
length
>
0
?
` ${ d. tasks. filter ( ( t) => t. done) . length} / ${ d. tasks. length} · ${ pct ( dp) } `
:
"—"
}
</ span>
</ div>
< ProgressBar value = { dp} size = " sm" className = " mb-2" />
< TaskList goal = { goal} week = { week} day = { d} />
{
===
.
id
?
(
< div className = " mt-1.5 flex flex-col gap-1.5" >
< div className = " flex items-center gap-2" >
< input
autoFocus
value = { newTask}
onChange = { ( e) => setNewTask ( e. target . value ) }
onKeyDown = { ( e) => {
if ( e. nativeEvent . isComposing ) return ;
if ( e. key === "Enter" ) submitTask ( d. id ) ;
if ( e. key === "Escape" ) {
setAddingTo ( null ) ;
setNewTask ( "" ) ;
setNewRepeat ( null ) ;
}
} }
placeholder = " Что сделать?"
aria-label = " Новая задача дня"
className = " h-10 flex-1 rounded-xl border border-line bg-canvas px-3 text-sm text-body placeholder:text-faint/60 focus:border-accent focus:outline-none"
/>
< button
onClick = { ( ) => submitTask ( d. id ) }
disabled = { ! newTask. trim ( ) }
aria-label = " Добавить задачу"
className = " flex h-10 w-10 items-center justify-center rounded-xl bg-accent text-white transition-all hover:brightness-110 active:scale-90 disabled:opacity-40"
>
< Check className = " h-4.5 w-4.5" />
</ button>
</ div>
{
&&
(
< RepeatChips
value = { newRepeat}
onChange = { setNewRepeat}
suffix = " → до конца цели"
/>
)
}
</ div>
)
:
(
< button
onClick = { ( ) => {
setAddingTo ( d. id ) ;
setNewTask ( "" ) ;
setNewRepeat ( null ) ;
} }
className = " mt-1.5 flex items-center gap-1.5 rounded-xl px-2 py-1.5 text-xs font-bold text-faint transition-all hover:text-accent active:scale-95"
>
< Plus className = " h-3.5 w-3.5" />
Задача
</ button>
)
}
</ section>
)
;
}
)
}
</ div>
</ div>
)
;
}
function
GoalDetail
(
{
,
,
,
}
:
{
:
Goal
;
onBack
:
(
)
=>
void
;
onOpenWeek
:
(
:
string
)
=>
void
;
}
)
{
const
{
}
=
useStore
(
)
;
const
[
,
]
=
useState
(
false
)
;
const
=
goalProgress
(
)
;
const
{
}
=
goalCounts
(
)
;
const
=
>
0
&&
===
1
;
if
(
.
horizon
!==
"month"
&&
.
weeks
[
0
]
)
{
return
(
< div>
< GoalHead goal = { goal} p = { p} complete = { complete} confirmDelete = { confirmDelete} setConfirmDelete = { setConfirmDelete} onDelete = { ( ) => { dispatch ( { type: "goal/delete" , id: goal. id } ) ; onBack ( ) ; } } crumbs = { [ "Цели" , goal. title ] } onBack = { onBack} />
< div className = " mt-4" >
< WeekDetail goal = { goal} week = { goal. weeks [ 0 ] } onBack = { onBack} />
</ div>
</ div>
)
;
}
return
(
< div className = " animate-rise" >
< GoalHead goal = { goal} p = { p} complete = { complete} confirmDelete = { confirmDelete} setConfirmDelete = { setConfirmDelete} onDelete = { ( ) => { dispatch ( { type: "goal/delete" , id: goal. id } ) ; onBack ( ) ; } } crumbs = { [ "Цели" , goal. title ] } onBack = { onBack} />
< h3 className = " mt-5 mb-2.5 text-sm font-bold text-body" >
Недели месяца
</ h3>
< ul className = " flex flex-col gap-2.5" >
{
.
weeks
.
map
(
(
)
=>
{
const
=
weekProgress
(
)
;
const
=
.
days
.
some
(
(
)
=>
.
tasks
.
length
>
0
)
;
return
(
< li key = { w. id } >
< button
onClick = { ( ) => onOpenWeek ( w. id ) }
className = " w-full rounded-2xl border border-line bg-card p-4 text-left transition-all duration-150 hover:border-accent/50 active:scale-[0.98] focus-visible:outline-2 focus-visible:outline-accent"
>
< div className = " flex items-center justify-between gap-3" >
< h4
className = { cn (
"text-sm font-bold text-body" ,
hasTasks && wp === 1 && "text-faint line-through"
) }
>
{
.
label
}
</ h4>
< span className = " num text-xs font-bold text-faint" >
{
?
pct
(
)
:
"—"
}
</ span>
</ div>
< ProgressBar value = { wp} className = " mt-2.5" />
</ button>
</ li>
)
;
}
)
}
</ ul>
</ div>
)
;
}
function
GoalHead
(
{
,
,
,
,
,
,
,
,
}
:
{
:
Goal
;
:
number
;
:
boolean
;
:
boolean
;
setConfirmDelete
:
(
:
boolean
)
=>
void
;
onDelete
:
(
)
=>
void
;
:
string
[
]
;
onBack
:
(
)
=>
void
;
}
)
{
const
{
}
=
useStore
(
)
;
return
(
< >
< DrillHeader crumbs = { crumbs} onBack = { onBack} />
< div className = " rounded-3xl border border-line bg-card p-5" >
< div className = " flex items-start justify-between gap-3" >
< p className = " text-[11px] font-bold uppercase tracking-wider text-faint" >
{
.
horizon
===
"month"
?
monthLabel
(
.
monthISO
)
:
HORIZON_LABEL
[
.
horizon
]
}
</ p>
< button
onClick = { ( ) => {
if ( ! confirmDelete) {
setConfirmDelete ( true ) ;
setTimeout ( ( ) => setConfirmDelete ( false ) , 2500 ) ;
return ;
}
onDelete ( ) ;
} }
aria-label = { confirmDelete ? "Подтвердить удаление цели" : "Удалить цель" }
className = { cn (
"flex h-8 items-center justify-center rounded-full transition-all active:scale-90" ,
confirmDelete
? "bg-danger px-3 text-[11px] font-bold text-white"
: "w-8 text-faint hover:bg-danger/10 hover:text-danger"
) }
>
{
?
"Точно?"
:
< Trash2 className = " h-4 w-4" />
}
</ button>
</ div>
< input
key = { goal. id }
defaultValue = { goal. title }
onBlur = { ( e) => {
const v = e. target . value . trim ( ) ;
if ( v && v !== goal. title )
dispatch ( { type: "goal/update" , id: goal. id , title: v, description: goal. description } ) ;
} }
onKeyDown = { ( e) => {
if ( e. key === "Enter" && ! e. nativeEvent . isComposing ) e. currentTarget . blur ( ) ;
} }
aria-label = " Название цели (редактируется)"
className = { cn (
"mt-1 w-full bg-transparent text-xl font-extrabold tracking-tight text-body transition-colors focus:outline-none focus:ring-2 focus:ring-accent/30 rounded-lg" ,
complete && "text-faint line-through"
) }
/>
< textarea
key = { ` ${ goal. id} -desc ` }
defaultValue = { goal. description }
placeholder = " Описание (по желанию)…"
rows = { 2 }
onBlur = { ( e) => {
const v = e. target . value . trim ( ) ;
if ( v !== goal. description )
dispatch ( { type: "goal/update" , id: goal. id , title: goal. title , description: v } ) ;
} }
aria-label = " Описание цели (редактируется)"
className = " mt-1.5 w-full resize-none bg-transparent text-sm leading-relaxed text-faint placeholder:text-faint/50 focus:outline-none focus:ring-2 focus:ring-accent/30 rounded-lg"
/>
< div className = " mt-4 flex items-center gap-3" >
< ProgressBar value = { p} size = " lg" className = " flex-1" />
< span className = " num text-sm font-bold text-accent-strong" >
{
pct
(
)
}
</ span>
</ div>
{
&&
(
< p className = " mt-3 flex items-center gap-2 rounded-xl bg-success/10 px-3 py-2 text-xs font-bold text-success animate-pop" >
< Check className = " h-3.5 w-3.5" strokeWidth = { 3 } />
Цель выполнена. Поздравляю, сэр.
</ p>
)
}
</ div>
</ >
)
;
}
export
function
GoalsScreen
(
)
{
const
{
}
=
useStore
(
)
;
const
[
,
]
=
useState < Drill>
(
{
:
"list"
}
)
;
const
=
.
level
!==
"list"
?
.
goals
.
find
(
(
)
=>
.
id
===
.
goalId
)
:
undefined
;
const
=
.
level
===
"week"
&&
?
.
weeks
.
find
(
(
)
=>
.
id
===
.
weekId
)
:
undefined
;
if
(
.
level
!==
"list"
&&
!
)
{
setDrill
(
{
:
"list"
}
)
;
return
null
;
}
return
(
< div className = " px-5 pt-4" >
{
.
level
===
"list"
&&
(
< GoalList onOpen = { ( goalId) => setDrill ( { level: "goal" , goalId } ) } />
)
}
{
.
level
===
"goal"
&&
&&
(
< GoalDetail
goal = { goal}
onBack = { ( ) => setDrill ( { level: "list" } ) }
onOpenWeek = { ( weekId) => setDrill ( { level: "week" , goalId: goal. id , weekId } ) }
/>
)
}
{
.
level
===
"week"
&&
&&
&&
(
< WeekDetail
goal = { goal}
week = { week}
crumbs = { [ "Цели" , goal. title , week. label ] }
onBack = { ( ) => setDrill ( { level: "goal" , goalId: goal. id } ) }
/>
)
}
</ div>
)
;
}