Skip to content

Commit

Permalink
fixed styling and displayed card based on backend call
Browse files Browse the repository at this point in the history
  • Loading branch information
SashankBalusu committed Oct 16, 2024
1 parent f243253 commit 87bcf03
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 86 deletions.
14 changes: 11 additions & 3 deletions api/supabase/queries/plant_by_id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import { UUID } from 'crypto';
import { Plant } from '@/types/schema';
import supabase from '../createClient';

export async function get_plant_by_id(
export async function getPlantById(
i_state: string,
p_id: UUID,
): Promise<Plant[]> {
): Promise<Plant> {
// const { data, error } = await supabase
// .from('plant_seasonality')
// .select('*')
// .eq('state', i_state)
// .eq("plant_seed_indoors_start", "January");
// if (error)
// throw new Error(`Error fetching plant seasonality: ${error.message}`);
// return data;
const { data, error } = await supabase.rpc('get_plant_by_id', {
input_state: i_state,
plant_id: p_id,
Expand All @@ -15,5 +23,5 @@ export async function get_plant_by_id(
throw new Error(`Error getting matching plant: ${error.message}`);
}

return data;
return data[0];
}
74 changes: 53 additions & 21 deletions app/view-plants/page.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
'use client';

import { useEffect, useState } from 'react';
import { UUID } from 'crypto';
import { getPlantById } from '@/api/supabase/queries/plant_by_id';
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',
};
return <PlantCard {...plant}></PlantCard>;
const [result, setResult] = useState<Plant>();
async function fetchPlant(state: string, id: UUID) {
const plant = await getPlantById(state, id);
console.log(plant);
return plant;
}
// 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',
// };
useEffect(() => {
const getData = async () => {
const testState: string = 'Tennessee';
const testUUID: UUID = '43c19f80-8205-4d03-b323-05c220550bf0';
const plant2 = await fetchPlant(testState, testUUID);
setResult(plant2); // Set the result to state
};

getData(); // Call the async function when the component mounts
}, []);
if (result === undefined) {
return <div>Loading...</div>;
} else {
return <PlantCard plant={result} />;
}
// return (
// <div>

// <PlantCard plant={plant}/>
//
// </div>
// );
}
22 changes: 11 additions & 11 deletions components/PlantCard/PlantCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import React from 'react';
import { Plant } from '@/types/schema';
import styles from './PlantCardStyles.module.css';

export default function PlantCard(plantObj: Plant) {
export default function PlantCard({ plant }: { plant: Plant }) {
return (
<div className={styles.Card}>
<div className={styles.CardPic}>
<img alt={plantObj.plant_name}></img>
<img alt={plant.plant_name}></img>

Check warning on line 9 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 9 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}>
<div className={styles.CardContent}>
<h2>{plant.plant_name}</h2>
<div className={styles.PlantAttributes}>
<div className={styles.Attribute}>
{/* icon */}
<p>{plantObj.harvest_start + ' - ' + plantObj.harvest_end}</p>
<p>{plant.harvest_start + ' - ' + plant.harvest_end}</p>
</div>
<div className={styles.attribute}>
<div className={styles.Attribute}>
{/* icon */}
<p>{plantObj.water_num_times_per_week + ' times / wk'}</p>
<p>{plant.water_num_times_per_week + ' times / wk'}</p>
</div>
<div className={styles.attribute}>
<div className={styles.Attribute}>
{/* icon */}
<p>{plantObj.sunlight_required}</p>
<p>{plant.sunlight_required}</p>
</div>
</div>
</div>
Expand Down
24 changes: 12 additions & 12 deletions components/PlantCard/PlantCardStyles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@
border-top-left-radius: 12px;
border-top-right-radius: 12px;
}
.cardContent {
.CardContent {
display: flex;
flex-direction: column;
padding-left: 20px;
padding-left: 1vw;
height: 40%;
row-gap: 10px;
row-gap: 1vh;
}
.cardContent > * {
.CardContent > * {
margin: 0;
}
.cardContent > h2 {
font-size: 20px;
margin-top: 10px;
.CardContent > h2 {
font-size: 1.5vw;
margin-top: 1vh;
}
.plantAttributes {
.PlantAttributes {
display: flex;
flex-direction: column;
gap: 10px;
gap: 1vh;
}

.attribute {
.Attribute {
display: flex;
flex-direction: row;
}
.attribute > * {
.Attribute > * {
margin: 0;
font-size: 14px;
font-size: 1vw;
}
20 changes: 0 additions & 20 deletions src/api/supabase/createClient.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/api/supabase/queries/plant_by_id.ts

This file was deleted.

0 comments on commit 87bcf03

Please sign in to comment.