Приложение для заметок, с целями и с ии чатом · VibeGit
Приложение для заметок, с целями и с ии чатом Это приложение для заметок с ии(свои ключи), есть поддерживание целей, их отслеживание по %
prilozhenie-dlya-zametok-s-tselyami-i-s-ii-chato / src / components / settings-sheet.tsx 133 строк · изменён 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
"use client" ;
import { ArchiveRestore , Eraser , Trash2 } from "lucide-react" ;
import { useStore } from "@/lib/store" ;
import { Segmented , Sheet } from "./ui" ;
const TRASH_DAYS = 30 ;
function daysLeft ( deletedAt: number ) : number {
return Math . max (
0 ,
Math . ceil ( deletedAt
id id id
open
onClose
theme
onTheme
open
theme
onTheme t
state dispatch
trashed state
n n
a b b a
seedCount
state n n
state g g
state e e
n state n n
type id n
e state e e
type id e
g state g g
type id g
trashed
trashed n
n n
seedCount
seedCount
(
+
TRASH_DAYS
*
24
*
3600
*
1000
-
Date
.
now
(
)
)
/
(
24
*
3600
*
1000
)
)
)
;
}
const
isSeedId
=
(
:
string
)
=>
/ ^ [ nge] -\d + $ /
.
test
(
)
||
===
"d-welcome"
;
export
function
SettingsSheet
(
{
,
,
,
,
}
:
{
:
boolean
;
onClose
:
(
)
=>
void
;
:
"system"
|
"light"
|
"dark"
;
:
(
:
"system"
|
"light"
|
"dark"
)
=>
void
;
}
)
{
const
{
,
}
=
useStore
(
)
;
const
=
.
notes
.
filter
(
(
)
=>
.
deletedAt
)
.
sort
(
(
,
)
=>
(
.
deletedAt
??
0
)
-
(
.
deletedAt
??
0
)
)
;
const
=
.
notes
.
filter
(
(
)
=>
isSeedId
(
.
id
)
)
.
length
+
.
goals
.
filter
(
(
)
=>
isSeedId
(
.
id
)
)
.
length
+
.
events
.
filter
(
(
)
=>
isSeedId
(
.
id
)
)
.
length
;
const
purgeSeed
=
(
)
=>
{
for
(
const
of
.
notes
.
filter
(
(
)
=>
isSeedId
(
.
id
)
)
)
dispatch
(
{
:
"note/purge"
,
:
.
id
}
)
;
for
(
const
of
.
events
.
filter
(
(
)
=>
isSeedId
(
.
id
)
)
)
dispatch
(
{
:
"event/delete"
,
:
.
id
}
)
;
for
(
const
of
.
goals
.
filter
(
(
)
=>
isSeedId
(
.
id
)
)
)
dispatch
(
{
:
"goal/delete"
,
:
.
id
}
)
;
}
;
return
(
< Sheet open = { open} onClose = { onClose} title = " Настройки" >
< div className = " flex flex-col gap-6" >
< section>
< h3 className = " mb-2 text-xs font-bold uppercase tracking-wider text-faint" >
Внешний вид
</ h3>
< Segmented
ariaLabel = " Тема оформления"
options = { [
{ value: "system" as const , label: "Системная" } ,
{ value: "light" as const , label: "Светлая" } ,
{ value: "dark" as const , label: "Тёмная" } ,
] }
value = { theme}
onChange = { onTheme}
/>
</ section>
< section>
< h3 className = " mb-1 text-xs font-bold uppercase tracking-wider text-faint" >
Недавно удалённые
</ h3>
<p className="mb-3 text-xs leading-relaxed text-faint">
Заметки из корзины стираются навсегда через
{
TRASH_DAYS
}
дней.
</ p>
{
.
length
===
0
?
(
< p className = " rounded-2xl border border-dashed border-line p-4 text-sm text-faint" >
Корзина пуста — удалённые заметки будут ждать здесь.
</ p>
)
:
(
< ul className = " flex flex-col gap-2" >
{
.
map
(
(
)
=>
(
< li
key = { n. id }
className = " flex items-center gap-3 rounded-2xl border border-line bg-card p-3.5"
>
< div className = " min-w-0 flex-1" >
< p className = " truncate text-sm font-semibold text-body" >
{
.
title
||
"Без названия"
}
</ p>
< p className = " num text-[11px] text-faint" >
удалится через
{
daysLeft
(
.
deletedAt
!
)
}
дн.
</ p>
</ div>
< button
onClick = { ( ) => dispatch ( { type: "note/restore" , id: n. id } ) }
aria-label = { ` Восстановить « ${ n. title} » ` }
className = " flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-accent-soft text-accent-strong transition-all hover:brightness-95 active:scale-90"
>
< ArchiveRestore className = " h-4 w-4" />
</ button>
< button
onClick = { ( ) => dispatch ( { type: "note/purge" , id: n. id } ) }
aria-label = { ` Удалить « ${ n. title} » навсегда ` }
className = " flex h-9 w-9 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>
</ li>
)
)
}
</ ul>
)
}
</ section>
{
>
0
&&
(
< section>
< h3 className = " mb-1 text-xs font-bold uppercase tracking-wider text-faint" >
Демо-данные
</ h3>
< p className = " mb-3 text-xs leading-relaxed text-faint" >
Примеры из первого запуска (заметки, цели, события). Ваши записи не тронет.
</ p>
< button
onClick = { purgeSeed}
className = " flex w-full items-center justify-center gap-2 rounded-2xl border border-line bg-card py-3 text-sm font-bold text-body transition-all hover:border-danger hover:text-danger active:scale-[0.98]"
>
< Eraser className = " h-4 w-4" />
Убрать примеры (
{
}
)
</ button>
</ section>
)
}
</ div>
</ Sheet >
)
;
}