Skip to content

Commit

Permalink
[feat] pull and display all plants (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Catherine Tan <[email protected]>
Co-authored-by: rachaelch3n <[email protected]>
Co-authored-by: Catherine Tan <[email protected]>
  • Loading branch information
4 people authored Oct 21, 2024
1 parent 8fe8603 commit 1811a59
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 24 deletions.
14 changes: 0 additions & 14 deletions api/supabase/queries/plantSeasonality.ts

This file was deleted.

8 changes: 8 additions & 0 deletions api/supabase/queries/plants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Plant } from '@/types/schema';
import supabase from '../createClient';

export async function getAllPlants(): Promise<Plant[]> {
const { data, error } = await supabase.from('plants').select('*');
if (error) throw new Error(`Error fetching all plants: ${error.message}`);
return data;
}
60 changes: 60 additions & 0 deletions app/seasonal-planting-guide/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'use client';

import React from 'react';
// import FilterDropdown from '@/components/FilterDropdown';
import { PlantList } from '@/components/PlantList';

// interface SeasonalPlantingGuideProps {}

const SeasonalPlantingGuide = () => {
// hide this for now, will be used in the next PR for dropdown filters

// const growingSeasonOptions = ['Spring', 'Summer', 'Fall', 'Winter'];
// const harvestSeasonOptions = ['Spring', 'Summer', 'Fall', 'Winter'];
// const plantingTypeOptions = [
// 'Start Seeds Indoors',
// 'Start Seeds Outdoors',
// 'Plant Seedlings/Transplant Outdoors',
// ];

// const [growingSeason, setGrowingSeason] = useState<string>('');
// const [harvestSeason, setHarvestSeason] = useState<string>('');
// const [plantingType, setPlantingType] = useState<string>('');

return (
//hide filter dropdowns for now, will be done in another PR
<div>
{/* <FilterDropdown
name="growingSeason"
id="growingSeason"
setStateAction={setGrowingSeason}
options={growingSeasonOptions}
placeholder="Growing Season"
/>
<FilterDropdown
name="harvestSeason"
id="harvestSeason"
setStateAction={setHarvestSeason}
options={harvestSeasonOptions}
placeholder="Harvest Season"
/>
<FilterDropdown
name="plantingType"
id="plantingType"
setStateAction={setPlantingType}
options={plantingTypeOptions}
placeholder="Planting Type"
/> */}

<PlantList
// growing_season={growingSeason}
// harvest_season={harvestSeason}
// planting_type={plantingType}
/>
</div>
);
};

export default SeasonalPlantingGuide;
10 changes: 7 additions & 3 deletions components/PlantList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React, { useEffect, useState } from 'react';
import { getPlantSeasonality } from '@/api/supabase/queries/plantSeasonality';
import { getAllPlants } from '@/api/supabase/queries/plants';
import { Plant } from '@/types/schema';

export const PlantList = () => {
const [plants, setPlants] = useState<Plant[]>([]);

useEffect(() => {
const fetchPlantSeasonality = async () => {
const plantList = await getPlantSeasonality('Tennessee');
setPlants(plantList);
const plantList = await getAllPlants();
const us_state = 'TENNESSEE';
const filteredPlantList = plantList.filter(
plant => plant.us_state === us_state,
);
setPlants(filteredPlantList);
};

fetchPlantSeasonality();
Expand Down
18 changes: 11 additions & 7 deletions types/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type { UUID } from 'crypto';

export type Season = 'SPRING' | 'SUMMER' | 'FALL' | 'WINTER';
export type SeasonEnum = 'SPRING' | 'SUMMER' | 'FALL' | 'WINTER';

export type DifficultyLevelEnum = 'EASY' | 'MODERATE' | 'HARD';

export interface Plant {
id: UUID;
plant_name: string;
state: string;
harvest_season: Season;
water_num_times_per_week: number;
us_state: string;
harvest_season: SeasonEnum;
water_frequency: string;
weeding_frequency: string;
plant_seed_indoors_start: string;
plant_seed_indoors_end: string;
plant_seed_outdoors_start: string;
Expand All @@ -16,9 +19,10 @@ export interface Plant {
plant_transplant_end: string;
harvest_start: string;
harvest_end: string;
water_inches_per_week: number;
harvest_days_after_plant: number;
sunlight_required: string;
beginner_friendly: boolean;
plant_tips: string;
img: string;
difficulty_level: DifficultyLevelEnum;
sunlight_min_hours: int;
sunlight_max_hours: int;
}

0 comments on commit 1811a59

Please sign in to comment.