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/preact */
import { getDocs } from "https://esm.town/v/stevekrouse/getSqliteDateMeDocs";
let linkClass = "text-sky-600 hover:text-sky-500";
let headers = [
"Name",
"Age",
"Gender",
"InterestedIn",
"Style",
"Location",
"LocationFlexibility",
"Community",
"Contact",
"LastUpdated",
];
function renderCell(header, row) {
let data = row[header];
if (header === "Name") {
return <a class={linkClass} href={row["Profile"]} target="_blank">{data}</a>;
} else if (Array.isArray(data)) {
return data.map(d => <span className="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 async function docs_table() {
const docs = await getDocs();
return (
<div class="overflow-auto">
<div id="filters" className="flex space-x-2 py-4">
Desired Gender:
<select id="desired-gender">
<option></option>
<option>M</option>
<option>F</option>
<option>NB</option>
</select>
Your Gender:
<select id="your-gender">
<option>M</option>
<option>F</option>
<option>NB</option>
</select>
<input
type="number"
id="min"
name="min"
placeholder="Min age"
className="border border-slate-400 rounded pl-1 h-min w-24"
/>
<input
type="number"
id="max"
name="max"
placeholder="Max age"
className="border border-slate-400 rounded pl-1 h-min w-24"
/>
<input
type="text"
id="search"
name="search"
placeholder="Search"
className="border border-slate-400 rounded pl-1 h-min w-28"
/>
</div>
<table id="docs">
<thead class="font-bold">{headers.map(h => <td>{h}</td>)}</thead>
<tbody>
{docs.map(d => (
<tr class="m-1 hover:bg-gray-100">
{headers.map(h => (
<td>
{renderCell(h, d)}
</td>
))}
</tr>
))}
</tbody>
</table>
</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!
January 11, 2024