-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f243253
commit 7cc4a5b
Showing
5 changed files
with
113 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,110 @@ | ||
'use client'; | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { UUID } from 'crypto'; | ||
import supabase from '@/api/supabase/createClient'; | ||
import { get_plant_by_id } from '@/api/supabase/queries/plant_by_id'; | ||
import { getPlantSeasonality } from '@/api/supabase/queries/plantSeasonality'; | ||
import PlantCard from '@/components/PlantCard/PlantCard'; | ||
import { Plant } from '@/types/schema'; | ||
|
||
export default function Home() { | ||
const plant: Plant = { | ||
id: '3067b896-ba05-45b0-bb5c-e09277cf1e68', | ||
plant_name: 'tomato', | ||
state: 'tennessee', | ||
harvest_season: 'SPRING', | ||
water_num_times_per_week: 7, | ||
plant_seed_indoors_start: 'January', | ||
plant_seed_indoors_end: 'February', | ||
plant_seed_outdoors_start: 'March', | ||
plant_seed_outdoors_end: 'April', | ||
plant_transplant_start: 'April', | ||
plant_transplant_end: 'May', | ||
harvest_start: 'April', | ||
harvest_end: 'May', | ||
water_inches_per_week: 7, | ||
harvest_days_after_plant: 5, | ||
sunlight_required: 'Yes', | ||
beginner_friendly: true, | ||
plant_tips: 'aerg', | ||
const [selectedOption, setSelectedOption] = useState<'myPlants' | 'all'>( | ||
'myPlants', | ||
); | ||
const [isSelected, setIsSelected] = useState<true | false>(false); | ||
|
||
const [plants, setPlants] = useState<Plant[]>([]); | ||
const [userPlants, setUserPlants] = useState<Plant[]>([]); | ||
const user_id: UUID = 'e72af66d-7aae-45f6-935a-187197749d9f'; | ||
async function fetchUserPlants(user_id: UUID) { | ||
const { data, error } = await supabase | ||
.from('user_plants') | ||
.select('plant_id') | ||
.eq('user_id', user_id); | ||
|
||
if (error) { | ||
console.error('Error fetching plant IDs:', error); | ||
return []; | ||
} | ||
|
||
const plantIds = data?.map(row => row.plant_id) || []; | ||
if (plantIds.length === 0) { | ||
return []; | ||
} | ||
|
||
const plantsUser: Plant[] = await Promise.all( | ||
plantIds.map(plantId => get_plant_by_id('Tennessee', plantId)), | ||
); | ||
return plantsUser; | ||
} | ||
useEffect(() => { | ||
const fetchPlantSeasonality = async () => { | ||
const plantList = await getPlantSeasonality('Tennessee'); | ||
setPlants(plantList); | ||
}; | ||
|
||
fetchPlantSeasonality(); | ||
}, []); | ||
useEffect(() => { | ||
const fetchData = async () => { | ||
const result = await fetchUserPlants(user_id); | ||
setUserPlants(result); | ||
}; | ||
fetchData(); | ||
}, []); | ||
|
||
// Handle button clicks | ||
const handleClick = (option: 'myPlants' | 'all') => { | ||
setSelectedOption(option); | ||
}; | ||
const handleSelected = (isSelectedInput: true | false) => { | ||
setIsSelected(isSelectedInput); | ||
}; | ||
return <PlantCard {...plant}></PlantCard>; | ||
return ( | ||
<div className="main"> | ||
<div id="plantContent"> | ||
<div className="plantSelectionHeader"> | ||
<button onClick={() => handleClick('myPlants')}>My Plants</button> | ||
<button onClick={() => handleClick('all')}>All</button> | ||
</div> | ||
<div className="componentsDisplay"> | ||
{selectedOption === 'myPlants' && userPlants.length == 0 && ( | ||
<div> | ||
<button onClick={() => handleClick('all')}>Add Plants</button> | ||
</div> | ||
)} | ||
{selectedOption === 'myPlants' && ( | ||
<div> | ||
{userPlants.map((plant, key) => ( | ||
<PlantCard key={key} plantObj={plant} canSelect={false} /> | ||
))} | ||
</div> | ||
)} | ||
{selectedOption === 'all' && isSelected == true && ( | ||
<div> | ||
{plants.map((plant, key) => ( | ||
<PlantCard key={key} plantObj={plant} canSelect={true} /> | ||
))} | ||
<div className="footer"> | ||
<button>Add to my plants</button> | ||
</div> | ||
</div> | ||
)} | ||
{selectedOption === 'all' && isSelected == false && ( | ||
<div> | ||
{plants.map((plant, key) => ( | ||
<PlantCard key={key} plantObj={plant} canSelect={false} /> | ||
))} | ||
<div className="footer"> | ||
<button onClick={() => handleSelected(true)}> | ||
Add to my plants | ||
</button> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.