Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Create my plants and all plants tabs #13

Merged
merged 22 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
46749a5
Added database function + basic plant card component
SashankBalusu Oct 6, 2024
0f655d2
Added database function + basic plant card component
SashankBalusu Oct 6, 2024
b1cda58
added viewing capability for plant component
SashankBalusu Oct 9, 2024
b83c8f8
Merge branch 'sashankbalusu/tg-16-create-the-plantcard-component' of …
SashankBalusu Oct 9, 2024
9217bd7
updated pnpmlock to meet req
SashankBalusu Oct 9, 2024
6727e08
added createClient to fix error
SashankBalusu Oct 9, 2024
f243253
fixing pnpm lock again
SashankBalusu Oct 9, 2024
7cc4a5b
unstyled version of view plants
SashankBalusu Oct 14, 2024
8fe8603
[feat] User Auth: Created a simple login page that supports sign up a…
rachaelch3n Oct 15, 2024
1811a59
[feat] pull and display all plants (#2)
kylezryr Oct 21, 2024
9fc4041
[feat] view plants: created PlantCard component (#4)
SashankBalusu Oct 21, 2024
ac644ba
Added database function + basic plant card component
SashankBalusu Oct 6, 2024
48bd98c
added viewing capability for plant component
SashankBalusu Oct 9, 2024
b3034c8
Added database function + basic plant card component
SashankBalusu Oct 6, 2024
3757227
updated pnpmlock to meet req
SashankBalusu Oct 9, 2024
704c081
added createClient to fix error
SashankBalusu Oct 9, 2024
3a5316c
fixing pnpm lock again
SashankBalusu Oct 9, 2024
8933183
unstyled version of view plants
SashankBalusu Oct 14, 2024
81c2053
updated based on comments
SashankBalusu Oct 26, 2024
30caa47
Merge branch 'Create-My-Plants-and-All-Plants-Tabs-#10' of https://gi…
SashankBalusu Oct 26, 2024
35b9ff6
pnpm
SashankBalusu Oct 26, 2024
29b49c8
filter by state
SashankBalusu Oct 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions api/supabase/queries/plant_by_id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { UUID } from 'crypto';
import { Plant } from '@/types/schema';
import supabase from '../createClient';

export async function get_plant_by_id(
i_state: string,
p_id: UUID,
): Promise<Plant> {
const { data, error } = await supabase.rpc('get_plant_by_id', {
input_state: i_state,
plant_id: p_id,
});

if (error) {
throw new Error(`Error getting matching plant: ${error.message}`);
}

return data;
}
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
110 changes: 110 additions & 0 deletions app/view-plants/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +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() {
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
const [selectedOption, setSelectedOption] = useState<'myPlants' | 'all'>(
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
'myPlants',
);
const [isSelected, setIsSelected] = useState<true | false>(false);
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved

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);
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved

if (error) {
console.error('Error fetching plant IDs:', error);
ccatherinetan marked this conversation as resolved.
Show resolved Hide resolved
return [];
}

const plantIds = data?.map(row => row.plant_id) || [];
if (plantIds.length === 0) {
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
return [];
}

const plantsUser: Plant[] = await Promise.all(
plantIds.map(plantId => get_plant_by_id('Tennessee', plantId)),
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
);
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) => {
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
setIsSelected(isSelectedInput);
};
return (
<div className="main">
<div id="plantContent">
<div className="plantSelectionHeader">
<button onClick={() => handleClick('myPlants')}>My Plants</button>
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
<button onClick={() => handleClick('all')}>All</button>
</div>
<div className="componentsDisplay">
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
{selectedOption === 'myPlants' && userPlants.length == 0 && (
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
<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>
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
)}
{selectedOption === 'all' && isSelected == false && (
<div>
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
{plants.map((plant, key) => (
<PlantCard key={key} plantObj={plant} canSelect={false} />
))}
<div className="footer">
<button onClick={() => handleSelected(true)}>
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
Add to my plants
</button>
</div>
</div>
)}
</div>
</div>
</div>
);
}
37 changes: 37 additions & 0 deletions components/PlantCard/PlantCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { Plant } from '@/types/schema';
import styles from './PlantCardStyles.module.css';

export default function PlantCard({
plantObj,
canSelect,
}: {
plantObj: Plant;
canSelect: boolean;
}) {
console.log(canSelect);
SashankBalusu marked this conversation as resolved.
Show resolved Hide resolved
return (
<div className={styles.Card}>
<div className={styles.CardPic}>
<img alt={plantObj.plant_name}></img>

Check warning on line 16 in components/PlantCard/PlantCard.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element

Check warning on line 16 in components/PlantCard/PlantCard.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint, Prettier, and TypeScript compiler

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
</div>
<div className={styles.cardContent}>
<h2>{plantObj.plant_name}</h2>
<div className={styles.plantAttributes}>
<div className={styles.attribute}>
{/* icon */}
<p>{plantObj.harvest_start + ' - ' + plantObj.harvest_end}</p>
</div>
<div className={styles.attribute}>
{/* icon */}
<p>{plantObj.water_num_times_per_week + ' times / wk'}</p>
</div>
<div className={styles.attribute}>
{/* icon */}
<p>{plantObj.sunlight_required}</p>
</div>
</div>
</div>
</div>
);
}
52 changes: 52 additions & 0 deletions components/PlantCard/PlantCardStyles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.Card {
height: 40vh;
width: 20vw;
display: flex;
flex-direction: column;
align-items: start;
border-radius: 12px;
background-color: white;
box-shadow:
0 24px 38px 3px rgba(0, 0, 0, 0.14),
0 9px 46px 8px rgba(0, 0, 0, 0.12),
0 11px 15px -7px rgba(0, 0, 0, 0.2);
}

.CardPic {
height: 60%;
width: 100%;
background-color: #f5f6f6;
display: flex;
justify-content: center;
align-items: center;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
.cardContent {
display: flex;
flex-direction: column;
padding-left: 20px;
height: 40%;
row-gap: 10px;
}
.cardContent > * {
margin: 0;
}
.cardContent > h2 {
font-size: 20px;
margin-top: 10px;
}
.plantAttributes {
display: flex;
flex-direction: column;
gap: 10px;
}

.attribute {
display: flex;
flex-direction: row;
}
.attribute > * {
margin: 0;
font-size: 14px;
}
Loading