ChrQR
7b97a0eb65
Need to fix google places call. It is refreshing the page when receiving the data, thus resetting the state. It's a job for tomorrow.
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
"use client";
|
|
import { getLocation } from "@/app/actions";
|
|
import { useState } from "react";
|
|
import { useFormStatus } from "react-dom";
|
|
|
|
export default function LocationSearch(props: any) {
|
|
const [searchLocation, setSearchLocation] = useState("");
|
|
const setGeoLocation = props.setGeoLocation;
|
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
setSearchLocation(e.target.value);
|
|
};
|
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
|
const coordinates = getLocation(searchLocation);
|
|
setGeoLocation(coordinates);
|
|
};
|
|
const { pending } = useFormStatus();
|
|
return (
|
|
<>
|
|
<form onSubmit={handleSubmit}>
|
|
<input
|
|
id="location"
|
|
name="locationSearch"
|
|
type="text"
|
|
placeholder="enter a location to get the weather"
|
|
value={searchLocation}
|
|
onChange={handleChange}
|
|
/>
|
|
<button type="submit" disabled={pending}>
|
|
{pending ? "Searching..." : "Search"}
|
|
</button>
|
|
<label htmlFor="location" className="hidden">
|
|
Enter location to get the weather!
|
|
</label>
|
|
</form>
|
|
<p>{searchLocation}</p>
|
|
</>
|
|
);
|
|
}
|