-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.tsx
59 lines (54 loc) · 1.88 KB
/
App.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
import { Box, Checkbox, Heading, Text, TextInput } from "@primer/react";
import { getYjsValue } from "@syncedstore/core";
import { useSyncedStore } from "@syncedstore/react";
import * as Y from "yjs";
import NostrStatusBar from "./NostrStatusBar";
import { globalStore } from "./store";
export default function App() {
const state = useSyncedStore(globalStore);
return (
<Box m={3} maxWidth={600} marginLeft={"auto"} marginRight={"auto"} p={3}>
{/* This is the top bar with Sign in button and Nostr status
It also takes care of hooking up the Y.Doc to Nostr.
*/}
<Heading sx={{ mb: 2 }}>Todo items:</Heading>
<NostrStatusBar doc={getYjsValue(state) as Y.Doc}>
<TextInput
block
placeholder="Enter a todo item and hit enter"
type="text"
name="todo"
sx={{ marginBottom: 2, marginTop: 2 }}
onKeyPress={(event: any) => {
if (event.key === "Enter" && event.target.value) {
const target = event.target as HTMLInputElement;
// Add a todo item using the text added in the textfield
state.todos.push({ completed: false, title: target.value });
target.value = "";
}
}}
/>
{state.todos.map((todo, i) => {
return (
<Box
as="form"
sx={{ display: "flex", alignItems: "center" }}
key={`cb-${i}`}>
<Checkbox
id={`cb-${i}`}
checked={todo.completed}
onChange={() => (todo.completed = !todo.completed)}
/>
<Text
as="label"
htmlFor={`cb-${i}`}
sx={{ fontSize: 3, marginLeft: 1 }}>
{todo.title}
</Text>
</Box>
);
})}
</NostrStatusBar>
</Box>
);
}