diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 292adc4..75d5a81 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -314,6 +314,481 @@ export async function GET(request: NextRequest) { "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", + }, ], }; diff --git a/src/app/components/search/SubmitButton.tsx b/src/app/components/search/SearchPostcodeButton.tsx similarity index 68% rename from src/app/components/search/SubmitButton.tsx rename to src/app/components/search/SearchPostcodeButton.tsx index e2e0428..971be56 100644 --- a/src/app/components/search/SubmitButton.tsx +++ b/src/app/components/search/SearchPostcodeButton.tsx @@ -1,9 +1,12 @@ -interface SubmitButtonProps { +interface SearchPostcodeButtonProps { buttonDisabled: boolean; onClickFunc: () => void; } -const SubmitButton = ({ buttonDisabled, onClickFunc }: SubmitButtonProps) => { +export default function SearchPostcodeButton({ + buttonDisabled, + onClickFunc, +}: SearchPostcodeButtonProps) { return ( ); -}; - -export default SubmitButton; +} diff --git a/src/app/search/page.tsx b/src/app/search/page.tsx index 3d98970..7a649c9 100644 --- a/src/app/search/page.tsx +++ b/src/app/search/page.tsx @@ -1,7 +1,7 @@ "use client"; import { useState } from "react"; -import SubmitButton from "../components/search/SubmitButton"; +import SearchPostcodeButton from "../components/search/SearchPostcodeButton"; import { useRouter } from "next/navigation"; import { SearchData, SearchResult } from "@/types/epc"; @@ -43,12 +43,33 @@ function ToggleAddressButton({ ); } +interface SelectAddressButtonProps { + buttonDisabled: boolean; + redirectFunc: () => void; +} + +const SelectAddressButton = ({ + buttonDisabled, + redirectFunc, +}: SelectAddressButtonProps) => { + return ( + + ); +}; + export default function Search() { const [postcode, setPostcode] = useState(""); const [buttonDisabled, setButtonDisabled] = useState(true); const [data, setData] = useState(null); const [address, setAddress] = useState(""); - const [toggleDisabled, setToggleDisabled] = useState(true); + const [addressButtonDisabled, setAddressButtonDisabled] = useState(true); // Keep track of which lmk-key is currently toggled. Initially, none // are toggled const [currentlyToggled, setCurrentlyToggled] = useState(""); @@ -63,7 +84,9 @@ export default function Search() { const handleSubmit = (e: React.KeyboardEvent) => { if (e.key === "Enter") { e.preventDefault(); - redirectToSearch(); + fetchData().catch((error) => { + console.log(error); + }); } }; @@ -78,8 +101,11 @@ export default function Search() { return; }; + // TODO: This might take a moment to fetch data, add a loading state? async function fetchData() { // TODO - add strict typing to the api response + setCurrentlyToggled(""); + setAddressButtonDisabled(true); try { const response = await fetch(`/api/search?postcode=${postcode}`); const data = (await response.json()) as SearchData; @@ -90,13 +116,26 @@ export default function Search() { } } + const redirectToEpc = () => { + if (data === null) return; + + const res = data.rows.find( + (row: SearchResult) => row["lmk-key"] === currentlyToggled + ); + + const portfolioId = "portfolioId"; + const propertyId = "propertyId"; + + router.push(`/portfolio/${portfolioId}/property/${propertyId}`); + }; + const submitProps = { buttonDisabled: buttonDisabled, onClickFunc: fetchData, }; return ( -
+
We will search for the most recent data about your property, so we can @@ -120,20 +159,20 @@ export default function Search() { onKeyDown={handleSubmit} />
- + {data && (
- Select the full address from the list + Scroll to find your address from the list
-
    +
      {data.rows.map((row: SearchResult) => { return ( +
      + +
)}