From 03d3a21a7a50954a8bdb413e81759c5f10518f13 Mon Sep 17 00:00:00 2001 From: Elliana May Date: Mon, 2 Oct 2023 08:09:40 +0000 Subject: [PATCH 1/3] fix: uk style date parsing --- api/data.ts | 4 ++-- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/data.ts b/api/data.ts index 4497e040..598f01c1 100644 --- a/api/data.ts +++ b/api/data.ts @@ -3,7 +3,7 @@ import { GoogleSpreadsheet, GoogleSpreadsheetCell } from 'google-spreadsheet'; import _ from 'lodash'; import { DataResponse, Property, StatusMapping } from '../src/types'; import { augment } from '../support'; -import { parseDate } from 'chrono-node'; +import { uk } from 'chrono-node'; async function getProperties(): Promise<{ rows: Partial[]; @@ -31,7 +31,7 @@ async function getProperties(): Promise<{ let value = row[header]; if (header == 'Available') { - value = value ? parseDate(value) : undefined; + value = value ? uk.parseDate(value) : undefined; } else if (header == 'Beds') { value = parseInt(value); } else if (header == 'Interested') { diff --git a/package.json b/package.json index 0ef3fc4c..fc94386d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@vercel/node": "^1.12.1", "axios": "^0.25.0", "cheerio": "^1.0.0-rc.12", - "chrono-node": "^2.3.6", + "chrono-node": "^2.7.0", "date-fns": "^2.28.0", "google-spreadsheet": "^3.2.0", "lodash": "^4.17.21", diff --git a/yarn.lock b/yarn.lock index dac5c9ef..a9da0f86 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4303,10 +4303,10 @@ chrome-trace-event@^1.0.2: dependencies: tslib "^1.9.0" -chrono-node@^2.3.6: - version "2.3.6" - resolved "https://registry.yarnpkg.com/chrono-node/-/chrono-node-2.3.6.tgz#4fab8996f480f37e6ad646c8c9c7e40fe70f8d63" - integrity sha512-nWvpNZJXCfxHs5IfQEXqSYKiLFpz2PHB7SUdc8La2sjoG0S4ifDYLrpICrs/PsSCkZxN+AfVQq11Vd2ex5umjw== +chrono-node@^2.7.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/chrono-node/-/chrono-node-2.7.0.tgz#2c25ed3d810ccd1fceabb630f70922af9600e45e" + integrity sha512-0s2vv89LmsbgoibV0AIVgNnGqlU8N5yCCVZXvc3mRCjnmlG/gJw1hCYOmNwjB+AIuwZQdKTXfwvsHDRTs6pwcg== dependencies: dayjs "^1.10.0" From 714477b4ae3b2cf3ea701acc09d1a55fd945cffb Mon Sep 17 00:00:00 2001 From: Elliana May Date: Mon, 2 Oct 2023 08:10:53 +0000 Subject: [PATCH 2/3] feat: add inspections listing --- api/data.ts | 2 +- api/inspections.ts | 35 +++++++++++++++++++++++++++++++++++ src/Inspections.tsx | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 api/inspections.ts create mode 100644 src/Inspections.tsx diff --git a/api/data.ts b/api/data.ts index 598f01c1..61298720 100644 --- a/api/data.ts +++ b/api/data.ts @@ -5,7 +5,7 @@ import { DataResponse, Property, StatusMapping } from '../src/types'; import { augment } from '../support'; import { uk } from 'chrono-node'; -async function getProperties(): Promise<{ +export async function getProperties(): Promise<{ rows: Partial[]; statusMapping: StatusMapping; }> { diff --git a/api/inspections.ts b/api/inspections.ts new file mode 100644 index 00000000..a938bc76 --- /dev/null +++ b/api/inspections.ts @@ -0,0 +1,35 @@ +import { VercelRequest, VercelResponse } from '@vercel/node'; +import { uk } from 'chrono-node'; +import { getProperties } from './data'; +import { augment } from '../support'; + +export default async function ( + request: VercelRequest, + response: VercelResponse +) { + const { rows, statusMapping } = await getProperties(); + + const today = rows + .filter((prop) => prop['Viewed?']) + .map((prop) => { + const viewed = uk.parseDate(prop['Viewed?']!); + return { ...prop, today: isToday(viewed) }; + }) + .filter(({ today }) => today); + + await augment(today); + + response.json({ today, statusMapping }); +} + +function isToday(date: Date): boolean { + if (!date) { + return false; + } + const today = new Date(); + return ( + date.getDate() === today.getDate() && + date.getMonth() === today.getMonth() && + date.getFullYear() == today.getFullYear() + ); +} diff --git a/src/Inspections.tsx b/src/Inspections.tsx new file mode 100644 index 00000000..e84d0160 --- /dev/null +++ b/src/Inspections.tsx @@ -0,0 +1 @@ +export default function Inspections() {} From 98972cefae82e2595d66c60fe1af895f769c001e Mon Sep 17 00:00:00 2001 From: Elliana May Date: Mon, 2 Oct 2023 08:13:37 +0000 Subject: [PATCH 3/3] feat: add dummy routing --- src/Inspections.tsx | 8 +++++++- src/index.tsx | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Inspections.tsx b/src/Inspections.tsx index e84d0160..0c4f343b 100644 --- a/src/Inspections.tsx +++ b/src/Inspections.tsx @@ -1 +1,7 @@ -export default function Inspections() {} +import useSWR from 'swr'; + +export default function Inspections() { + const { data } = useSWR('/api/inspections'); + + return
`${data}`
; +} diff --git a/src/index.tsx b/src/index.tsx index c1900dd8..5e5d91c3 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -5,6 +5,7 @@ import reportWebVitals from './reportWebVitals'; import { SWRConfig } from 'swr'; import * as Sentry from '@sentry/react'; import { Integrations } from '@sentry/tracing'; +import Inspections from './Inspections'; Sentry.init({ dsn: process.env.REACT_APP_SENTRY_DSN, @@ -16,10 +17,18 @@ Sentry.init({ tracesSampleRate: 1.0, }); +function AppWrapper() { + return window.location.pathname.includes('inspections') ? ( + + ) : ( + + ); +} + ReactDOM.render( - + , document.getElementById('root')