Skip to content

Commit

Permalink
updates for cache revalidation on the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmalbert committed Jul 2, 2021
1 parent 6ca739d commit fc6d210
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ All notable changes to this project will be documented in this file. The format
- Add Rankings and Results section to listing management ([#1433](https://github.com/bloom-housing/bloom/pull/1433)) (Emily Jablonski)
- Add Application Address section to listing management ([#1425](https://github.com/bloom-housing/bloom/pull/1425)) (Emily Jablonski)
- Add Application Dates section to listing management ([#1432](https://github.com/bloom-housing/bloom/pull/1432)) (Emily Jablonski)
- Adds cache revalidation to frontend public app

- Fixed:

Expand Down
3 changes: 3 additions & 0 deletions backend/core/src/listings/listings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ export class ListingsController {
@ApiOperation({ summary: "Get listing by id", operationId: "retrieve" })
@UseInterceptors(CacheInterceptor)
async retrieve(@Param("listingId") listingId: string): Promise<ListingDto> {
if (listingId === undefined || listingId === "undefined") {
return mapTo(ListingDto, {})
}
const result = mapTo(ListingDto, await this.listingsService.findOne(listingId))

return result
Expand Down
2 changes: 2 additions & 0 deletions sites/public/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ MAPBOX_TOKEN=pk.eyJ1IjoibWplZHJhcyIsImEiOiJjazI2OHA5YzQycTBpM29xdDVwbXNyMDlwIn0.
LANGUAGES=en,es,zh,vi
IDLE_TIMEOUT=5
COUNTY_CODE=Alameda
# next js cache revalidate
CACHE_REVALIDATE=60

# this GTM key is for local development only
GTM_KEY=GTM-KF22FJP
3 changes: 3 additions & 0 deletions sites/public/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module.exports = withCSS(
gtmKey: process.env.GTM_KEY || null,
idleTimeout: process.env.IDLE_TIMEOUT,
countyCode: process.env.COUNTY_CODE,
cacheRevalidate: process.env.CACHE_REVALIDATE
? Number(process.env.CACHE_REVALIDATE)
: 60,
},
i18n: {
locales: process.env.LANGUAGES ? process.env.LANGUAGES.split(",") : ["en"],
Expand Down
2 changes: 1 addition & 1 deletion sites/public/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ export async function getStaticProps() {
console.error(error)
}

return { props: { listings }, revalidate: 60 }
return { props: { listings }, revalidate: process.env.cacheRevalidate }
}
12 changes: 8 additions & 4 deletions sites/public/pages/listing/[id]/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ import { imageUrlFromListing, t } from "@bloom-housing/ui-components"
import Layout from "../../../layouts/application"
import { ListingView } from "../../../src/ListingView"
import { MetaTags } from "../../../src/MetaTags"
import { ErrorPage } from "../../_error"

interface ListingProps {
listing: Listing
}

export default function ListingPage(props: ListingProps) {
const { listing } = props

if (!listing) {
return <ErrorPage />
}

const pageTitle = `${listing.name} - ${t("nav.siteTitle")}`
const metaDescription = t("pageDescription.listing", {
regionName: t("region.name"),
Expand Down Expand Up @@ -57,14 +63,12 @@ export async function getStaticPaths(context: { locales: Array<string> }) {
}

export async function getStaticProps(context: { params: Record<string, string> }) {
const response = await axios.get(
`${process.env.backendApiBase}/listings/${context.params.id}?filter[$comparison]=<>&filter[status]=pending`
)
const response = await axios.get(`${process.env.backendApiBase}/listings/${context.params.id}`)

return {
props: {
listing: response.data,
},
revalidate: 60,
revalidate: process.env.cacheRevalidate,
}
}
2 changes: 1 addition & 1 deletion sites/public/pages/listings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ export async function getStaticProps() {
console.error(error)
}

return { props: { openListings, closedListings }, revalidate: 60 }
return { props: { openListings, closedListings }, revalidate: process.env.cacheRevalidate }
}
5 changes: 5 additions & 0 deletions sites/public/src/ListingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
ReferralApplication,
} from "@bloom-housing/ui-components"
import moment from "moment"
import { ErrorPage } from "../pages/_error"

interface ListingProps {
listing: Listing
Expand All @@ -45,6 +46,10 @@ export const ListingView = (props: ListingProps) => {
let buildingSelectionCriteria, preferencesSection
const { listing, preview = false } = props

if (!listing) {
return <ErrorPage />
}

const oneLineAddress = <OneLineAddress address={listing.buildingAddress} />

const googleMapsHref =
Expand Down

0 comments on commit fc6d210

Please sign in to comment.