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
/** @jsxImportSource https://esm.sh/react */
import { Dispatch } from "https://esm.sh/react";
export default function Home(
dispatch: Dispatch<{
type: string;
value: string | {
date: string;
objectID: string;
};
}>,
pages: number[],
stories: { date: string; objectID }[],
comments: { author: string; comment_text: string; objectID: string }[],
) {
return (
<div class="flex flex-wrap w-full">
<div class="p-4 flex gap-5 w-full">
<>
Date
<select
name="date"
class="border border-gray-300"
onChange={(e) => dispatch({ type: "story", value: stories.find((story) => story.date == e.target.value) })}
>
{stories.map((story) => <option>story.date</option>)}
</select>
</>
<>
Page
<select
name="page"
class="border border-gray-300"
onChange={(e) => dispatch({ type: "page", value: e.target.value })}
>
{pages.map((page) => <option>{page}</option>)}
</select>
</>
<>
Search
<input
class="border border-gray-300"
onChange={(
e,
) => (dispatch({ type: "query", value: e.target.value }), dispatch({ type: "page", value: "1" }))}
>
</input>
</>
</div>
<div class=" mx-auto p-4 mt-10 flex flex-wrap justify-center gap-10 w-[1500px]">
{comments.map((comment) => (
<div>
<a href={`https://news.ycombinator.com/item?id=${comment.objectID}`} class="underline">
{comment.author}
</a>
<div
class="p-2 w-96 h-56 truncate text-wrap border border-gray"
dangerouslySetInnerHTML={{ __html: comment.comment_text }}
>
</div>
</div>
))}
</div>
</div>
);
}