diff --git a/package-lock.json b/package-lock.json index a18857fa..5ca27d4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@headlessui/react": "^1.7.14", "@heroicons/react": "^2.0.18", + "@tanstack/react-query": "^4.29.12", "@types/node": "20.2.3", "@types/react": "18.2.7", "@types/react-dom": "18.2.4", @@ -422,6 +423,41 @@ "tslib": "^2.4.0" } }, + "node_modules/@tanstack/query-core": { + "version": "4.29.11", + "resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-4.29.11.tgz", + "integrity": "sha512-8C+hF6SFAb/TlFZyS9FItgNwrw4PMa7YeX+KQYe2ZAiEz6uzg6yIr+QBzPkUwZ/L0bXvGd1sufTm3wotoz+GwQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, + "node_modules/@tanstack/react-query": { + "version": "4.29.12", + "resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-4.29.12.tgz", + "integrity": "sha512-zhcN6+zF6cxprxhTHQajHGlvxgK8npnp9uLe9yaWhGc6sYcPWXzyO4raL4HomUzQOPzu3jLvkriJQ7BOrDM8vA==", + "dependencies": { + "@tanstack/query-core": "4.29.11", + "use-sync-external-store": "^1.2.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0", + "react-native": "*" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + }, + "react-native": { + "optional": true + } + } + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -4312,6 +4348,14 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz", + "integrity": "sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 41832c29..b27abb65 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "dependencies": { "@headlessui/react": "^1.7.14", "@heroicons/react": "^2.0.18", + "@tanstack/react-query": "^4.29.12", "@types/node": "20.2.3", "@types/react": "18.2.7", "@types/react-dom": "18.2.4", diff --git a/src/app/ReactQueryProvider.tsx b/src/app/ReactQueryProvider.tsx new file mode 100644 index 00000000..f003a391 --- /dev/null +++ b/src/app/ReactQueryProvider.tsx @@ -0,0 +1,15 @@ +"use client"; + +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; + +const queryClient = new QueryClient(); + +export const ReactQueryProvider = ({ + children, +}: { + children: React.ReactNode; +}) => { + return ( + {children} + ); +}; diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 75d5a810..44c422b4 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -21,776 +21,11 @@ export async function GET(request: NextRequest) { Authorization: `Basic ${process.env.EPC_AUTH_TOKEN ?? ""}`, }; - // const response = await fetch(url, { - // headers: headers, - // next: { revalidate: 60 }, - // }); - // const data = await response.json(); - console.log("PUT ME BACK"); - const data = { - rows: [ - { - "low-energy-fixed-light-count": "1", - address: "53 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "1172153279062017040516522305558463", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "55 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "117215937906201704320516522305558463", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "10 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "11721593790620170405165223055583123", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "10 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "dsdw11721593790620170405165223055583123", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "10 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "11fewde721593790620170405165223055583123", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "10 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "117215937906201704051fe432265223055583123", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "10 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "117215937906201704051611115223055583123", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - { - "low-energy-fixed-light-count": "1", - address: "10 Distillery Wharf, Regatta Lane", - "uprn-source": "Address Matched", - "floor-height": "", - "heating-cost-potential": "142", - "unheated-corridor-length": "", - "hot-water-cost-potential": "96", - "construction-age-band": "NO DATA!", - "potential-energy-rating": "B", - "mainheat-energy-eff": "Very Good", - "windows-env-eff": "Very Good", - "lighting-energy-eff": "Very Good", - "environment-impact-potential": "91", - "glazed-type": "NO DATA!", - "heating-cost-current": "142", - address3: "", - "mainheatcont-description": - "Charging system linked to use of community heating, TRVs", - "sheating-energy-eff": "N/A", - "property-type": "Flat", - "local-authority-label": "Hammersmith and Fulham", - "fixed-lighting-outlets-count": "1", - "energy-tariff": "standard tariff", - "mechanical-ventilation": "NO DATA!", - "hot-water-cost-current": "96", - county: "Greater London Authority", - postcode: "W6 9BF", - "solar-water-heating-flag": "", - constituency: "E14000726", - "co2-emissions-potential": "0.8", - "number-heated-rooms": "", - "floor-description": "Average thermal transmittance 0.19 W/m-¦K", - "energy-consumption-potential": "50", - "local-authority": "E09000013", - "built-form": "Mid-Terrace", - "number-open-fireplaces": "0", - "windows-description": "High performance glazing", - "glazed-area": "NO DATA!", - "inspection-date": "2017-04-05", - "mains-gas-flag": "", - "co2-emiss-curr-per-floor-area": "9", - address1: "53 Distillery Wharf", - "heat-loss-corridor": "NO DATA!", - "flat-storey-count": "", - "constituency-label": "Hammersmith", - "roof-energy-eff": "N/A", - "total-floor-area": "89.0", - "building-reference-number": "6013745278", - "environment-impact-current": "91", - "co2-emissions-current": "0.8", - "roof-description": "(other premises above)", - "floor-energy-eff": "Very Good", - "number-habitable-rooms": "", - address2: "Regatta Lane", - "hot-water-env-eff": "Very Good", - posttown: "LONDON", - "mainheatc-energy-eff": "Good", - "main-fuel": "NO DATA!", - "lighting-env-eff": "Very Good", - "windows-energy-eff": "Very Good", - "floor-env-eff": "Very Good", - "sheating-env-eff": "N/A", - "lighting-description": "Low energy lighting in all fixed outlets", - "roof-env-eff": "N/A", - "walls-energy-eff": "Very Good", - "photo-supply": "", - "lighting-cost-potential": "58", - "mainheat-env-eff": "Very Good", - "multi-glaze-proportion": "", - "main-heating-controls": "", - "lodgement-datetime": "2017-04-05 16:52:23", - "flat-top-storey": "", - "current-energy-rating": "B", - "secondheat-description": "None", - "walls-env-eff": "Very Good", - "transaction-type": "new dwelling", - uprn: "34154017", - "current-energy-efficiency": "86", - "energy-consumption-current": "50", - "mainheat-description": "Community scheme", - "lighting-cost-current": "58", - "lodgement-date": "2017-04-05", - "extension-count": "", - "mainheatc-env-eff": "Good", - "lmk-key": "117215937906201704051652230550000583123", - "wind-turbine-count": "", - tenure: "unknown", - "floor-level": "mid floor", - "potential-energy-efficiency": "86", - "hot-water-energy-eff": "Very Good", - "low-energy-lighting": "100", - "walls-description": "Average thermal transmittance 0.16 W/m-¦K", - "hotwater-description": "Community scheme", - }, - ], - }; + const response = await fetch(url, { + headers: headers, + next: { revalidate: 120 }, + }); + const data = await response.json(); // Handle the response from the external API and return it return NextResponse.json(data); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f82ec1fd..2b3a3685 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,6 +1,8 @@ import "./globals.css"; import Provider from "./components/Provider"; import Nav from "./components/Navbar"; +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { ReactQueryProvider } from "./ReactQueryProvider"; export const metadata = { title: "", @@ -20,8 +22,10 @@ export default function RootLayout({ - - {children} + + + {children} + diff --git a/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx b/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx index 187d9b6e..b92c1343 100644 --- a/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx +++ b/src/app/portfolio/[slug]/property/[lmkKey]/page.tsx @@ -4,13 +4,70 @@ import { useState } from "react"; import { Dialog } from "@headlessui/react"; import Link from "next/link"; import { ArrowLeftIcon } from "@heroicons/react/24/outline"; +import { SearchData } from "@/types/epc"; +import { useRouter } from "next/navigation"; +import { useQuery } from "@tanstack/react-query"; + +const EpcDefaults = { + G: "C", + F: "C", + E: "C", + D: "C", + C: "B", + B: "A", + A: "A", +}; + +async function fetchData(postcode: string): Promise { + // TODO - add strict typing to the api response + + const response = await fetch(`/api/search?postcode=${postcode}`); + + if (!response.ok) { + // This will activate the closest `error.js` Error Boundary + throw new Error("Failed to fetch data"); + } + + return response.json(); +} + +export default function PropertyPage({ + params, + searchParams, +}: { + params: { slug: string; lmkKey: string }; + searchParams: { [key: string]: string | string[] | undefined }; +}) { + const router = useRouter(); -const PropertyPage = ({ params }: { params: { slug: string } }) => { const portfolioId = params.slug; + const lmkKey = params.lmkKey; + const postcode = searchParams.postcode; + + if (postcode === undefined) { + router.push(`/portfolio/${portfolioId}/error`); + } const [isEditModalOpen, setIsEditModalOpen] = useState(false); const [isDetailModalOpen, setIsDetailModalOpen] = useState(false); + const { data, error, isLoading } = useQuery({ + queryKey: ["search", postcode], + queryFn: async () => fetchData(postcode as string), + }); + + // TODO: Add a loading state and error handling + if (isLoading) { + return
Loading...
; + } + + if (error) { + return
Error fetching data: {error.message}
; + } + + const propertyData = data.rows.filter((row) => row["lmk-key"] === lmkKey)[0]; + const currentEpcRating = propertyData["current-energy-rating"]; + const handleEditClick = () => { setIsEditModalOpen(true); }; @@ -18,19 +75,13 @@ const PropertyPage = ({ params }: { params: { slug: string } }) => { const handleDetailClick = () => { setIsDetailModalOpen(true); }; + // NextJS docs recomment fetching data directly in the component that needs it, + // even if requeting the same data in multiple components. rather than passing data between + // components as props return (
- {/* -
- - Back to portfolio -
- */}
@@ -40,12 +91,12 @@ const PropertyPage = ({ params }: { params: { slug: string } }) => {

Your Property

-

123 Main St, City, State

+

{propertyData.address}

Current EPC rating

-

Rating: A

+

Rating: {currentEpcRating}

{ onClick={handleEditClick} >

Target EPC rating

-

Rating: B

+

Rating: {EpcDefaults[currentEpcRating]}

@@ -115,6 +166,4 @@ const PropertyPage = ({ params }: { params: { slug: string } }) => {
); -}; - -export default PropertyPage; +} diff --git a/src/app/portfolio/[slug]/search/page.tsx b/src/app/portfolio/[slug]/search/page.tsx index 2bada9f6..1690d57a 100644 --- a/src/app/portfolio/[slug]/search/page.tsx +++ b/src/app/portfolio/[slug]/search/page.tsx @@ -69,7 +69,9 @@ export default function Search({ params }: { params: { slug: string } }) { const portfolioId = params.slug; const lmkKey = res["lmk-key"]; - router.push(`/portfolio/${portfolioId}/property/${lmkKey}`); + router.push( + `/portfolio/${portfolioId}/property/${lmkKey}?postcode=${postcode}` + ); }; const submitProps = { diff --git a/src/types/epc.ts b/src/types/epc.ts index 650c7374..aa094add 100644 --- a/src/types/epc.ts +++ b/src/types/epc.ts @@ -75,7 +75,7 @@ type SearchResult = { "main-heating-controls": string; "lodgement-datetime": string; "flat-top-storey": string; - "current-energy-rating": string; + "current-energy-rating": "A" | "B" | "C" | "D" | "E" | "F" | "G"; "secondheat-description": string; "walls-env-eff": string; "transaction-type": string;