mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
get rid of useeffect
This commit is contained in:
parent
de947062bb
commit
2bf5cded94
1 changed files with 21 additions and 17 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState } from "react";
|
||||
|
||||
export type PropertyFilterValues = {
|
||||
address: string;
|
||||
|
|
@ -27,23 +27,27 @@ export default function PropertyFilters({
|
|||
useState<PropertyFilterValues["expected_epc_at_least"]>("");
|
||||
|
||||
/* ----------------------------------------
|
||||
Auto-fix invalid combinations
|
||||
Change handlers (no useEffect)
|
||||
----------------------------------------- */
|
||||
useEffect(() => {
|
||||
if (currentEpc && expectedEpc) {
|
||||
if (epcIndex(expectedEpc) >= epcIndex(currentEpc)) {
|
||||
setExpectedEpc("");
|
||||
}
|
||||
}
|
||||
}, [currentEpc]);
|
||||
function handleCurrentEpcChange(
|
||||
value: PropertyFilterValues["current_epc_at_most"]
|
||||
) {
|
||||
setCurrentEpc(value);
|
||||
|
||||
useEffect(() => {
|
||||
if (currentEpc && expectedEpc) {
|
||||
if (epcIndex(expectedEpc) >= epcIndex(currentEpc)) {
|
||||
setCurrentEpc("");
|
||||
}
|
||||
if (value && expectedEpc && epcIndex(expectedEpc) >= epcIndex(value)) {
|
||||
setExpectedEpc("");
|
||||
}
|
||||
}, [expectedEpc]);
|
||||
}
|
||||
|
||||
function handleExpectedEpcChange(
|
||||
value: PropertyFilterValues["expected_epc_at_least"]
|
||||
) {
|
||||
setExpectedEpc(value);
|
||||
|
||||
if (value && currentEpc && epcIndex(value) >= epcIndex(currentEpc)) {
|
||||
setCurrentEpc("");
|
||||
}
|
||||
}
|
||||
|
||||
function apply() {
|
||||
onApply({
|
||||
|
|
@ -115,7 +119,7 @@ export default function PropertyFilters({
|
|||
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm
|
||||
bg-white focus:outline-none focus:ring-2 focus:ring-black/10"
|
||||
value={currentEpc}
|
||||
onChange={(e) => setCurrentEpc(e.target.value as any)}
|
||||
onChange={(e) => handleCurrentEpcChange(e.target.value as any)}
|
||||
>
|
||||
<option value="">Any</option>
|
||||
{["C", "D", "E", "F", "G"].map((epc) => (
|
||||
|
|
@ -139,7 +143,7 @@ export default function PropertyFilters({
|
|||
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm
|
||||
bg-white focus:outline-none focus:ring-2 focus:ring-black/10"
|
||||
value={expectedEpc}
|
||||
onChange={(e) => setExpectedEpc(e.target.value as any)}
|
||||
onChange={(e) => handleExpectedEpcChange(e.target.value as any)}
|
||||
>
|
||||
<option value="">Any</option>
|
||||
{["A", "B", "C", "D"].map((epc) => (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue