feat(sw-343): fixed map page (without modal)
This commit is contained in:
@@ -11,6 +11,7 @@ import { setLang } from "@/i18n/serverContext"
|
|||||||
import {
|
import {
|
||||||
fetchAvailableHotels,
|
fetchAvailableHotels,
|
||||||
generateChildrenString,
|
generateChildrenString,
|
||||||
|
getCentralCoordinates,
|
||||||
getPointOfInterests,
|
getPointOfInterests,
|
||||||
} from "../../utils"
|
} from "../../utils"
|
||||||
|
|
||||||
@@ -54,17 +55,7 @@ export default async function SelectHotelMapPage({
|
|||||||
|
|
||||||
const pointOfInterests = getPointOfInterests(hotels)
|
const pointOfInterests = getPointOfInterests(hotels)
|
||||||
|
|
||||||
const centralCoordinates = pointOfInterests.reduce(
|
const centralCoordinates = getCentralCoordinates(pointOfInterests)
|
||||||
(acc, poi) => {
|
|
||||||
acc.lat += poi.coordinates.lat
|
|
||||||
acc.lng += poi.coordinates.lng
|
|
||||||
return acc
|
|
||||||
},
|
|
||||||
{ lat: 0, lng: 0 }
|
|
||||||
)
|
|
||||||
|
|
||||||
centralCoordinates.lat /= pointOfInterests.length
|
|
||||||
centralCoordinates.lng /= pointOfInterests.length
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MapModal>
|
<MapModal>
|
||||||
@@ -73,6 +64,7 @@ export default async function SelectHotelMapPage({
|
|||||||
coordinates={centralCoordinates}
|
coordinates={centralCoordinates}
|
||||||
pointsOfInterest={pointOfInterests}
|
pointsOfInterest={pointOfInterests}
|
||||||
mapId={googleMapId}
|
mapId={googleMapId}
|
||||||
|
isModal={true}
|
||||||
/>
|
/>
|
||||||
</MapModal>
|
</MapModal>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { getLocations } from "@/lib/trpc/memoizedRequests"
|
|||||||
import {
|
import {
|
||||||
fetchAvailableHotels,
|
fetchAvailableHotels,
|
||||||
generateChildrenString,
|
generateChildrenString,
|
||||||
|
getCentralCoordinates,
|
||||||
getFiltersFromHotels,
|
getFiltersFromHotels,
|
||||||
getPointOfInterests,
|
getPointOfInterests,
|
||||||
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
} from "@/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils"
|
||||||
@@ -55,15 +56,16 @@ export default async function SelectHotelMapPage({
|
|||||||
const filters = getFiltersFromHotels(hotels)
|
const filters = getFiltersFromHotels(hotels)
|
||||||
|
|
||||||
const pointOfInterests = getPointOfInterests(hotels)
|
const pointOfInterests = getPointOfInterests(hotels)
|
||||||
|
const centralCoordinates = getCentralCoordinates(pointOfInterests)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
<SelectHotelMap
|
<SelectHotelMap
|
||||||
apiKey={googleMapsApiKey}
|
apiKey={googleMapsApiKey}
|
||||||
// TODO: use correct coordinates. The city center?
|
coordinates={centralCoordinates}
|
||||||
coordinates={{ lat: 59.32, lng: 18.01 }}
|
|
||||||
pointsOfInterest={pointOfInterests}
|
pointsOfInterest={pointOfInterests}
|
||||||
mapId={googleMapId}
|
mapId={googleMapId}
|
||||||
|
isModal={false}
|
||||||
/>
|
/>
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -78,3 +78,19 @@ export function getPointOfInterests(hotels: HotelData[]): PointOfInterest[] {
|
|||||||
group: PointOfInterestGroupEnum.LOCATION,
|
group: PointOfInterestGroupEnum.LOCATION,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCentralCoordinates(pointOfInterests: PointOfInterest[]) {
|
||||||
|
const centralCoordinates = pointOfInterests.reduce(
|
||||||
|
(acc, poi) => {
|
||||||
|
acc.lat += poi.coordinates.lat
|
||||||
|
acc.lng += poi.coordinates.lng
|
||||||
|
return acc
|
||||||
|
},
|
||||||
|
{ lat: 0, lng: 0 }
|
||||||
|
)
|
||||||
|
|
||||||
|
centralCoordinates.lat /= pointOfInterests.length
|
||||||
|
centralCoordinates.lng /= pointOfInterests.length
|
||||||
|
|
||||||
|
return centralCoordinates
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { selectHotel } from "@/constants/routes/hotelReservation"
|
|||||||
import { CloseIcon, CloseLargeIcon } from "@/components/Icons"
|
import { CloseIcon, CloseLargeIcon } from "@/components/Icons"
|
||||||
import InteractiveMap from "@/components/Maps/InteractiveMap"
|
import InteractiveMap from "@/components/Maps/InteractiveMap"
|
||||||
import Button from "@/components/TempDesignSystem/Button"
|
import Button from "@/components/TempDesignSystem/Button"
|
||||||
import Link from "@/components/TempDesignSystem/Link"
|
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
|
|
||||||
import HotelListing from "./HotelListing"
|
import HotelListing from "./HotelListing"
|
||||||
@@ -23,23 +22,30 @@ export default function SelectHotelMap({
|
|||||||
coordinates,
|
coordinates,
|
||||||
pointsOfInterest,
|
pointsOfInterest,
|
||||||
mapId,
|
mapId,
|
||||||
|
isModal,
|
||||||
}: SelectHotelMapProps) {
|
}: SelectHotelMapProps) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const [activePoi, setActivePoi] = useState<string | null>(null)
|
const [activePoi, setActivePoi] = useState<string | null>(null)
|
||||||
|
|
||||||
function onDismiss() {
|
function handleModalDismiss() {
|
||||||
router.back()
|
router.back()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handlePageRedirect() {
|
||||||
|
router.push(
|
||||||
|
`${selectHotel[lang]}?${new URLSearchParams(window.location.search)}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const closeButton = (
|
const closeButton = (
|
||||||
<Button
|
<Button
|
||||||
intent="inverted"
|
intent="inverted"
|
||||||
size="small"
|
size="small"
|
||||||
theme="base"
|
theme="base"
|
||||||
className={styles.closeButton}
|
className={styles.closeButton}
|
||||||
onClick={onDismiss}
|
onClick={isModal ? handleModalDismiss : handlePageRedirect}
|
||||||
>
|
>
|
||||||
<CloseIcon color="burgundy" />
|
<CloseIcon color="burgundy" />
|
||||||
{intl.formatMessage({ id: "Close the map" })}
|
{intl.formatMessage({ id: "Close the map" })}
|
||||||
@@ -47,28 +53,30 @@ export default function SelectHotelMap({
|
|||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
<APIProvider apiKey={apiKey}>
|
<APIProvider apiKey={apiKey}>
|
||||||
<div className={styles.filterContainer}>
|
<div className={styles.container}>
|
||||||
<Button
|
<div className={styles.filterContainer}>
|
||||||
intent="text"
|
<Button
|
||||||
size="small"
|
intent="text"
|
||||||
variant="icon"
|
size="small"
|
||||||
wrapping
|
variant="icon"
|
||||||
onClick={onDismiss}
|
wrapping
|
||||||
>
|
onClick={isModal ? handleModalDismiss : handlePageRedirect}
|
||||||
<CloseLargeIcon />
|
>
|
||||||
</Button>
|
<CloseLargeIcon />
|
||||||
<span>Filter and sort</span>
|
</Button>
|
||||||
{/* TODO: Add filter and sort button */}
|
<span>Filter and sort</span>
|
||||||
|
{/* TODO: Add filter and sort button */}
|
||||||
|
</div>
|
||||||
|
<HotelListing />
|
||||||
|
<InteractiveMap
|
||||||
|
closeButton={closeButton}
|
||||||
|
coordinates={coordinates}
|
||||||
|
pointsOfInterest={pointsOfInterest}
|
||||||
|
activePoi={activePoi}
|
||||||
|
onActivePoiChange={setActivePoi}
|
||||||
|
mapId={mapId}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<HotelListing />
|
|
||||||
<InteractiveMap
|
|
||||||
closeButton={closeButton}
|
|
||||||
coordinates={coordinates}
|
|
||||||
pointsOfInterest={pointsOfInterest}
|
|
||||||
activePoi={activePoi}
|
|
||||||
onActivePoiChange={setActivePoi}
|
|
||||||
mapId={mapId}
|
|
||||||
/>
|
|
||||||
</APIProvider>
|
</APIProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.filterContainer {
|
.filterContainer {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -16,6 +20,7 @@
|
|||||||
z-index: 10;
|
z-index: 10;
|
||||||
background-color: var(--Base-Surface-Secondary-light-Normal);
|
background-color: var(--Base-Surface-Secondary-light-Normal);
|
||||||
padding: 0 var(--Spacing-x2);
|
padding: 0 var(--Spacing-x2);
|
||||||
|
height: 44px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filterContainer .closeButton {
|
.filterContainer .closeButton {
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ export interface SelectHotelMapProps {
|
|||||||
coordinates: Coordinates
|
coordinates: Coordinates
|
||||||
pointsOfInterest: PointOfInterest[]
|
pointsOfInterest: PointOfInterest[]
|
||||||
mapId: string
|
mapId: string
|
||||||
|
isModal: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user