-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
card de dados do local; fix social nome
- Loading branch information
Showing
15 changed files
with
452 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { cn } from "@/lib/utils"; | ||
import * as React from "react"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; | ||
import { Local } from "@/types"; | ||
import { REDE_SOCIAL_NOME } from "@/lib/constants"; | ||
|
||
import { SocialIcon } from "react-social-icons"; | ||
|
||
interface Props extends React.HTMLAttributes<HTMLDivElement> { | ||
data: Local; | ||
} | ||
|
||
function LocalPanel({ data, className, ...props }: Props) { | ||
const [open, setOpen] = React.useState(true); | ||
|
||
return open ? ( | ||
<Card className={cn("m-6 max-w-72 text-sm sm:max-w-80", className)} {...props}> | ||
<CardHeader className="py-3"> | ||
<CardTitle className="text-base">{data.nome}</CardTitle> | ||
{data.endereco.enderecoFormatado && <CardDescription>{data.endereco.enderecoFormatado}</CardDescription>} | ||
</CardHeader> | ||
<CardContent | ||
className={cn("max-h-[calc(100vh_-_12rem)] cursor-auto overflow-y-scroll px-6 py-0 text-sm", className)} | ||
> | ||
<dl className="grid grid-cols-1 gap-x-6 gap-y-10 sm:grid-cols-2 sm:gap-y-16 lg:gap-x-8"> | ||
<div className="border-t border-gray-200 pt-4"> | ||
<dt className="font-medium text-gray-900">Nomes populares</dt> | ||
{data.apelidos.map(({ id, apelido }) => ( | ||
<dd key={`apelido-${id}`} className="mt-2 text-base"> | ||
{apelido} | ||
</dd> | ||
))} | ||
</div> | ||
|
||
<div className="border-t border-gray-200 pt-4"> | ||
<dt className="font-medium text-gray-900">Redes sociais</dt> | ||
<dd className="mt-2 flex flex-wrap gap-2"> | ||
{data.redesSociais.map(({ id, link, nome }) => ( | ||
<SocialIcon | ||
key={id} | ||
style={{ width: "2.85rem", height: "2.85rem" }} | ||
url={link} | ||
title={REDE_SOCIAL_NOME[nome]} | ||
/> | ||
))} | ||
</dd> | ||
</div> | ||
|
||
<div className="border-t border-gray-200 pt-4"> | ||
<dt className="font-medium text-gray-900">Telefone</dt> | ||
<dd className="mt-2 text-base">(11) 95194-9746</dd> | ||
</div> | ||
|
||
<div className="border-t border-gray-200 pt-4"> | ||
<dt className="font-medium text-gray-900">Site</dt> | ||
<dd className="mt-1 truncate text-base"> | ||
<a href={"https://ruanosena.github.io"}>{new URL("https://ruanosena.github.io").hostname}</a> | ||
</dd> | ||
</div> | ||
</dl> | ||
</CardContent> | ||
<CardFooter className="py-3"> | ||
<div className="mt-2 flex justify-between"> | ||
<a | ||
href="https://codesandbox.io/s/github/visgl/react-google-maps/tree/main/examples/advanced-marker-interaction" | ||
target="_new" | ||
> | ||
Try on CodeSandbox ↗ | ||
</a> | ||
|
||
<a | ||
href="https://github.com/visgl/react-google-maps/tree/main/examples/advanced-marker-interaction" | ||
target="_new" | ||
> | ||
View Code ↗ | ||
</a> | ||
</div> | ||
</CardFooter> | ||
</Card> | ||
) : ( | ||
<Button variant="outline" onClick={() => setOpen((prevState) => !prevState)}> | ||
Informações | ||
</Button> | ||
); | ||
} | ||
|
||
export default React.memo(LocalPanel); |
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,54 @@ | ||
"use client"; | ||
import { useGeo } from "@/contexts/GeoContext"; | ||
import { useDirections } from "@/hooks/useDirections"; | ||
import { getEnderecoBounds } from "@/lib/utils"; | ||
import { Endereco, isLocal, Local } from "@/types"; | ||
import { AdvancedMarker, InfoWindow, Map, Pin, useMap } from "@vis.gl/react-google-maps"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
|
||
interface Props { | ||
data: Endereco | Local; | ||
location?: google.maps.LatLngLiteral; | ||
} | ||
|
||
export default function MapPlaces({ location: locationProps, data }: Props) { | ||
const { location, isDefaultLocation, promptGeolocation } = useGeo(); | ||
const { leg } = useDirections(data, isDefaultLocation ? locationProps : location); | ||
|
||
const map = useMap(); | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const defaultBounds = useRef<google.maps.LatLngBoundsLiteral | undefined>( | ||
getEnderecoBounds(isLocal(data) ? data.endereco : data), | ||
).current; | ||
const { mapsGetBoundingBox, geometryAvailable } = useGeo(); | ||
|
||
useEffect(() => { | ||
if (!map || !geometryAvailable) return; | ||
// fit local coordinate bounds if no endereco bounds was found | ||
if (!defaultBounds) map.fitBounds(mapsGetBoundingBox(data.lat, data.lng, 250)); | ||
}, [map, geometryAvailable, mapsGetBoundingBox, data]); | ||
|
||
return ( | ||
<Map | ||
className="max-h-screen" | ||
mapId={process.env.NEXT_PUBLIC_MAP_ID} | ||
defaultZoom={12} | ||
defaultBounds={defaultBounds} | ||
gestureHandling={"greedy"} | ||
clickableIcons={false} | ||
disableDefaultUI={false} | ||
> | ||
<AdvancedMarker position={data} onClick={() => setOpen(true)}> | ||
<Pin background={"cyan"} borderColor={"teal"} glyphColor={"darkcyan"} /> | ||
</AdvancedMarker> | ||
|
||
{open && ( | ||
<InfoWindow position={data} onCloseClick={() => setOpen(false)}> | ||
<p>{leg?.distance?.text}</p> | ||
</InfoWindow> | ||
)} | ||
</Map> | ||
); | ||
} |
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,52 @@ | ||
"use client"; | ||
import { useGeo } from "@/contexts/GeoContext"; | ||
import { useDirections } from "@/hooks/useDirections"; | ||
import { getEnderecoBounds } from "@/lib/utils"; | ||
import { Endereco } from "@/types"; | ||
import { AdvancedMarker, InfoWindow, Map, Pin, useMap } from "@vis.gl/react-google-maps"; | ||
import React, { useEffect, useRef, useState } from "react"; | ||
|
||
interface Props { | ||
data: Endereco; | ||
location?: google.maps.LatLngLiteral; | ||
} | ||
|
||
export default function MapPlacesEndereco({ location: locationProps, data }: Props) { | ||
const { location, isDefaultLocation, promptGeolocation } = useGeo(); | ||
const { leg } = useDirections(data, isDefaultLocation ? locationProps : location); | ||
|
||
const map = useMap(); | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const defaultBounds = useRef<google.maps.LatLngBoundsLiteral | undefined>(getEnderecoBounds(data)).current; | ||
const { mapsGetBoundingBox, geometryAvailable } = useGeo(); | ||
|
||
useEffect(() => { | ||
if (!map || !geometryAvailable) return; | ||
|
||
if (!defaultBounds) map.fitBounds(mapsGetBoundingBox(data.lat, data.lng, 250)); | ||
}, [map, geometryAvailable, mapsGetBoundingBox, data]); | ||
|
||
return ( | ||
<Map | ||
className="max-h-screen" | ||
mapId={process.env.NEXT_PUBLIC_MAP_ID} | ||
defaultZoom={12} | ||
defaultBounds={defaultBounds} | ||
gestureHandling={"greedy"} | ||
clickableIcons={false} | ||
disableDefaultUI={false} | ||
> | ||
<AdvancedMarker position={data} onClick={() => setOpen(true)}> | ||
<Pin background={"cyan"} borderColor={"teal"} glyphColor={"darkcyan"} /> | ||
</AdvancedMarker> | ||
|
||
{open && ( | ||
<InfoWindow position={data} onCloseClick={() => setOpen(false)}> | ||
<p>{leg?.distance?.text}</p> | ||
</InfoWindow> | ||
)} | ||
</Map> | ||
); | ||
} |
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,64 @@ | ||
"use client"; | ||
import { useGeo } from "@/contexts/GeoContext"; | ||
import { useDirections } from "@/hooks/useDirections"; | ||
import { getEnderecoBounds } from "@/lib/utils"; | ||
import { Local } from "@/types"; | ||
import { AdvancedMarker, ControlPosition, InfoWindow, Map, Pin, useMap } from "@vis.gl/react-google-maps"; | ||
import React, { Fragment, useEffect, useRef, useState } from "react"; | ||
import PanelLocal from "./LocalPanel"; | ||
import dynamic from "next/dynamic"; | ||
const DynamicMapControl = dynamic(() => import("@vis.gl/react-google-maps").then((m) => m.MapControl), { ssr: false }); | ||
|
||
interface Props { | ||
data: Local; | ||
location?: google.maps.LatLngLiteral; | ||
} | ||
|
||
export default function MapPlacesLocal({ data, location: locationProps }: Props) { | ||
const { location, isDefaultLocation, promptGeolocation } = useGeo(); | ||
const { leg } = useDirections(data, isDefaultLocation ? locationProps : location); | ||
|
||
const map = useMap(); | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const defaultBounds = useRef<google.maps.LatLngBoundsLiteral | undefined>(getEnderecoBounds(data.endereco)).current; | ||
const { mapsGetBoundingBox, geometryAvailable } = useGeo(); | ||
|
||
useEffect(() => { | ||
if (!map || !geometryAvailable) return; | ||
|
||
if (!defaultBounds) map.fitBounds(mapsGetBoundingBox(data.lat, data.lng, 250)); | ||
}, [map, geometryAvailable, mapsGetBoundingBox, data]); | ||
|
||
useEffect(() => { | ||
promptGeolocation(); | ||
}, []); | ||
|
||
return ( | ||
<Fragment> | ||
<Map | ||
className="h-screen" | ||
mapId={process.env.NEXT_PUBLIC_MAP_ID} | ||
defaultZoom={12} | ||
defaultBounds={defaultBounds} | ||
gestureHandling={"greedy"} | ||
clickableIcons={false} | ||
disableDefaultUI={true} | ||
> | ||
<AdvancedMarker position={data} onClick={() => setOpen(true)}> | ||
<Pin background={"cyan"} borderColor={"teal"} glyphColor={"darkcyan"} /> | ||
</AdvancedMarker> | ||
|
||
{open && ( | ||
<InfoWindow position={data} onCloseClick={() => setOpen(false)}> | ||
<p>{leg?.distance?.text}</p> | ||
</InfoWindow> | ||
)} | ||
</Map> | ||
<DynamicMapControl position={ControlPosition.TOP_RIGHT}> | ||
<PanelLocal data={data} /> | ||
</DynamicMapControl> | ||
</Fragment> | ||
); | ||
} |
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
Oops, something went wrong.