Skip to content

Commit

Permalink
feat: DAH-2661 refactoring and adding feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tallulahkay committed Dec 18, 2024
1 parent 77cd82a commit 917c7d5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 76 deletions.
20 changes: 20 additions & 0 deletions app/javascript/modules/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IconHomeCheck } from "./listings/assets/icon-home-check"

export const PREFERENCES = {
aliceGriffith: "Alice Griffith Housing Development Resident",
antiDisplacement: "Anti-Displacement Housing Preference (ADHP)",
Expand Down Expand Up @@ -124,3 +126,21 @@ export const RENTAL_DIRECTORY_SECTIONS = [
]

export const DIRECTORY_TYPE_SALES = "forSale"
export const DIRECTORY_SECTION_INFO = {
open: {
ref: "enter-a-lottery",
icon: "house",
},
fcfs: {
ref: "buy-now",
icon: IconHomeCheck,
},
upcoming: {
ref: "upcoming-lotteries",
icon: "clock",
},
results: {
ref: "lottery-results",
icon: "result",
},
}
6 changes: 2 additions & 4 deletions app/javascript/modules/listings/DirectoryHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export interface ListingsGroups {
upcoming: RailsListing[]
results: RailsListing[]
additional: RailsListing[]
fcfsSalesOpen: RailsListing[]
fcfsSalesNotYetOpen: RailsListing[]
fcfs: RailsListing[]
}

type Listing = RailsRentalListing & {
Expand Down Expand Up @@ -433,8 +432,7 @@ export const sortListings = (
upcoming,
results,
additional,
fcfsSalesOpen,
fcfsSalesNotYetOpen,
fcfs: [...fcfsSalesOpen, ...fcfsSalesNotYetOpen],
} as ListingsGroups
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { ReactNode } from "react"
import "./DirectoryPageNavigationBar.scss"
import { Button, Icon as SeedsIcon } from "@bloom-housing/ui-seeds"
import { Icon, t, UniversalIconType } from "@bloom-housing/ui-components"
import { ListingsGroups } from "./DirectoryHelpers"
interface DirectorySectionInfoObject {
key: string
ref: string
Expand All @@ -12,9 +13,11 @@ interface DirectorySectionInfoObject {
const DirectoryPageNavigationBar = ({
directorySections,
activeItem,
listings,
}: {
directorySections: DirectorySectionInfoObject[]
activeItem: string
listings: ListingsGroups
}) => {
return (
<div className="directory-page-navigation-bar">
Expand All @@ -40,7 +43,7 @@ const DirectoryPageNavigationBar = ({
<SeedsIcon size="md">{section.icon}</SeedsIcon>
)}
{t(`listingsDirectory.navBar.${section.key}`, {
numListings: section.numListings,
numListings: listings[section.key].length,
})}
</Button>
)
Expand Down
3 changes: 0 additions & 3 deletions app/javascript/modules/listings/GenericDirectory.scss

This file was deleted.

116 changes: 48 additions & 68 deletions app/javascript/modules/listings/GenericDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import "./ListingDirectory.scss"
import { MailingListSignup } from "../../components/MailingListSignup"
import DirectoryPageNavigationBar from "./DirectoryPageNavigationBar"
import {
DIRECTORY_SECTION_INFO,
DIRECTORY_TYPE_SALES,
RENTAL_DIRECTORY_SECTIONS,
SALE_DIRECTORY_SECTIONS,
} from "../constants"
import { IconHomeCheck } from "./assets/icon-home-check"
import { useFeatureFlag } from "../../hooks/useFeatureFlag"

interface RentalDirectoryProps {
listingsAPI: (filters?: EligibilityFilters) => Promise<RailsListing[]>
Expand All @@ -37,15 +38,37 @@ interface RentalDirectoryProps {
findMoreActionBlock: ReactNode
}

const DirectorySection = ({
refKey,
observerRef,
children,
}: {
refKey: string
observerRef: React.MutableRefObject<null | IntersectionObserver>
children: ReactNode
}) => {
return (
<div
id={refKey}
ref={(el) => {
if (el) {
observerRef?.current?.observe(el)
}
}}
>
{children}
</div>
)
}

export const GenericDirectory = (props: RentalDirectoryProps) => {
const [rawListings, setRawListings] = useState<Array<RailsListing>>([])
const [listings, setListings] = useState<ListingsGroups>({
open: [],
upcoming: [],
results: [],
additional: [],
fcfsSalesOpen: [],
fcfsSalesNotYetOpen: [],
fcfs: [],
})
const [loading, setLoading] = useState<boolean>(true)
// Whether any listings are a match.
Expand Down Expand Up @@ -99,73 +122,44 @@ export const GenericDirectory = (props: RentalDirectoryProps) => {
? SALE_DIRECTORY_SECTIONS
: RENTAL_DIRECTORY_SECTIONS

const directorySectionInfo = {
open: {
ref: "enter-a-lottery",
icon: "house",
numListings: listings.open.length,
},
fcfs: {
ref: "buy-now",
icon: IconHomeCheck,
numListings: listings.fcfsSalesNotYetOpen.length + listings.fcfsSalesOpen.length,
},
upcoming: {
ref: "upcoming-lotteries",
icon: "clock",
numListings: listings.upcoming.length,
},
results: {
ref: "lottery-results",
icon: "result",
numListings: listings.results.length,
},
}
const { unleashFlag: newDirectoryEnabled } = useFeatureFlag(
"temp.webapp.directory.listings",
false
)

return (
<LoadingOverlay isLoading={loading}>
<div>
{!loading && (
<>
{props.getPageHeader(filters, setFilters, match)}
<DirectoryPageNavigationBar
directorySections={directorySections.map((section: string) => {
return { key: section, ...directorySectionInfo[section] }
})}
activeItem={activeItem}
/>
{newDirectoryEnabled && (
<DirectoryPageNavigationBar
directorySections={directorySections.map((section: string) => {
return { key: section, ...DIRECTORY_SECTION_INFO[section] }
})}
activeItem={activeItem}
listings={listings}
/>
)}
<div id="listing-results">
<div
id="enter-a-lottery"
ref={(el) => {
if (el) {
observerRef?.current?.observe(el)
}
}}
>
<DirectorySection refKey="enter-a-lottery" observerRef={observerRef}>
{openListingsView(
listings.open,
props.directoryType,
props.getSummaryTable,
hasFiltersSet
)}
</div>
</DirectorySection>
{props.directoryType === DIRECTORY_TYPE_SALES && (
<div
id="buy-now"
ref={(el) => {
if (el) {
observerRef?.current?.observe(el)
}
}}
>
<DirectorySection refKey="buy-now" observerRef={observerRef}>
{fcfsSalesView(
[...listings.fcfsSalesOpen, ...listings.fcfsSalesNotYetOpen],
listings.fcfs,
props.directoryType,
props.getSummaryTable,
hasFiltersSet
)}
</div>
</DirectorySection>
)}
{props.findMoreActionBlock}
{filters &&
Expand All @@ -175,30 +169,16 @@ export const GenericDirectory = (props: RentalDirectoryProps) => {
props.getSummaryTable,
hasFiltersSet
)}
<div
id="upcoming-lotteries"
ref={(el) => {
if (el) {
observerRef?.current?.observe(el)
}
}}
>
<DirectorySection refKey="upcoming-lotteries" observerRef={observerRef}>
{upcomingLotteriesView(
listings.upcoming,
props.directoryType,
props.getSummaryTable
)}
</div>
<div
id="lottery-results"
ref={(el) => {
if (el) {
observerRef?.current?.observe(el)
}
}}
>
</DirectorySection>
<DirectorySection refKey="lottery-results" observerRef={observerRef}>
{lotteryResultsView(listings.results, props.directoryType, props.getSummaryTable)}
</div>
</DirectorySection>
</div>
</>
)}
Expand Down

0 comments on commit 917c7d5

Please sign in to comment.