Public
Script
Forked from pomdtr/dateme_browse
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
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource npm:hono@3/jsx */
import { sqlite } from "https://esm.town/v/std/sqlite";
import Layout from "https://esm.town/v/stevekrouse/dateme_layout";
import { zip } from "npm:lodash-es";
function absoluteURL(url) {
if (url.startsWith("http://") || url.startsWith("https://"))
return url;
else return "https://" + url;
}
let headers = [
"Name",
"Age",
"Gender",
"InterestedIn",
"Style",
"Location",
"LocationFlexibility",
"Contact",
"LastUpdated",
];
let linkClass = "text-sky-600 hover:text-sky-500";
function httpsIfy(url: string) {
if (!url.startsWith("http://") && !url.startsWith("https://")) {
return `https://${url}`;
}
return url;
}
function renderCell(header, row) {
let data = row[header];
if (header === "Name") {
return <a class={linkClass} href={httpsIfy(row["Profile"])} target="_blank">{data}</a>;
} else if (Array.isArray(data)) {
return data.map(d => <span class="p-1 m-1 border rounded-md">{d}</span>);
} else if (header === "LastUpdated") {
return new Date(data).toISOString().split("T")[0];
}
else {
return data;
}
}
export default async function Browse(c) {
const url = new URL(c.req.url);
const search = {
gender: url.searchParams.get("gender"),
desiredGender: url.searchParams.get("desired-gender"),
minAge: url.searchParams.get("min-age")?.length ? url.searchParams.get("min-age") : 0,
maxAge: url.searchParams.get("max-age")?.length ? url.searchParams.get("max-age") : 100,
location: url.searchParams.get("location"),
};
let { columns, rows } = await sqlite.execute({
sql: `select * from datemedocs
where
Location like ?
and Age >= ?
and Age <= ?
and Gender like ?
and InterestedIn like ?
order by LastUpdated desc
`,
args: [
"%" + (search.location ?? "") + "%",
search.minAge,
search.maxAge,
"%" + (search.desiredGender ?? "") + "%",
"%" + (search.gender ?? "") + "%",
],
});
const profiles = rows.map(row =>
Object.fromEntries(zip(
columns,
row.map(d => {
try {
return JSON.parse(d);
} catch (_) {
return d;
}
}),
))
);
return c.html(
<Layout activeTab={new URL(c.req.url).pathname}>
<div class="max-w-md mx-auto p-10">
<div>
You are <b>{search.gender?.length ? search.gender : "any gender"}</b>{" "}looking for{" "}
<b>{search.desiredGender?.length ? search.desiredGender : "any gender"}</b>{" "}bewteen the ages of{" "}
<b>{search.minAge}</b>{" "}and{" "}<b>{search.maxAge}</b> in{" "}
<b>{search.location?.length ? search.location : "the world"}</b>. There are{" "}<b>{profiles.length}</b>{" "}
profiles for you.
</div>
<div>
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!
May 10, 2024