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] implements add plant details #18

Merged
merged 10 commits into from
Oct 30, 2024
Merged

[feat] implements add plant details #18

merged 10 commits into from
Oct 30, 2024

Conversation

SashankBalusu
Copy link
Contributor

What's new in this PR 🧑‍🌾

Description

  • scroll through plant objects to add plant details
  • push details to database on submit

Screenshots

How to review

  • can test through the add-details directory
  • navigate through the plant objects and details, when submit is pressed the database is updated
  • database function is under queries "updateUserPlants.ts"

Next steps

  • no styling!

Relevant links

Online sources

Related PRs

CC: @ccatherinetan

@ccatherinetan ccatherinetan linked an issue Oct 22, 2024 that may be closed by this pull request
@ccatherinetan ccatherinetan changed the title View plant details [feat] implements add plant details Oct 22, 2024
Copy link
Collaborator

@ccatherinetan ccatherinetan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh so amazing, tysm sashank! plz see my comments

  1. we should merge in ur previous pr (All Plants + My Plants tab) + rebase this branch after that's merged
  2. there is 1 big logic fix for accessing the input values for each plants.
  3. let's try to add comments esp in the move func to explain the logic!

types/schema.d.ts Outdated Show resolved Hide resolved
components/PlantDetails/PlantDetails.tsx Outdated Show resolved Hide resolved
components/PlantDetails/PlantDetails.tsx Outdated Show resolved Hide resolved
components/PlantDetails/PlantDetails.tsx Outdated Show resolved Hide resolved
api/supabase/queries/updateUserPlants.ts Outdated Show resolved Hide resolved
app/add-details/page.tsx Outdated Show resolved Hide resolved
app/add-details/page.tsx Show resolved Hide resolved
app/add-details/page.tsx Show resolved Hide resolved
app/add-details/page.tsx Show resolved Hide resolved
api/supabase/queries/updateUserPlants.ts Outdated Show resolved Hide resolved
{currentIndex != plants.length + 1 && (
<div>
<PlantDetails plant={plants[currentIndex - 1]}></PlantDetails>
<button onClick={() => move(-1)}>Back</button>
Copy link
Collaborator

@ccatherinetan ccatherinetan Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design question @kyrenetam: do we want to hide (or rename) the "Back" button on the first add plant screen page? I feel like it's misleading, unless we plan to allow users to route back to view-plants

Copy link
Collaborator

@ccatherinetan ccatherinetan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great so far! the final change is to change planting_type to type PlantingTypeEnum in UserPlants. This will cause some type errors which should be resolved by passing in plantingType/setPlantingType or dateInput/setDateInput to PlantDetails

api/supabase/queries/plant_by_id.ts Outdated Show resolved Hide resolved
plant_id: UUID;
date_added: string;
date_harvested: string;
planting_type: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be PlantingTypeEnum

you should also have
export type PlantingTypeEnum = 'INDOORS' | 'OUTDOORS' | 'TRANSPLANT'

import { Plant, UserPlants } from '@/types/schema';

export default function PlantDetails({
detail,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should take in setDate and setPlant
See Kyle's FilterDropdown in components/FilterDropdown.tsx for an example of how to pass in setState react hooks

if (currentIndex != plants.length + 1) {
const updatedDetails = [...details];
const plantID = plants[currentIndex - 1]['id'];
const date = (document.getElementById('date')! as HTMLInputElement).value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing document.getElementById we can use a useState to track the dateInput and plantingType, i.e.

const [dateInput, setDateInput] = useState<Date | null>(null);
const [plantingType, setPlantingType] = useState<PlantingTypeEnum | null>(null);

(you might be able to handle the null cases differently, but this is just a suggestion)
And then, pass the value and the setValue func (e.g. plantingType, setPlantingType) into PlantDetails (see the later comment)

).value;
updatedDetails[currentIndex - 1] = {
date_added: date,
planting_type: plant_type,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will cause a type error once we change planting_type to PlantingTypeEnum (instead of string) in schema.d.ts. Hopefully the additional value/setValue handling (see other comments) will resolve the the type error

@ccatherinetan ccatherinetan merged commit ec9ee96 into main Oct 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create the Add Plant Details Flow
2 participants