-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c0a73c
commit 6a6d67a
Showing
9 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { SquareArrowOutUpRight } from "lucide-react"; | ||
import { Link } from "raviger"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { getMapUrl, isAndroidDevice } from "@/Utils/utils"; | ||
|
||
const isValidLatitude = (latitude: string) => { | ||
const lat = parseFloat(latitude.trim()); | ||
return Number.isFinite(lat) && lat >= -90 && lat <= 90; | ||
}; | ||
|
||
const isValidLongitude = (longitude: string) => { | ||
const long = parseFloat(longitude.trim()); | ||
return Number.isFinite(long) && long >= -180 && long <= 180; | ||
}; | ||
|
||
export const FacilityMapsLink = ({ | ||
latitude, | ||
longitude, | ||
}: { | ||
latitude: string; | ||
longitude: string; | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
if (!isValidLatitude(latitude) || !isValidLongitude(longitude)) { | ||
return null; | ||
} | ||
const target = isAndroidDevice ? "_self" : "_blank"; | ||
|
||
return ( | ||
<Link | ||
className="text-primary flex items-center gap-1 w-max" | ||
href={getMapUrl(latitude, longitude)} | ||
target={target} | ||
rel="noreferrer" | ||
> | ||
{t("show_on_map")} | ||
<SquareArrowOutUpRight className="h-3 w-3" /> | ||
</Link> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters