-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tsx
45 lines (38 loc) · 1.37 KB
/
main.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
import { Elysia } from "elysia";
import { staticPlugin } from "@elysiajs/static";
import { html } from "@elysiajs/html";
import { SORT_TYPE, YugaItem } from "./src/database/database";
import { get_data } from "./src/database/database";
import { BaseHTML } from "./src/components/BaseHTML";
import RoadmapItems from "./src/components/RoadmapItems";
const app = new Elysia()
.use(staticPlugin({ prefix: "/" }))
.use(html())
.get("/", () => <BaseHTML></BaseHTML>)
.get("/roadmap", () => roadmap_items_page())
.get("/roadmap/items/:sort", ({ params: {sort} }) => roadmap_items_page(sort))
.listen(3000);
console.log(`🦊 listening on ${app.server?.hostname}: ${app.server?.port}`);
function roadmap_items_page(sort_param?: string): Promise<JSX.Element> {
let sort = SORT_TYPE.by_category;
if (sort_param && Object.values(SORT_TYPE).includes(sort_param)) {
sort = SORT_TYPE[sort_param as keyof typeof SORT_TYPE]
}
console.log(sort_param, sort);
return get_data(sort).then(
(items) => roadmap_items_html(items),
(reason) => {
return `Could not retrieve items from database. Reason: ${reason}`;
},
);
}
// function get_sorted_items(sort: SORT_TYPE): Promise<YugaItem[]> {
// return get_data(sort);
// }
function roadmap_items_html(all_items: YugaItem[]): JSX.Element {
return (
<RoadmapItems
all_items={all_items}
></RoadmapItems>
);
}