Got the structure of the addresses search page working

This commit is contained in:
Khalim Conn-Kowlessar 2023-05-29 15:35:58 +01:00
parent 71a62f9939
commit 6e99e1b58d
3 changed files with 535 additions and 14 deletions

View file

@ -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",
},
],
};

View file

@ -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 (
<button
type="button"
@ -11,9 +14,7 @@ const SubmitButton = ({ buttonDisabled, onClickFunc }: SubmitButtonProps) => {
onClick={onClickFunc}
className="focus:shadow-outline mt-3 rounded bg-brandtan px-4 py-2 font-bold text-white shadow hover:bg-hovertan focus:outline-none disabled:opacity-25 disabled:hover:bg-hovetan"
>
Submit
Search postcode
</button>
);
};
export default SubmitButton;
}

View file

@ -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 (
<button
type="button"
disabled={buttonDisabled}
onClick={redirectFunc}
className="focus:shadow-outline mt-3 rounded bg-brandtan px-4 py-2 font-bold text-white shadow hover:bg-hovertan focus:outline-none disabled:opacity-25 disabled:hover:bg-brandtan"
>
Select Address
</button>
);
};
export default function Search() {
const [postcode, setPostcode] = useState("");
const [buttonDisabled, setButtonDisabled] = useState(true);
const [data, setData] = useState<null | SearchData>(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<HTMLInputElement>) => {
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 (
<div className="flex min-h-screen flex-col items-center pt-20">
<div className="flex min-h-screen flex-col items-center pt-8">
<div className="w-1/2 flex flex-col justify-center bg-gray-100 rounded p-4 shadow-md">
<div className="w-full flex justify-center text-center mb-7 text-gray-700">
We will search for the most recent data about your property, so we can
@ -120,20 +159,20 @@ export default function Search() {
onKeyDown={handleSubmit}
/>
</div>
<SubmitButton {...submitProps} />
<SearchPostcodeButton {...submitProps} />
</form>
{data && (
<div>
<div className="flex justify-center mt-7">
Select the full address from the list
Scroll to find your address from the list
</div>
<ul className="mt-3 overflow-y-auto flex flex-col items-center">
<ul className="mt-3 overflow-y-auto flex flex-col items-center max-h-60">
{data.rows.map((row: SearchResult) => {
return (
<ToggleAddressButton
key={row["lmk-key"]}
rowKey={row["lmk-key"]}
setButtonDisabled={setToggleDisabled}
setButtonDisabled={setAddressButtonDisabled}
setAddress={setAddress}
setCurrentlyToggled={setCurrentlyToggled}
address={row.address}
@ -146,6 +185,12 @@ export default function Search() {
);
})}
</ul>
<div className="flex justify-end">
<SelectAddressButton
buttonDisabled={addressButtonDisabled}
redirectFunc={redirectToEpc}
/>
</div>
</div>
)}
</div>