Приложение для заметок, с целями и с ии чатом · VibeGit
Приложение для заметок, с целями и с ии чатом Это приложение для заметок с ии(свои ключи), есть поддерживание целей, их отслеживание по %
prilozhenie-dlya-zametok-s-tselyami-i-s-ii-chato / src / components / screens / calendar.tsx 429 строк · изменён 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
"use client" ;
import { useMemo, useState } from "react" ;
import {
CalendarPlus ,
ChevronLeft ,
ChevronRight ,
Clock ,
Flag ,
Trash2 ,
} from "lucide-react" ;
import { useStore } from "@/lib/store" ;
import type { CalEvent , EventKind } from "@/lib/types" ;
import {
addDays,
cap1,
cn,
fmtDayFull,
fmtDayMon,
fmtDayNum,
fmtDayShort,
fmtMonthShort
fmtMonthYear
isSameDay
startOfWeek
toISODate
uid
label dot
task label dot
deadline label dot
event label dot
date
open
onClose
date
open
dispatch
title setTitle
time setTime
kind setKind
t title
t
event
id
date date
title t
time time
kind
done
type event
date k
k
e e
dispatch
e e e e e
state
view setView
cursor setCursor
selected setSelected
sheetOpen setSheetOpen
today
weekDays
start cursor
length _ i start i
cursor
monthGrid
first cursor cursor
start first
length _ i start i
cursor
byDate
map
e state
list map e
list e
map e list
list map
list a b a b
map
state
dir
c
view
c dir
c c dir
agendaDays view weekDays selected
agendaHasEvents agendaDays
d byDate d
d
isSel d selected
isToday d today
events byDate d
d d events e
d inMonth
isSel d selected
isToday d today
events byDate d
d events e
e
events
events
view
cursor view
weekDays weekCell
monthGrid d d d cursor
view
selected today
selected agendaHasEvents
agendaDays d
events byDate d
events
isSel d selected
d d today
isSel view
events e
,
,
,
,
,
,
}
from
"@/lib/utils"
;
import
{ Checkbox , EmptyState , Segmented , Sheet }
from
"../ui"
;
const
KIND_STYLE
:
Record
<
EventKind
,
{
:
string
;
:
string
}
>
=
{
:
{
:
"Задача"
,
:
"bg-accent"
}
,
:
{
:
"Дедлайн"
,
:
"bg-danger"
}
,
:
{
:
"Событие"
,
:
"bg-success"
}
,
}
;
function
EventSheet
(
{
,
,
,
}
:
{
:
Date
;
:
boolean
;
onClose
:
(
)
=>
void
;
}
)
{
const
{
}
=
useStore
(
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState
(
""
)
;
const
[
,
]
=
useState < EventKind>
(
"event"
)
;
const
submit
=
(
)
=>
{
const
=
.
trim
(
)
;
if
(
!
)
return
;
const
:
CalEvent
=
{
:
uid
(
"e"
)
,
:
toISODate
(
)
,
:
,
:
||
undefined
,
,
:
false
,
}
;
dispatch
(
{
:
"event/add"
,
}
)
;
setTitle
(
""
)
;
setTime
(
""
)
;
setKind
(
"event"
)
;
onClose
(
)
;
}
;
return
(
< Sheet open = { open} onClose = { onClose} title = " Новое событие" >
< div className = " flex flex-col gap-4" >
< p className = " text-sm font-medium text-faint" >
{
cap1
(
fmtDayFull
(
)
)
}
</ p>
< 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"
/>
< div className = " flex gap-2" >
{
(
Object
.
keys
(
KIND_STYLE
)
as
EventKind
[
]
)
.
map
(
(
)
=>
(
< button
key = { k}
onClick = { ( ) => setKind ( k) }
aria-pressed = { kind === k}
className = { cn (
"flex flex-1 items-center justify-center gap-1.5 rounded-xl border px-2 py-2.5 text-xs font-bold transition-all active:scale-95" ,
kind === k
? "border-accent bg-accent-soft text-accent-strong"
: "border-line text-faint hover:text-body"
) }
>
< span className = { cn ( "h-2 w-2 rounded-full" , KIND_STYLE [ k] . dot ) } />
{
KIND_STYLE
[
]
.
label
}
</ button>
)
)
}
</ div>
< label className = " flex items-center gap-3 rounded-2xl border border-line bg-card px-4" >
< Clock className = " h-4 w-4 shrink-0 text-faint" />
< input
type = " time"
value = { time}
onChange = { ( e) => setTime ( e. target . value ) }
aria-label = " Время (необязательно)"
className = " h-12 w-full bg-transparent text-[15px] text-body focus:outline-none"
/>
</ label>
< button
onClick = { submit}
disabled = { ! title. 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
EventRow
(
{
}
:
{
:
CalEvent
}
)
{
const
{
}
=
useStore
(
)
;
return
(
< div
className = { cn (
"flex items-center gap-3 rounded-2xl border border-line bg-card p-3.5 transition-opacity" ,
e. done && "opacity-55"
) }
>
< Checkbox
checked = { e. done }
onChange = { ( ) => dispatch ( { type: "event/toggle" , id: e. id } ) }
label = { e. title }
/>
< div className = " min-w-0 flex-1" >
< p
className = { cn (
"truncate text-sm font-semibold text-body" ,
e. done && "line-through"
) }
>
{
.
title
}
</ p>
< p className = " mt-0.5 flex items-center gap-1.5 text-xs text-faint" >
< span className = { cn ( "h-1.5 w-1.5 rounded-full" , KIND_STYLE [ e. kind ] . dot ) } />
{
.
kind
===
"deadline"
&&
< Flag className = " h-3 w-3" />
}
{
KIND_STYLE
[
.
kind
]
.
label
}
{
.
time
&&
< span className = " num" >
·
{
.
time
}
</ span>
}
</ p>
</ div>
< button
onClick = { ( ) => dispatch ( { type: "event/delete" , id: e. id } ) }
aria-label = { ` Удалить « ${ e. title} » ` }
className = " flex h-8 w-8 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-4 w-4" />
</ button>
</ div>
)
;
}
export
function
CalendarScreen
(
)
{
const
{
}
=
useStore
(
)
;
const
[
,
]
=
useState < "week" | "month" >
(
"week"
)
;
const
[
,
]
=
useState
(
(
)
=>
new
Date
(
)
)
;
const
[
,
]
=
useState
(
(
)
=>
new
Date
(
)
)
;
const
[
,
]
=
useState
(
false
)
;
const
=
new
Date
(
)
;
const
=
useMemo
(
(
)
=>
{
const
=
startOfWeek
(
)
;
return
Array
.
from
(
{
:
7
}
,
(
,
)
=>
addDays
(
,
)
)
;
}
,
[
]
)
;
const
=
useMemo
(
(
)
=>
{
const
=
new
Date
(
.
getFullYear
(
)
,
.
getMonth
(
)
,
1
)
;
const
=
startOfWeek
(
)
;
return
Array
.
from
(
{
:
42
}
,
(
,
)
=>
addDays
(
,
)
)
;
}
,
[
]
)
;
const
=
useMemo
(
(
)
=>
{
const
=
new
Map< string , CalEvent[ ] >
(
)
;
for
(
const
of
.
events
)
{
const
=
.
get
(
.
date
)
??
[
]
;
.
push
(
)
;
.
set
(
.
date
,
)
;
}
for
(
const
of
.
values
(
)
)
.
sort
(
(
,
)
=>
(
.
time
??
"99"
)
.
localeCompare
(
.
time
??
"99"
)
)
;
return
;
}
,
[
.
events
]
)
;
const
shift
=
(
:
-
1
|
1
)
=>
setCursor
(
(
)
=>
===
"week"
?
addDays
(
,
*
7
)
:
new
Date
(
.
getFullYear
(
)
,
.
getMonth
(
)
+
,
1
)
)
;
const
=
===
"week"
?
:
[
]
;
const
=
.
some
(
(
)
=>
(
.
get
(
toISODate
(
)
)
??
[
]
)
.
length
>
0
)
;
const
weekCell
=
(
:
Date
)
=>
{
const
=
isSameDay
(
,
)
;
const
=
isSameDay
(
,
)
;
const
=
.
get
(
toISODate
(
)
)
??
[
]
;
return
(
< button
key = { d. toISOString ( ) }
onClick = { ( ) => setSelected ( d) }
aria-label = { fmtDayFull ( d) }
aria-pressed = { isSel}
className = { cn (
"flex flex-col items-center gap-1 rounded-2xl py-2 transition-all duration-150 active:scale-95" ,
"focus-visible:outline-2 focus-visible:outline-accent" ,
isSel ? "bg-accent text-white shadow-md shadow-accent/25" : "hover:bg-card-2"
) }
>
< span
className = { cn (
"text-[10px] font-bold uppercase tracking-wide" ,
isSel ? "text-white/80" : "text-faint"
) }
>
{
fmtDayShort
(
)
}
</ span>
< span
className = { cn (
"num flex h-8 w-8 items-center justify-center rounded-full text-sm font-bold" ,
isSel
? "bg-white/20"
: isToday
? "border-2 border-accent text-accent"
: "text-body"
) }
>
{
fmtDayNum
(
)
}
</ span>
< span className = " flex h-1.5 gap-0.5" >
{
.
slice
(
0
,
3
)
.
map
(
(
)
=>
(
< span
key = { e. id }
className = { cn (
"h-1.5 w-1.5 rounded-full" ,
isSel ? "bg-white/90" : KIND_STYLE [ e. kind ] . dot
) }
/>
)
)
}
</ span>
</ button>
)
;
}
;
const
monthCell
=
(
:
Date
,
:
boolean
)
=>
{
const
=
isSameDay
(
,
)
;
const
=
isSameDay
(
,
)
;
const
=
.
get
(
toISODate
(
)
)
??
[
]
;
return
(
< button
key = { d. toISOString ( ) }
onClick = { ( ) => setSelected ( d) }
aria-label = { ` ${ fmtDayFull ( d) } , событий: ${ events. length} ` }
aria-pressed = { isSel}
className = { cn (
"flex min-h-16 flex-col items-stretch gap-0.5 rounded-xl p-1 transition-all duration-150 active:scale-95" ,
"focus-visible:outline-2 focus-visible:outline-accent" ,
! inMonth && "opacity-35" ,
isSel ? "bg-accent-soft ring-1 ring-accent" : "hover:bg-card-2"
) }
>
< span
className = { cn (
"num flex h-6 w-6 items-center justify-center self-start rounded-full text-xs font-bold" ,
isToday ? "bg-accent text-white" : "text-body"
) }
>
{
fmtDayNum
(
)
}
</ span>
{
.
slice
(
0
,
2
)
.
map
(
(
)
=>
(
< span
key = { e. id }
className = { cn (
"flex items-center gap-1 truncate rounded px-1 py-px text-left text-[9px] font-semibold leading-tight text-body" ,
e. done && "opacity-50 line-through"
) }
>
< span className = { cn ( "h-1 w-1 shrink-0 rounded-full" , KIND_STYLE [ e. kind ] . dot ) } />
< span className = " truncate" >
{
.
title
}
</ span>
</ span>
)
)
}
{
.
length
>
2
&&
(
< span className = " num px-1 text-left text-[9px] font-bold text-faint" >
+
{
.
length
-
2
}
</ span>
)
}
</ button>
)
;
}
;
return
(
< div className = " px-5 pt-4" >
< div className = " flex items-center justify-between gap-3" >
< Segmented
ariaLabel = " Вид календаря"
options = { [
{ value: "week" as const , label: "Неделя" } ,
{ value: "month" as const , label: "Месяц" } ,
] }
value = { view}
onChange = { setView}
/>
< div className = " flex items-center gap-1" >
< button
onClick = { ( ) => shift ( - 1 ) }
aria-label = { view === "week" ? "Предыдущая неделя" : "Предыдущий месяц" }
className = " flex h-9 w-9 items-center justify-center rounded-full text-faint transition-all hover:bg-card-2 hover:text-body active:scale-90"
>
< ChevronLeft className = " h-4.5 w-4.5" />
</ button>
< button
onClick = { ( ) => shift ( 1 ) }
aria-label = { view === "week" ? "Следующая неделя" : "Следующий месяц" }
className = " flex h-9 w-9 items-center justify-center rounded-full text-faint transition-all hover:bg-card-2 hover:text-body active:scale-90"
>
< ChevronRight className = " h-4.5 w-4.5" />
</ button>
</ div>
</ div>
< p className = " mt-3 text-sm font-bold text-body" >
{
===
"week"
?
cap1
(
` ${ fmtDayNum ( weekDays[ 0 ] ) } ${ fmtMonthShort ( weekDays[ 0 ] ) } — ${ fmtDayNum ( weekDays[ 6 ] ) } ${ fmtMonthShort ( weekDays[ 6 ] ) } `
)
:
cap1
(
fmtMonthYear
(
)
)
}
</ p>
< div className = " mt-2 rounded-3xl border border-line bg-card p-2" >
{
===
"week"
?
(
< div className = " grid grid-cols-7 gap-0.5" >
{
.
map
(
)
}
</ div>
)
:
(
< div className = " grid grid-cols-7 gap-0.5" >
{
.
map
(
(
)
=>
monthCell
(
,
.
getMonth
(
)
===
.
getMonth
(
)
)
)
}
</ div>
)
}
</ div>
< div className = " mt-5 flex items-center justify-between" >
< h2 className = " text-sm font-bold text-body" >
{
===
"week"
?
"Дела недели"
:
isSameDay
(
,
)
?
"Сегодня"
:
cap1
(
fmtDayFull
(
)
)
}
</ h2>
< button
onClick = { ( ) => setSheetOpen ( true ) }
className = " flex items-center gap-1.5 rounded-full bg-accent-soft px-3 py-1.5 text-xs font-bold text-accent-strong transition-all hover:brightness-95 active:scale-95"
>
< CalendarPlus className = " h-3.5 w-3.5" />
Событие
</ button>
</ div>
{
!
?
(
< EmptyState
image = " empty-calendar"
title = { view === "week" ? "Неделя свободна" : "День свободен" }
hint = " Ни событий, ни дедлайнов. Хороший день, чтобы сверстать план — или выдохнуть."
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"
>
< CalendarPlus className = " h-4 w-4" /> Запланировать
</ button>
}
/>
)
:
(
< div className = " mt-3 flex flex-col gap-4" >
{
.
map
(
(
)
=>
{
const
=
.
get
(
toISODate
(
)
)
??
[
]
;
if
(
.
length
===
0
)
return
null
;
const
=
isSameDay
(
,
)
;
return
(
< section key = { d. toISOString ( ) } className = " animate-rise" >
< h3
className = { cn (
"mb-2 flex items-baseline gap-2 text-xs font-bold" ,
isSel ? "text-accent-strong" : "text-faint"
) }
>
{
cap1
(
fmtDayMon
(
)
)
}
{
isSameDay
(
,
)
&&
(
< span className = " rounded-full bg-accent-soft px-1.5 py-px text-[10px] text-accent-strong" >
сегодня
</ span>
)
}
{
&&
===
"week"
&&
(
< span className = " text-[10px] font-semibold" >
· выбрано
</ span>
)
}
</ h3>
< ul className = " flex flex-col gap-2" >
{
.
map
(
(
)
=>
(
< li key = { e. id } >
< EventRow e = { e} />
</ li>
)
)
}
</ ul>
</ section>
)
;
}
)
}
</ div>
)
}
< EventSheet date = { selected} open = { sheetOpen} onClose = { ( ) => setSheetOpen ( false ) } />
</ div>
)
;
}