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
/** @jsxImportSource https://esm.sh/react */
import Layout from "https://esm.town/v/pomdtr/dateme_layout";
import { Action, handler } from "https://esm.town/v/pomdtr/ssr";
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
import { zip } from "npm:lodash-es";
export const action: Action = async (req: Request, ctx) => {
const url = new URL(req.url);
const search = url.searchParams;
let { columns, rows } = await sqlite.execute({
sql: `select * from dateme
where
Location like ?
and Gender like ?
and InterestedIn like ?
`,
args: [
"%" + (search.get("location") ?? "") + "%",
"%" + (search.get("desired-gender") ?? "") + "%",
"%" + (search.get("gender") ?? "") + "%",
],
});
const profiles = rows.map(row =>
Object.fromEntries(zip(
columns,
row.map(d => {
try {
return JSON.parse(d);
} catch (_) {
return d;
}
}),
))
);
// TODO: handle form here
return ctx.render({
search: {
gender: search.get("gender"),
desiredGender: search.get("desired-gender"),
minAge: search.get("min-age"),
maxAge: search.get("max-age"),
location: search.get("location"),
},
profiles,
});
};
export function Browse({ route, search, profiles }: any) {
return (
<Layout activeTab={route}>
<div className="max-w-lg mx-auto p-10">
<div>
You are <b>{search.gender ?? "any gender"}</b>{" "}looking for <b>{search.desiredGender ?? "any gender"}</b>
{" "}bewteen the ages of <b>{search.minAge ?? "any"}</b>{" "}and{" "}<b>{search.maxAge ?? "any"}</b> in
{" "}
<b>{search.location ?? "any"}</b>. There are{" "}<b>{profiles.length}</b> profiles for you.
</div>
<div>
<a
href="/home"
className="text-blue-500 hover:text-blue-600"
>
Redo Search
</a>
</div>
<div>
<a href="/browse" className="text-blue-500 hover:text-blue-600">Clear filters</a>
</div>
<div>
{profiles.map(profile => (
<a href={profile["Profile"]}>
<div className="p-4 m-4 border shadow">
<h2>{profile["Name"]}</h2>
<div>{profile["Age"]}</div>
</div>
</a>
))}
</div>
</div>
</Layout>
);
}
export default handler(Browse, action);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v25
February 27, 2024