feat: made lat and long into single input field
This commit is contained in:
1 parent
b0075082e2
commit
f7ae586ed1
3 files changed
+33
-42
No files matched your search
+5
-1
@@ -64,7 +64,11 @@ export default function TagMissingLocationDialog({
|
|||||||
</TabsContent>
|
</TabsContent>
|
||||||
<TabsContent value="maps">
|
<TabsContent value="maps">
|
||||||
<div className="flex flex-col gap-6 items-center ">
|
<div className="flex flex-col gap-6 items-center ">
|
||||||
<LazyMap location={mapPosition} onLocationChange={setMapPosition} />
|
<LazyMap location={{
|
||||||
|
latitude: isNaN(mapPosition.latitude) ? 0 : mapPosition.latitude,
|
||||||
|
longitude: isNaN(mapPosition.longitude) ? 0 : mapPosition.longitude,
|
||||||
|
name: mapPosition.name,
|
||||||
|
}} onLocationChange={setMapPosition} />
|
||||||
</div>
|
</div>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|||||||
+27
-40
@@ -5,7 +5,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { IPlace } from "@/types/common";
|
import { IPlace } from "@/types/common";
|
||||||
import React, { useMemo, useState } from "react";
|
import React, { useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
interface TagMissingLocationSearchLatLongProps {
|
interface TagMissingLocationSearchLatLongProps {
|
||||||
onSubmit: (place: IPlace) => Promise<any>;
|
onSubmit: (place: IPlace) => Promise<any>;
|
||||||
@@ -24,6 +24,8 @@ export default function TagMissingLocationSearchLatLong(
|
|||||||
) {
|
) {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const [latLong, setLatLong] = useState<string>("");
|
||||||
|
|
||||||
const [formData, setFormData] = useState<IPlace>({
|
const [formData, setFormData] = useState<IPlace>({
|
||||||
latitude: location.latitude,
|
latitude: location.latitude,
|
||||||
longitude: location.longitude,
|
longitude: location.longitude,
|
||||||
@@ -32,34 +34,16 @@ export default function TagMissingLocationSearchLatLong(
|
|||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
||||||
const isValid = useMemo(() => {
|
const isValid = useMemo(() => {
|
||||||
if (formData.latitude === 0 || formData.longitude === 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (isNaN(formData.latitude) || isNaN(formData.longitude)) {
|
if (isNaN(formData.latitude) || isNaN(formData.longitude)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (formData.latitude === 0 || formData.longitude === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}, [formData]);
|
}, [formData]);
|
||||||
|
|
||||||
const handleChange = (key: string, value: string) => {
|
|
||||||
// if somebody pastes a combination of "lat, long"
|
|
||||||
if (key === "latitude" && value.includes(",")) {
|
|
||||||
const latLong = value.split(",");
|
|
||||||
if (latLong.length === 2) {
|
|
||||||
setFormData({
|
|
||||||
...formData,
|
|
||||||
latitude: parseFloat(latLong[0]),
|
|
||||||
longitude: parseFloat(latLong[1]),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setFormData({
|
|
||||||
...formData,
|
|
||||||
[key]: value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return;
|
return;
|
||||||
@@ -103,32 +87,35 @@ export default function TagMissingLocationSearchLatLong(
|
|||||||
onLocationChange(place);
|
onLocationChange(place);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (latLong) {
|
||||||
|
const [latitude, longitude] = latLong.split(",");
|
||||||
|
setFormData({
|
||||||
|
...formData,
|
||||||
|
latitude: parseFloat(latitude),
|
||||||
|
longitude: parseFloat(longitude),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [latLong]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4 py-4 px-2">
|
<div className="flex flex-col gap-4 py-4 px-2">
|
||||||
<div className="flex items-start gap-2">
|
<div className="flex items-start gap-2">
|
||||||
<div className="flex flex-col gap-2 flex-1">
|
<div className="flex flex-col gap-2 flex-1">
|
||||||
<Label>Latitude</Label>
|
<Label>Latitude, Longitude</Label>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
Enter lat and long in comma separated values
|
||||||
|
</span>
|
||||||
<Input
|
<Input
|
||||||
placeholder="Latitude"
|
placeholder="Latitude, Longitude"
|
||||||
value={formData.latitude}
|
value={latLong}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
handleChange("latitude", e.target.value);
|
setLatLong(e.target.value);
|
||||||
}}
|
|
||||||
onBlur={(e) => handleBlur()}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col gap-2 flex-1">
|
|
||||||
<Label>
|
|
||||||
Longitude
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
placeholder="Longitude"
|
|
||||||
value={formData.longitude}
|
|
||||||
onChange={(e) => {
|
|
||||||
handleChange("longitude", e.target.value);
|
|
||||||
}}
|
}}
|
||||||
onBlur={(e) => handleBlur()}
|
onBlur={(e) => handleBlur()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export default function LazyGridImage(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div>
|
||||||
<img {...props.imageProps} alt={props.imageProps.alt || ""} title="" />
|
<img {...props.imageProps} alt={props.imageProps.alt || ""} title="" />
|
||||||
{props.item.isVideo && <div className="absolute bottom-2 right-2 bg-black/50 p-1 rounded-full flex items-center gap-1">
|
{props.item.isVideo && <div className="absolute bottom-2 right-2 bg-black/50 p-1 rounded-full flex items-center gap-1">
|
||||||
<PlayIcon className="w-3 h-3 text-white" />
|
<PlayIcon className="w-3 h-3 text-white" />
|
||||||
|
|||||||
Reference in new issue
Block a user