|
| 1 | +import React, { useEffect, useContext, useState, useCallback } from "react" |
| 2 | +import { useRouter } from "next/router" |
| 3 | +import { APIProvider } from "@vis.gl/react-google-maps" |
| 4 | +import { Button, Card, Heading, LoadingState } from "@bloom-housing/ui-seeds" |
| 5 | +import { |
| 6 | + Jurisdiction, |
| 7 | + Listing, |
| 8 | + FeatureFlagEnum, |
| 9 | + MultiselectQuestion, |
| 10 | +} from "@bloom-housing/shared-helpers/src/types/backend-swagger" |
| 11 | +import { |
| 12 | + AuthContext, |
| 13 | + BloomCard, |
| 14 | + ListingList, |
| 15 | + MessageContext, |
| 16 | + pushGtmEvent, |
| 17 | + ResponseException, |
| 18 | +} from "@bloom-housing/shared-helpers" |
| 19 | +import { t } from "@bloom-housing/ui-components" |
| 20 | +import Layout from "../../../layouts/application" |
| 21 | +import MaxWidthLayout from "../../../layouts/max-width" |
| 22 | +import { UserStatus } from "../../../lib/constants" |
| 23 | +import { fetchFavoriteListingIds, isFeatureFlagOn, saveListingFavorite } from "../../../lib/helpers" |
| 24 | +import { FilterDrawer } from "../FilterDrawer" |
| 25 | +import { |
| 26 | + decodeQueryToFilterData, |
| 27 | + encodeFilterDataToQuery, |
| 28 | + FilterData, |
| 29 | + getFilterQueryFromURL, |
| 30 | +} from "../FilterDrawerHelpers" |
| 31 | +import { PageHeaderSection } from "../../../patterns/PageHeaderLayout" |
| 32 | +import { ListingCard } from "../ListingCard" |
| 33 | +import styles from "../ListingBrowse.module.scss" |
| 34 | +import { MetaTags } from "../../shared/MetaTags" |
| 35 | +import ListingsSearchCombined from "./ListingsSearchCombined" |
| 36 | + |
| 37 | +export interface PaginationData { |
| 38 | + currentPage: number |
| 39 | + itemCount: number |
| 40 | + itemsPerPage: number |
| 41 | + totalItems: number |
| 42 | + totalPages: number |
| 43 | +} |
| 44 | + |
| 45 | +export interface ListingBrowseProps { |
| 46 | + listings: Listing[] |
| 47 | + jurisdiction: Jurisdiction |
| 48 | + multiselectData: MultiselectQuestion[] |
| 49 | + paginationData?: PaginationData |
| 50 | + areFiltersActive?: boolean |
| 51 | +} |
| 52 | + |
| 53 | +export const ListingMap = (props: ListingBrowseProps) => { |
| 54 | + const router = useRouter() |
| 55 | + const { profile, userService } = useContext(AuthContext) |
| 56 | + const { addToast } = useContext(MessageContext) |
| 57 | + const [isLoading, setIsLoading] = useState<boolean>(false) |
| 58 | + |
| 59 | + useEffect(() => { |
| 60 | + pushGtmEvent<ListingList>({ |
| 61 | + event: "pageView", |
| 62 | + pageTitle: "Rent Affordable Housing - Housing Portal", |
| 63 | + status: profile ? UserStatus.LoggedIn : UserStatus.NotLoggedIn, |
| 64 | + numberOfListings: props.listings?.length, |
| 65 | + listingIds: props.listings?.map((listing) => listing.id), |
| 66 | + }) |
| 67 | + }, [profile, props.listings, userService]) |
| 68 | + |
| 69 | + const pageTitle = `${t("pageTitle.rent")} - ${t("nav.siteTitle")}` |
| 70 | + |
| 71 | + let searchString = |
| 72 | + "counties:Alameda,Contra Costa,Marin,Napa,San Francisco,San Mateo,Santa Clara,Solano,Sonoma" |
| 73 | + const searchParam = Array.isArray(router.query.search) |
| 74 | + ? router.query.search[0] |
| 75 | + : router.query.search |
| 76 | + |
| 77 | + // override the search value if present in url |
| 78 | + if (searchParam) { |
| 79 | + searchString = searchParam |
| 80 | + } |
| 81 | + |
| 82 | + return ( |
| 83 | + <Layout hideFooter={true} pageTitle={pageTitle}> |
| 84 | + <Heading className={"sr-only"} priority={1}> |
| 85 | + {t("nav.listings")} |
| 86 | + </Heading> |
| 87 | + <APIProvider apiKey={process.env.googleMapsApiKey}> |
| 88 | + <ListingsSearchCombined |
| 89 | + googleMapsApiKey={process.env.googleMapsApiKey} |
| 90 | + googleMapsMapId={process.env.googleMapsMapId} |
| 91 | + searchString={searchString} |
| 92 | + bedrooms={[]} |
| 93 | + bathrooms={[]} |
| 94 | + counties={[]} |
| 95 | + /> |
| 96 | + </APIProvider> |
| 97 | + </Layout> |
| 98 | + ) |
| 99 | +} |
0 commit comments