-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.tsx
220 lines (196 loc) · 6.97 KB
/
page.tsx
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
"use client";
import React, { useMemo, useState } from "react";
import Image from "next/image";
import { useDisclosure } from "@nextui-org/modal";
import { v4 as uuidv4 } from "uuid";
import { Store } from "tauri-plugin-store-api";
import Item from "@/components/item/item";
import Date, { getGreeting } from "@/components/date/date";
import ItemModal from "@/components/item_modal/modal";
import Settings from "@/components/settings/settings";
import { raleway } from "./fonts";
import { ItemInterface } from "@/interfaces/interfaces";
import { fetchItems, fetchSettings } from "@/helpers/fetchers";
export default function Home() {
const {
isOpen: isItemModalOpen,
onOpen: onItemModalOpen,
onOpenChange: onItemModalOpenChange,
} = useDisclosure();
const {
isOpen: isSettingsModalOpen,
onOpen: onSettingsModalOpen,
onOpenChange: onSettingsModalOpenChange,
} = useDisclosure();
const settingsStore: Store = useMemo(() => new Store(".settings.dat"), []);
const noteStore: Store = useMemo(() => new Store(".notes.dat"), []);
const taskStore: Store = useMemo(() => new Store(".tasks.dat"), []);
const [currentItem, setCurrentItem] = useState<ItemInterface>({
title: "",
subtitle: "",
notes: "",
key: "",
tags: [],
});
const [tasks, setTasks] = useState<ItemInterface[]>([]);
const [notes, setNotes] = useState<ItemInterface[]>([]);
const [username, setUsername] = useState<string>("");
const [background, setBackground] = useState<string>("");
const [itemType, setItemType] = useState("tasks");
React.useEffect(() => {
fetchSettings(settingsStore).then((settings) => {
if (background !== settings.background_path) {
setBackground(settings.background_path);
}
if (username !== settings.username) {
setUsername(settings.username);
}
});
fetchItems(taskStore).then((tasks) => setTasks(tasks));
fetchItems(noteStore).then((notes) => setNotes(notes));
setItemType("tasks");
}, [taskStore, noteStore, settingsStore, background, username]);
const handleItemClick = (type: string) => {
setCurrentItem({
title: "",
subtitle: "",
notes: "",
key: "",
tags: [],
});
setItemType(type);
onItemModalOpen();
};
return (
<div className="relative h-auto">
<Image
src={background}
className="h-auto object-cover object-center"
fill
alt="Background"
/>
{/* Outer Flexbox for the division into 25:75 */}
<div className="flex flex-row">
{/* Sidebar content goes here */}
<div className="left-0 top-0 hidden h-screen w-1/4 bg-white bg-opacity-20 backdrop-blur-md lg:block">
<div>
<div
className={`m-4 mt-8 text-left text-5xl font-normal text-white ${raleway.className}`}
>
<h2>{getGreeting()},</h2>
<input
className="bg-transparent text-4xl font-semibold placeholder-current outline-none"
placeholder="Type a username"
value={username}
onChange={async (e) => {
setUsername(e.target.value);
await settingsStore.set("username", e.target.value);
}}
/>
<Date />
</div>
</div>
<div className="absolute bottom-0 flex-1 p-4 ">
<button
onClick={() => onSettingsModalOpen()}
className="rounded-md bg-white bg-opacity-20 px-4 py-2 text-white backdrop-blur-md hover:bg-opacity-40"
>
Settings
</button>
</div>
</div>
<div className="flex-1">
<div className="sm:flex lg:pl-10 lg:pr-10">
<div className="h-screen p-8 text-left sm:w-1/2 ">
<div className="flex h-full flex-col overflow-auto rounded-lg bg-[#969696] bg-opacity-50 backdrop-blur-md">
<div className="m-6 mt-8">
<div
className={`flex justify-between text-4xl font-normal text-white ${raleway.className}`}
>
<h2 className={`text-5xl font-semibold lg:text-6xl`}>
Tasks
</h2>
<button onClick={() => handleItemClick("task")}>
<Image
priority
src="/plus.svg"
height={48}
width={48}
alt="Add a task"
/>
</button>
</div>
<Item
items={tasks}
setItems={setTasks}
store={taskStore}
settingsStore={settingsStore}
/>
</div>
</div>
</div>
<div className="h-screen p-8 text-left sm:w-1/2 ">
<div className="flex h-full flex-col overflow-auto rounded-lg bg-[#969696] bg-opacity-50 backdrop-blur-md">
<div className="m-6 mt-8">
<div
className={`flex justify-between text-4xl font-normal text-white ${raleway.className}`}
>
<h2 className={`text-5xl font-semibold lg:text-6xl `}>
Notes
</h2>
<button onClick={() => handleItemClick("note")}>
<Image
priority
src="/plus.svg"
height={48}
width={48}
alt="Add a note"
/>
</button>
</div>
<Item
items={notes}
setItems={setNotes}
store={noteStore}
settingsStore={settingsStore}
/>
</div>
</div>
</div>
</div>
</div>
</div>
<Settings
store={settingsStore}
isOpen={isSettingsModalOpen}
onOpenChange={onSettingsModalOpenChange}
setUsername={setUsername}
setBackground={setBackground}
onClose={async () => {
await settingsStore.save();
}}
/>
<ItemModal
isOpen={isItemModalOpen}
onOpenChange={onItemModalOpenChange}
item={currentItem}
itemSetter={setCurrentItem}
store={settingsStore}
onClose={async () => {
if (!currentItem.title) {
return;
}
currentItem.key = uuidv4();
if (itemType === "task") {
// Don't use .then() in a async function
await taskStore.set(currentItem.key, currentItem);
setTasks(await fetchItems(taskStore));
} else {
await noteStore.set(currentItem.key, currentItem);
setNotes(await fetchItems(noteStore));
}
}}
/>
</div>
);
}