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] implement routing to plant page #38

Merged

Conversation

SashankBalusu
Copy link
Contributor

What's new in this PR 🧑‍🌾

Description

  • when user clicks on a plant they are routed to a new page. In that page they either see just the plant object if they were in all plants or the plant object and the user plant row from db if in my plants
  • Refactored backend calls in view-plants to be solely present in the api folder
  • Created backend functions to fetch userplants table by id and user id

Screenshots

Screenshot 2024-11-11 at 6 01 19 PM

How to review

  • can look through view-plants first and then the dynamic routing files under [plantId] and [userPlantId]
  • changes to backend files are in userPlants and plants

Next steps

Relevant links

Online sources

Related PRs

CC: @ccatherinetan

@ccatherinetan ccatherinetan changed the title Sashankbalusu/tg 35 implement routing to plant page [feat] implement routing to plant page Nov 16, 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.

looking great! the functionality is fantastic 🤩 A couple big changes to consider

  1. Create an OwnedPlant type and track a state of OwnedPlant[] instead of a map of UUIDs
  2. split handlePlantCardClick into 2 functions that take in a OwnedPlant and a Plant to handle clicking on User PlantCards and PlantCards respectively
  3. remove InlineDiv and handle clicks all within PlantCard

api/supabase/queries/plants.ts Outdated Show resolved Hide resolved
api/supabase/queries/userPlants.ts Outdated Show resolved Hide resolved
app/my-plants/[userPlantId]/page.tsx Outdated Show resolved Hide resolved
app/my-plants/[userPlantId]/page.tsx Outdated Show resolved Hide resolved
app/view-plants/page.tsx Outdated Show resolved Hide resolved
app/view-plants/page.tsx Show resolved Hide resolved
app/view-plants/page.tsx Outdated Show resolved Hide resolved
app/view-plants/page.tsx Outdated Show resolved Hide resolved
app/view-plants/page.tsx Outdated Show resolved Hide resolved
components/PlantCard/index.tsx Outdated Show resolved Hide resolved
@ccatherinetan ccatherinetan linked an issue Nov 16, 2024 that may be closed by this pull request
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 so great!! some final things but otherwise ready to merge!

components/PlantCard/index.tsx Show resolved Hide resolved
api/supabase/queries/userPlants.ts Show resolved Hide resolved
api/supabase/queries/userPlants.ts Outdated Show resolved Hide resolved
}, []);

useEffect(() => {
const fetchData = async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we directly just move fetchUserPlants into the useEffect instead of using fetchData as another wrapper?

so it could look like

useEffect(() => {
  const fetchUserPlants = async () => {
    const fetchedUserPlants = await getUserPlantsByUserId(user_id);

    const ownedPlants: OwnedPlant[] = await Promise.all(
      fetchedUserPlants.map(async userPlant => {
        const plant = await getMatchingPlantForUserPlant(userPlant);
        return {
          userPlantId: userPlant.id,
          plant,
        };
      }),
    );

    setOwnedPlants(ownedPlants);
  }, []); // eventually when ProfileContext is connected, userId would be in the dependency list.

See IJP for an example of using queries in the useEffect

Copy link
Collaborator

Choose a reason for hiding this comment

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

note: since the queries (both getUserPlantsByUserId and getMatchingPlantForUserPlant) throw an error on error, we may want to use a try / catch block here and wherever a query is called to handle the error, i.e. console.error() it in the future (see IJP's example above)

@SashankBalusu SashankBalusu force-pushed the sashankbalusu/tg-35-implement-routing-to-plant-page branch from ce3361d to e694946 Compare November 20, 2024 09:17
@ccatherinetan ccatherinetan merged commit a3f4ffe into main Nov 20, 2024
2 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.

Implement Routing to PlantPage
2 participants