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
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import { useEffect, useState } from "https://esm.sh/react@18.2.0";
async function getCurrentPosition(opts): Promise<GeolocationPosition> {
return new Promise((resolve, reject) => {
if (!navigator?.geolocation) {
return resolve(undefined);
} else {
navigator.geolocation.getCurrentPosition(resolve, reject, opts);
}
});
}
async function reverseGeocodeNominat(lat, lng) {
const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&zoom=13`;
const response = await fetch(url);
const json = await response.json();
return json;
}
export default function Home() {
const [locationName, setLocationName] = useState("");
useEffect(() => {
(async () => {
console.log("looking up location");
const location = await getCurrentPosition({ enableHighAccuracy: false });
console.log(location);
if (location) {
setLocationName(await reverseGeocodeNominat(location.coords.latitude, location.coords.longitude));
}
})();
}, []);
return (
<div className="max-w-lg mx-auto p-10">
<div className="mb-10">
<div className="text-4xl font-bold mb-4">
Date thoughtfully
</div>
<div className="text-lg ">
Date Me Docs are long-form, earnest dating profiles for romantic partners.
</div>
</div>
<form className="space-y-4" action="/browse">
<div className="flex text-xl space-x-2">
<div>I'm</div>
<select name="gender" className="border border-gray-300">
<option value="" className="text-gray-500">...</option>
<option value="m">male</option>
<option value="f">female</option>
<option value="nb">non-binary</option>
</select>
</div>
<div className="flex text-xl space-x-2">
<div>Looking for</div>
<select name="desired-gender" className="border border-gray-300">
<option value="">...</option>
<option value="m">male</option>
<option value="f">female</option>
<option value="nb">non-binary</option>
</select>
</div>
<div className="flex text-xl space-x-2">
<div>Between</div>
<input defaultValue={18} type="number" name="min-age" className="w-12 h-min border border-gray-300"></input>
<div>and</div>
<input defaultValue={70} type="number" name="max-age" className="w-12 border border-gray-300"></input>
<div>years old</div>
</div>
<div className="flex text-xl space-x-2">
<div>Within</div>
<input defaultValue={10} type="number" name="radius" className="w-12 border border-gray-300"></input>{" "}
<div>miles of</div>
<input
className="h-min border border-gray-300"
type="text"
name="location"
defaultValue={locationName.display_name}
>
</input>
</div>
<button className="border text-xl border-gray-300 px-4 py-2 bg-blue-500 text-white font-bold rounded">
Search
</button>
</form>
</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!
June 18, 2024