Skip to content

Commit

Permalink
feat: creating views for public and partner lists (#1271)
Browse files Browse the repository at this point in the history
* feat: creating views for public and partner lists

* fix: re-adding the features per sean

* fix: fixes accessibilityFeaturesExist

* fix: updates per sean

* feat: update default listing view

Co-authored-by: Sean Albert <[email protected]>
  • Loading branch information
YazeedLoonat and seanmalbert authored May 19, 2022
1 parent 812bcd4 commit 34d8f00
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 27 deletions.
54 changes: 49 additions & 5 deletions backend/core/src/listings/views/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ views.partnerList = {
select: [
"listings.id",
"listings.name",
"listings.applicationDueDate",
"property.id",
...getBaseAddressSelect(["buildingAddress"]),
"listings.status",
"listings.waitlistMaxSize",
"listings.waitlistCurrentSize",
"property.unitsAvailable",
"listings.isVerified",
],
leftJoins: [
{ join: "listings.property", alias: "property" },
{ join: "property.buildingAddress", alias: "buildingAddress" },
],
leftJoins: [{ join: "listings.property", alias: "property" }],
}

views.detail = {
Expand Down Expand Up @@ -209,4 +211,46 @@ views.full = {
],
}

views.publicListings = {
select: [
"listings.id",
"listings.name",
"listings.marketingType",
"listings.marketingDate",
"listings.marketingSeason",
"listings.isVerified",
"property.id",
...getBaseAddressSelect(["buildingAddress"]),
"listingImages.ordinal",
"listingImagesImage.id",
"listingImagesImage.fileId",
"listingImagesImage.label",
"listingPrograms.ordinal",
"listingsProgramsProgram.id",
"listingsProgramsProgram.title",
"features.id",
"features.elevator",
"features.wheelchairRamp",
"features.serviceAnimalsAllowed",
"features.accessibleParking",
"features.parkingOnSite",
"features.inUnitWasherDryer",
"features.barrierFreeEntrance",
"features.rollInShower",
"features.grabBars",
"features.heatingInUnit",
"features.acInUnit",
"features.laundryInBuilding",
],
leftJoins: [
{ join: "listings.property", alias: "property" },
{ join: "property.buildingAddress", alias: "buildingAddress" },
{ join: "listings.images", alias: "listingImages" },
{ join: "listingImages.image", alias: "listingImagesImage" },
{ join: "listings.listingPrograms", alias: "listingPrograms" },
{ join: "listingPrograms.program", alias: "listingsProgramsProgram" },
{ join: "listings.features", alias: "features" },
],
}

export { views }
1 change: 1 addition & 0 deletions backend/core/src/listings/views/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum ListingViewEnum {
detail = "detail",
full = "full",
partnerList = "partnerList",
publicListings = "publicListings",
}

export type Views = {
Expand Down
17 changes: 17 additions & 0 deletions backend/core/src/listings/views/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export function getView(qb: SelectQueryBuilder<Listing>, view?: string) {
return new BaseListingView(qb)
case views.detail:
return new DetailView(qb)
case views.publicListings:
return new PublicListingsView(qb)
case views.partnerList:
return new PartnerListView(qb)
case views.full:
default:
return new FullView(qb)
Expand Down Expand Up @@ -51,6 +55,19 @@ export class DetailView extends BaseListingView {
}
}

export class PublicListingsView extends BaseListingView {
constructor(qb: SelectQueryBuilder<Listing>) {
super(qb)
this.view = views.publicListings
}
}
export class PartnerListView extends BaseListingView {
constructor(qb: SelectQueryBuilder<Listing>) {
super(qb)
this.view = views.partnerList
}
}

export class FullView extends BaseListingView {
constructor(qb: SelectQueryBuilder<Listing>) {
super(qb)
Expand Down
4 changes: 3 additions & 1 deletion sites/partners/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type UseUserListProps = PaginationProps

type UseListingsDataProps = PaginationProps & {
listingIds?: string[]
view?: string
}

export function useSingleListingData(listingId: string) {
Expand All @@ -50,11 +51,12 @@ export function useListingsData({
listingIds,
orderBy,
orderDir,
view = "base",
}: UseListingsDataProps) {
const params = {
page,
limit,
view: "base",
view,
orderBy,
orderDir: OrderDirEnum.ASC,
}
Expand Down
1 change: 1 addition & 0 deletions sites/partners/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default function ListingsList() {
: undefined,
orderBy: sortOptions.orderBy,
orderDir: sortOptions.orderDir,
view: "partnerList",
})

const gridOptions: GridOptions = {
Expand Down
10 changes: 2 additions & 8 deletions sites/public/lib/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ImageTag,
Tooltip,
} from "@bloom-housing/ui-components"
import { imageUrlFromListing, listingFeatures } from "@bloom-housing/shared-helpers"
import { imageUrlFromListing } from "@bloom-housing/shared-helpers"

export const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

Expand Down Expand Up @@ -55,13 +55,7 @@ const getListingCardSubtitle = (address: Address) => {

export const accessibilityFeaturesExist = (features: ListingFeatures) => {
if (!features) return false
let featuresExist = false
Object.keys(listingFeatures).map((feature) => {
if (features[feature]) {
featuresExist = true
}
})
return featuresExist
return Object.keys(features).some((feature) => features[feature])
}

export const getImageTagLabelFromListing = (listing: Listing) => {
Expand Down
23 changes: 12 additions & 11 deletions sites/public/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useFormConductor = (stepName: string) => {
return context
}

const listingsFetcher = function () {
const listingsFetcher = function (view: string) {
return async (
url: string,
page: number,
Expand All @@ -60,11 +60,11 @@ const listingsFetcher = function () {
) => {
const res = await axios.get(url, {
params: {
view: "base",
page: page,
limit: limit,
view,
page,
limit,
filter: encodeToBackendFilterArray(filters),
orderBy: orderBy,
orderBy,
},
paramsSerializer: (params) => {
return qs.stringify(params)
Expand All @@ -77,13 +77,14 @@ const listingsFetcher = function () {
// TODO: move this so it can be shared with the partner site.
export function useListingsData(
pageIndex: number,
limit = 10,
limit = 8,
filters: ListingFilterState,
orderBy: OrderByFieldsEnum
orderBy: OrderByFieldsEnum,
view = "publicListings"
) {
const { data, error } = useSWR(
[`${process.env.listingServiceUrl}`, pageIndex, limit, filters, orderBy],
listingsFetcher()
listingsFetcher(view)
)

return {
Expand Down Expand Up @@ -140,9 +141,9 @@ export async function fetchBaseListingData() {
try {
const response = await axios.get(process.env.listingServiceUrl, {
params: {
view: "base",
limit: "8",
page: "1",
view: "publicListings",
limit: 8,
page: 1,
orderBy: OrderByFieldsEnum.comingSoon,
filter: [
{
Expand Down
3 changes: 2 additions & 1 deletion sites/public/pages/account/favorites.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ const FavoritedListingsPage = () => {
currentPage,
itemsPerPage,
filterState,
OrderByFieldsEnum.mostRecentlyUpdated
OrderByFieldsEnum.comingSoon,
"publicListings"
)

const content = useMemo(() => {
Expand Down
3 changes: 2 additions & 1 deletion sites/public/pages/listings/filtered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const FilteredListingsPage = () => {
currentPage,
itemsPerPage,
filterState,
OrderByFieldsEnum.comingSoon
OrderByFieldsEnum.comingSoon,
"publicListings"
)

let numberOfFilters = 0
Expand Down

0 comments on commit 34d8f00

Please sign in to comment.