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

Added image upload component and backend call #132

Merged
merged 3 commits into from
Sep 24, 2024

Conversation

ahong75
Copy link
Contributor

@ahong75 ahong75 commented Sep 12, 2024

What does this Pull Request change?

Created a frontend component ImageUpload.tsx for caretakers to upload baby pictures. It is currently unstyled, only uses a basic input component. When the user selects an image, in the frontend the image is uploaded to firebase. Then if the upload is successful, a newly implemented backend call saves the image metadata to the firestore path /babies/{babyID}/book/{caregiverID_timestamp}

Important Changes

  • ImageUpload.tsx the new frontend component
  • save-image.ts backend call for saving metadata
  • upload-test.tsx dummy component used for testing. Should not be merged to main

Related PRs

Anything else?

@ahong75 ahong75 linked an issue Sep 12, 2024 that may be closed by this pull request
Copy link

netlify bot commented Sep 15, 2024

Deploy Preview for motherhoodbeyondbars ready!

Name Link
🔨 Latest commit 9f090c3
🔍 Latest deploy log https://app.netlify.com/sites/motherhoodbeyondbars/deploys/66f336a558f9e80008174a16
😎 Deploy Preview https://deploy-preview-132--motherhoodbeyondbars.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@parkerra parkerra added this to the Sprint 1 milestone Sep 18, 2024
Copy link
Contributor

@parkerra parkerra left a comment

Choose a reason for hiding this comment

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

Great work! This works well on web and mobile which is perfect. I had some comments about code practices, but I'll fix them for now since we're running low on time, try to keep in mind separating frontend and backend code and returning objects from the backend while completing future tickets!

(snapshot.bytesTransferred / snapshot.totalBytes) * 100;
},
(error) => {
console.error("Upload failed:", error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Return an object instead of printing the error or showing an alert so that displaying errors can be handled by the frontend, should be in the form {success: false, error: [error message]}

});
if (!response.ok) {
const result = await response.json();
alert(result.error || "Error uploading image metadata");
Copy link
Contributor

Choose a reason for hiding this comment

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

Return an object here as well instead of an error

alert("An error occurred while uploading the image.");
}
};
return <input type="file" onChange={saveFile} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

The backend and frontend should be separated where the backend endpoint is in a separate file from the frontend so that it can be re-used

req: NextApiRequest,
res: NextApiResponse
) {
if (req.method === "POST") {
Copy link
Contributor

Choose a reason for hiding this comment

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

API isn't needed in this case since Firebase can do client-side database calls, so to speed up code fetching we should call the Firebase functions as endpoints rather than in the API. There are some cases where we need to handle things on the server-side, but we're good in this case

@parkerra parkerra merged commit dfa1ca7 into main Sep 24, 2024
4 checks passed
@parkerra parkerra deleted the ash/babybook-image-uploads branch September 24, 2024 22:03
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.

[BE] Image Uploads for Baby Book
2 participants