Приложение для заметок, с целями и с ии чатом · VibeGit
Приложение для заметок, с целями и с ии чатом Это приложение для заметок с ии(свои ключи), есть поддерживание целей, их отслеживание по %
prilozhenie-dlya-zametok-s-tselyami-i-s-ii-chato / src / components / app-shell.tsx 170 строк · изменён 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
"use client" ;
import { useEffect, useState } from "react" ;
import { Moon , Settings , Sun } from "lucide-react" ;
import { AppProvider , useStore } from "@/lib/store" ;
import type { TabId } from "@/lib/types" ;
import { handleBack } from "@/lib/overlay-stack" ;
import { cn } from "@/lib/utils" ;
import { BottomNav
title subtitle
notes title subtitle
calendar title subtitle
goals title subtitle
ai title subtitle
mode
dark
mode
mode
dark
mode
mode
tab tab
title subtitle tab
mode setMode
settingsOpen setSettingsOpen
saved
saved saved saved
isDark
next isDark
next
next
title subtitle mode
tab setTab
hydrated
cleanup
sub
sub
cleanup
hydrated
tab tab tab tab
}
from
"./bottom-nav"
;
import
{ SettingsSheet }
from
"./settings-sheet"
;
import
{ NotesScreen }
from
"./screens/notes"
;
import
{ CalendarScreen }
from
"./screens/calendar"
;
import
{ GoalsScreen }
from
"./screens/goals"
;
import
{ AiScreen }
from
"./screens/ai-chat"
;
const
TITLES
:
Record
<
TabId
,
{
:
string
;
:
string
}
>
=
{
:
{
:
"Заметки"
,
:
"Текст, списки и markdown"
}
,
:
{
:
"Календарь"
,
:
"События и дедлайны"
}
,
:
{
:
"Цели"
,
:
"Месяц → неделя → день"
}
,
:
{
:
"Ассистент"
,
:
"Знает ваши заметки и планы"
}
,
}
;
type
ThemeMode
=
"system"
|
"light"
|
"dark"
;
function
applyTheme
(
:
ThemeMode
)
{
const
=
===
"dark"
||
(
===
"system"
&&
window
.
matchMedia
(
"(prefers-color-scheme: dark)"
)
.
matches
)
;
document
.
documentElement
.
classList
.
toggle
(
"dark"
,
)
;
try
{
if
(
===
"system"
)
localStorage
.
removeItem
(
"margin:theme"
)
;
else
localStorage
.
setItem
(
"margin:theme"
,
)
;
}
catch
{
}
}
function
Header
(
{
}
:
{
:
TabId
}
)
{
const
{
,
}
=
TITLES
[
]
;
const
[
,
]
=
useState < ThemeMode>
(
"system"
)
;
const
[
,
]
=
useState
(
false
)
;
useEffect
(
(
)
=>
{
try
{
const
=
localStorage
.
getItem
(
"margin:theme"
)
;
setMode
(
===
"light"
||
===
"dark"
?
:
"system"
)
;
}
catch
{
setMode
(
"system"
)
;
}
}
,
[
]
)
;
const
quickToggle
=
(
)
=>
{
const
=
document
.
documentElement
.
classList
.
contains
(
"dark"
)
;
const
:
ThemeMode
=
?
"light"
:
"dark"
;
setMode
(
)
;
applyTheme
(
)
;
}
;
return
(
< >
< header className = " sticky top-0 z-30 shrink-0 border-b border-line/60 bg-canvas/80 backdrop-blur-xl" >
< div className = " flex items-center justify-between gap-3 px-5 py-3.5" >
< div key = { tab} className = " animate-rise" >
< h1 className = " text-xl font-extrabold tracking-tight text-body" >
{
}
</ h1>
< p className = " text-xs font-medium text-faint" >
{
}
</ p>
</ div>
< div className = " flex items-center gap-2.5" >
< button
onClick = { quickToggle}
aria-label = { mode === "dark" ? "Включить светлую тему" : "Включить тёмную тему" }
className = " flex h-10 w-10 items-center justify-center rounded-full border border-line bg-card text-faint transition-all duration-200 hover:text-body active:scale-90"
>
{
===
"dark"
?
(
< Sun className = " h-4.5 w-4.5" />
)
:
(
< Moon className = " h-4.5 w-4.5" />
)
}
</ button>
< button
onClick = { ( ) => setSettingsOpen ( true ) }
aria-label = " Настройки"
className = " flex h-10 w-10 items-center justify-center rounded-full border border-line bg-card text-faint transition-all duration-200 hover:text-body active:scale-90"
>
< Settings className = " h-4.5 w-4.5" />
</ button>
</ div>
</ div>
</ header>
< SettingsSheet
open = { settingsOpen}
onClose = { ( ) => setSettingsOpen ( false ) }
theme = { mode}
onTheme = { ( t) => {
setMode ( t) ;
applyTheme ( t) ;
} }
/>
</ >
)
;
}
function
Splash
(
)
{
return
(
< div className = " flex min-h-dvh items-center justify-center bg-canvas" >
< div className = " flex flex-col items-center gap-3 animate-pop" >
< div className = " flex h-14 w-14 items-center justify-center rounded-2xl bg-accent shadow-lg" >
< span className = " text-2xl font-extrabold text-white" >
M
</ span>
</ div>
< p className = " text-sm font-bold tracking-wide text-faint" >
Margin
</ p>
</ div>
</ div>
)
;
}
function
Shell
(
)
{
const
[
,
]
=
useState < TabId>
(
"notes"
)
;
const
{
}
=
useStore
(
)
;
useEffect
(
(
)
=>
{
let
:
(
(
)
=>
void
)
|
undefined
;
void
(
async
(
)
=>
{
try
{
const
{
App
}
=
await
import
(
"@capacitor/app"
)
;
const
=
await
App
.
addListener
(
"backButton"
,
(
)
=>
{
if
(
!
handleBack
(
)
)
void
App
.
exitApp
(
)
;
}
)
;
cleanup
=
(
)
=>
void
.
remove
(
)
;
}
catch
{
}
}
)
(
)
;
return
(
)
=>
?.
(
)
;
}
,
[
]
)
;
if
(
!
)
return
< Splash />
;
return
(
< div className = " mx-auto flex h-dvh w-full max-w-md flex-col overflow-hidden bg-canvas shadow-[0_0_60px_-20px_rgba(0,0,0,0.25)] sm:border-x sm:border-line" >
< Header tab = { tab} />
{
}
< main
className = { cn (
"min-h-0 flex-1" ,
tab === "ai" ? "flex flex-col overflow-hidden" : "overflow-y-auto pb-6"
) }
>
< div
key = { tab}
className = { cn ( "animate-fade" , tab === "ai" && "flex min-h-0 flex-1 flex-col" ) }
>
{
===
"notes"
&&
< NotesScreen />
}
{
===
"calendar"
&&
< CalendarScreen />
}
{
===
"goals"
&&
< GoalsScreen />
}
{
===
"ai"
&&
< AiScreen />
}
</ div>
</ main>
< BottomNav tab = { tab} onChange = { setTab} />
</ div>
)
;
}
export
function
AppShell
(
)
{
return
(
< AppProvider >
< Shell />
</ AppProvider >
)
;
}