diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 43f2fe7..292adc4 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -1,25 +1,3 @@ -// export async function getEPCData(postcode: string) { -// const url = `https://epc.opendatacommunities.org/api/v1/domestic/search?postcode=${postcode}&size=1000`; - -// const headers = { -// Accept: "application/json", -// Authorization: `Basic ${process.env.EPC_AUTH_TOKEN ?? ""}`, -// }; - -// console.log("Fetching EPC data from:", headers); - -// try { -// const response = await fetch(url, { headers }); -// if (!response.ok) { -// throw new Error(`HTTP error! status: ${response.status}`); -// } -// return await response.json(); -// } catch (error) { -// console.error("Failed to fetch EPC data:", error); -// throw error; -// } -// } - import { NextRequest, NextResponse } from "next/server"; export async function GET(request: NextRequest) { @@ -43,11 +21,301 @@ 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(); + // 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", + }, + ], + }; // Handle the response from the external API and return it return NextResponse.json(data); diff --git a/src/app/search/page.tsx b/src/app/search/page.tsx index 820da2a..5760f47 100644 --- a/src/app/search/page.tsx +++ b/src/app/search/page.tsx @@ -3,11 +3,55 @@ import { useState } from "react"; import SubmitButton from "../components/search/SubmitButton"; import { useRouter } from "next/navigation"; +import { SearchData, SearchResult } from "@/types/epc"; + +const defaultToggleClass = + "mb-1 block max-w-sm rounded-lg border border-gray-200 bg-white p-6 shadow hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700"; + +const toggledButtonClass = + "text-white mb-1 block max-w-sm rounded-lg border border-gray-200 bg-brandblue p-6 shadow hover:bg-hoverblue dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700"; + +interface ToggleAddressButtonProps { + rowKey: string; + setButtonDisabled: (value: boolean) => void; + setAddress: (value: string) => void; + setCurrentlyToggled: (value: string) => void; + toggleClassName: string; + address: string; +} + +function ToggleAddressButton({ + rowKey, + setButtonDisabled, + setAddress, + setCurrentlyToggled, + toggleClassName, + address, +}: ToggleAddressButtonProps) { + const handleOnClick = () => { + setCurrentlyToggled(rowKey); + setAddress(address); + setButtonDisabled(false); + }; + + return ( +