Skip to content

Commit

Permalink
adding clear filters button to FilterDropdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezryr committed Oct 20, 2024
1 parent 6ca499b commit 33bea10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions app/seasonal-planting-guide/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import React, { useState } from 'react';
import FilterDropdown from '@/components/FilterDropdown';
import { PlantList } from '@/components/PlantList';

interface SeasonalPlantingGuideProps {}

const SeasonalPlantingGuide = (props: SeasonalPlantingGuideProps) => {
const SeasonalPlantingGuide = () => {
const growingSeasonOptions = ['Spring', 'Summer', 'Fall', 'Winter'];
const harvestSeasonOptions = ['Spring', 'Summer', 'Fall', 'Winter'];
const plantingTypeOptions = [
Expand All @@ -19,11 +17,18 @@ const SeasonalPlantingGuide = (props: SeasonalPlantingGuideProps) => {
const [harvestSeason, setHarvestSeason] = useState<string>('');
const [plantingType, setPlantingType] = useState<string>('');

const clearFilters = () => {
setGrowingSeason('');
setHarvestSeason('');
setPlantingType('');
};

return (
<div>
<FilterDropdown
name="growingSeason"
id="growingSeason"
value={growingSeason}
setStateAction={setGrowingSeason}
options={growingSeasonOptions}
placeholder="Growing Season"
Expand All @@ -32,6 +37,7 @@ const SeasonalPlantingGuide = (props: SeasonalPlantingGuideProps) => {
<FilterDropdown
name="harvestSeason"
id="harvestSeason"
value={harvestSeason}
setStateAction={setHarvestSeason}
options={harvestSeasonOptions}
placeholder="Harvest Season"
Expand All @@ -40,11 +46,14 @@ const SeasonalPlantingGuide = (props: SeasonalPlantingGuideProps) => {
<FilterDropdown
name="plantingType"
id="plantingType"
value={plantingType}
setStateAction={setPlantingType}
options={plantingTypeOptions}
placeholder="Planting Type"
/>

<button onClick={clearFilters}>Clear filters</button>

<PlantList
growing_season={growingSeason}
harvest_season={harvestSeason}
Expand Down
4 changes: 3 additions & 1 deletion components/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useState } from 'react';
interface FilterDropdownProps {
name: string;
id: string;
value: string;
setStateAction: React.SetStateAction<any>;

Check failure on line 7 in components/FilterDropdown.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

Unexpected any. Specify a different type

Check failure on line 7 in components/FilterDropdown.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

Unexpected any. Specify a different type
options: string[];
placeholder: string;
Expand All @@ -27,9 +28,10 @@ export default function FilterDropdown(props: FilterDropdownProps) {
onChange={handleChange}
onClick={handleToggle}
onBlur={() => setIsOpen(false)}
value={props.value}
>
{/*Default placeholder text*/}
<option disabled={true} selected={true} hidden={true}>
<option value="" disabled hidden>
{props.placeholder}
</option>
{props.options.map((option, index) => (
Expand Down

0 comments on commit 33bea10

Please sign in to comment.