Skip to content

Commit f86bc76

Browse files
committed
add tinybase
1 parent 2cc1c84 commit f86bc76

File tree

5 files changed

+212
-37
lines changed

5 files changed

+212
-37
lines changed

apps/events/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"react": "^18.3.1",
2222
"react-dom": "^18.3.1",
2323
"tailwind-merge": "^2.5.2",
24-
"tailwindcss-animate": "^1.0.7"
24+
"tailwindcss-animate": "^1.0.7",
25+
"tinybase": "^5.3.0"
2526
},
2627
"devDependencies": {
2728
"@eslint/js": "^9.9.0",

apps/events/src/App.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}

apps/events/src/App.tsx

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,58 @@
11
import { hello } from "graph-framework";
2-
import { Page } from "./components/app-events-page";
2+
import { useEffect } from "react";
3+
import { createStore } from "tinybase";
4+
import { Provider, useCreateStore } from "tinybase/ui-react";
5+
import { Inspector } from "tinybase/ui-react-inspector";
6+
import { EventsPage } from "./components/events-page";
37

48
export function App() {
5-
return (
6-
<>
7-
<p>{hello()}</p>
9+
const store = useCreateStore(() => {
10+
// Create the TinyBase Store and initialize the Store's data
11+
return createStore()
12+
.setTable("spaces", {
13+
abc: { name: "GeoBrowser" },
14+
})
15+
.setTable("events", {
16+
"6ea749ab": {
17+
name: "Tech Conference 2023",
18+
date: "2023-09-15",
19+
location: "San Francisco, CA",
20+
description:
21+
"Join us for the biggest tech conference of the year, featuring keynote speakers from leading tech companies.",
22+
},
23+
ef9ae3d7: {
24+
name: "Music Festival",
25+
date: "2023-10-01",
26+
location: "Austin, TX",
27+
description:
28+
"A three-day music extravaganza featuring top artists from around the world.",
29+
},
30+
"607f12a6": {
31+
name: "Food & Wine Expo",
32+
date: "2023-11-05",
33+
location: "New York, NY",
34+
description:
35+
"Explore culinary delights and fine wines from renowned chefs and vintners.",
36+
},
37+
});
38+
});
39+
40+
useEffect(() => {
41+
const listenerId = store.addTablesListener((a, b) =>
42+
console.log("Tables changed!", a, b)
43+
);
44+
return () => {
45+
store.delListener(listenerId);
46+
};
47+
}, []);
848

9-
<Page />
10-
</>
49+
return (
50+
<Provider store={store}>
51+
<>
52+
<p>{hello()}</p>
53+
<EventsPage />
54+
</>
55+
<Inspector />
56+
</Provider>
1157
);
1258
}

apps/events/src/components/app-events-page.tsx renamed to apps/events/src/components/events-page.tsx

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,17 @@ import {
99
CardHeader,
1010
CardTitle,
1111
} from "@/components/ui/card";
12+
import { useAddRowCallback, useTable } from "tinybase/ui-react";
1213

13-
export function Page() {
14-
const events = [
15-
{
16-
id: 1,
17-
name: "Tech Conference 2023",
18-
date: "2023-09-15",
19-
location: "San Francisco, CA",
20-
description:
21-
"Join us for the biggest tech conference of the year, featuring keynote speakers from leading tech companies.",
22-
},
23-
{
24-
id: 2,
25-
name: "Music Festival",
26-
date: "2023-10-01",
27-
location: "Austin, TX",
28-
description:
29-
"A three-day music extravaganza featuring top artists from around the world.",
30-
},
31-
{
32-
id: 3,
33-
name: "Food & Wine Expo",
34-
date: "2023-11-05",
35-
location: "New York, NY",
36-
description:
37-
"Explore culinary delights and fine wines from renowned chefs and vintners.",
38-
},
39-
];
14+
export function EventsPage() {
15+
const events = useTable("events");
16+
17+
const addEvent = useAddRowCallback("events", () => ({
18+
name: "New Event",
19+
date: "2023-12-31",
20+
location: "New York, NY",
21+
description: "A new event",
22+
}));
4023

4124
return (
4225
<div className="flex flex-col min-h-screen">
@@ -72,15 +55,25 @@ export function Page() {
7255
<h1 className="text-3xl font-bold tracking-tighter sm:text-4xl md:text-5xl lg:text-6xl/none mb-8">
7356
Upcoming Events
7457
</h1>
58+
<Button
59+
onClick={() => {
60+
addEvent();
61+
}}
62+
>
63+
Add Event
64+
</Button>
7565
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
76-
{events.map((event) => (
77-
<Card key={event.id}>
66+
{Object.entries(events).map(([id, event]) => (
67+
<Card key={id}>
7868
<CardHeader>
7969
<CardTitle>{event.name}</CardTitle>
8070
<CardDescription>
8171
<div className="flex items-center mt-2">
8272
<CalendarDays className="mr-2 h-4 w-4" />
83-
{new Date(event.date).toLocaleDateString()}
73+
{
74+
// @ts-expect-error tinybase types issue
75+
new Date(event.date).toLocaleDateString()
76+
}
8477
</div>
8578
<div className="flex items-center mt-2">
8679
<MapPin className="mr-2 h-4 w-4" />

pnpm-lock.yaml

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)