Skip to content

Commit

Permalink
todo: Add Area search filter
Browse files Browse the repository at this point in the history
refs #49
  • Loading branch information
franthormel committed Aug 17, 2024
1 parent fe78717 commit 03babd2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
10 changes: 10 additions & 0 deletions app/listings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ export const BEDS_BATHS_FILTER = ["Any", "1", "2", "3", "4", "5+"];
* * Default value is `Any`
*/
export const BEDS_BATHS_DEFAULT = 0;

export const AREA_DEFAULT_INPUT_MIN_FILTER = 0;
/**
* Placeholder value for maximum area input field.
*/
export const AREA_DEFAULT_MAX_FILTER = 1_000;
/**
* Maximum input value for the maximum area input field.
*/
export const AREA_INPUT_MAX_FILTER = 1_000_000;
8 changes: 3 additions & 5 deletions app/listings/filters-area.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import Dropdown from "@/components/dropdown"
import FormInput from "@/components/form-input"
import { formatAppend } from "@/lib/formatter/number"
import { useState } from "react"
import { AREA_DEFAULT_MAX_FILTER } from "./constants"

export default function ListingsFilterArea() {
const DEFAULT_MAX = 20

const minAreaPlaceholder = "None"
const maxAreaPlaceholder = formatAppend(DEFAULT_MAX, "sqm.")
const maxAreaPlaceholder = formatAppend(AREA_DEFAULT_MAX_FILTER, "sqm.")

const [displayDropdown, setDisplayDropdown] = useState<boolean>(false)

Expand All @@ -27,7 +25,7 @@ export default function ListingsFilterArea() {
<div className="flex w-24 flex-col gap-5 xl:w-56">
<FormInput label="Minimum Area"
name="area-min"
placeholder={minAreaPlaceholder} />
placeholder="None" />
<FormInput label="Maximum Area"
name="area-min"
placeholder={maxAreaPlaceholder} />
Expand Down
42 changes: 36 additions & 6 deletions app/listings/provider.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
"use client"

import { createContext, useState } from "react"
import { BEDS_BATHS_DEFAULT, PRICE_MAX_FILTER, PRICE_MIN_FILTER, STARTING_PAGE } from "./constants"
import { AREA_DEFAULT_INPUT_MIN_FILTER, AREA_DEFAULT_MAX_FILTER, BEDS_BATHS_DEFAULT, PRICE_MAX_FILTER, PRICE_MIN_FILTER, STARTING_PAGE } from "./constants"

type ContextTypeNumber = {
value: number,
change: (value: number) => void
}

type ContenTypeNumberRange = {
min: ContextTypeNumber,
max: ContextTypeNumber
}

interface ListingsContextInterface {
searchFilters: {
price: {
min: ContextTypeNumber,
max: ContextTypeNumber
},
price: ContenTypeNumberRange,
beds: ContextTypeNumber,
baths: ContextTypeNumber
baths: ContextTypeNumber,
area: ContenTypeNumberRange
},
pagination: {
changeToPreviousPage: () => void,
Expand Down Expand Up @@ -44,6 +47,16 @@ export const ListingsContext = createContext<ListingsContextInterface>({
value: BEDS_BATHS_DEFAULT,
change: (value) => { }
},
area: {
min: {
value: AREA_DEFAULT_INPUT_MIN_FILTER,
change: (value) => { }
},
max: {
value: AREA_DEFAULT_MAX_FILTER,
change: (value) => { }
}
},
},
pagination: {
changeToPreviousPage: () => { },
Expand All @@ -62,6 +75,9 @@ export default function ListingsProvider({ children }: { children: React.ReactNo
const [bedsFilter, setBedsFilter] = useState<number>(BEDS_BATHS_DEFAULT)
const [bathsFilter, setBathsFilter] = useState<number>(BEDS_BATHS_DEFAULT)

const [minAreaFilter, setMinAreaFilter] = useState<number>(AREA_DEFAULT_INPUT_MIN_FILTER)
const [maxAreaFilter, setMaxAreaFilter] = useState<number>(AREA_DEFAULT_MAX_FILTER)

const [currentPage, setCurrentPage] = useState<number>(STARTING_PAGE);

const stateValue: ListingsContextInterface = {
Expand Down Expand Up @@ -91,6 +107,20 @@ export default function ListingsProvider({ children }: { children: React.ReactNo
change: (value) => {
setBathsFilter(value)
}
},
area: {
min: {
value: minAreaFilter,
change: (value) => {
setMinAreaFilter(value)
}
},
max: {
value: maxAreaFilter,
change: (value) => {
setMaxAreaFilter(value)
}
}
}
},
pagination: {
Expand Down
1 change: 1 addition & 0 deletions app/listings/search-filters-modal-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ListingsFilterPrice from "./filter-price";
import ListingsFilterArea from "./filters-area";

export default function ListingsSearchFiltersModalContent() {
// TODO: Fix display of search filters
return (
<div className="flex flex-col gap-8 p-8">
<header className="text-2xl font-bold">
Expand Down

0 comments on commit 03babd2

Please sign in to comment.