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

Issue #1 | Connect app to Firebase #44

Merged
merged 4 commits into from
Dec 22, 2019
Merged

Conversation

stacietaylorcima
Copy link
Collaborator

@stacietaylorcima stacietaylorcima commented Dec 22, 2019

Type of Changes

Type
✨ New feature
🔗 Update dependencies

Acceptance Criteria

  • The following have been added as project dependencies: firebase & react-firestore
  • Make a change in the Firestore database and it shows up in the app
  • Make a change in the app and it shows up in the Firestore database

Related Issue

Closes #23

Description

This PR adds two new components: one for adding new items to the database and another for displaying the list of items.

Display items from database

Inside that List component, we've used FirestoreCollection which is a component that allows you to interact with a Firestore collection. Using this component, you can access the collection at a given path and provide sort options, perform queries, and paginate data.

This component will setup a listener and update whenever our collection is updated in Firestore.

More documentation on FirestoreCollection here.

Write items to the database

When we wrap this AddItem component in the higher-order component (HOC) withFirestore we're provided some handy dandy methods that make it easy to send documents up to the database.

Check out more documentation and examples of how withFirestore is used here.
More documentation on React forms and controlled components here.

Testing Steps / QA Criteria

  • From your terminal, pull down this branch with git pull origin stc-connect-firebase and check that branch out with git checkout stc-connect-firebase
  • Then yarn to install the newly added dependencies locally and yarn start to launch the app.
  • Fill out the form with a new item. Make sure it adds it to the list and make sure that item appears in the items collection of the database here.

TODOs

  • Due to the last-minute circumstances that led to the completion of this issue by me (Stacie), tests were not prioritized. If I have time before the tcl-3 demos tomorrow, I will add these. If anyone else sees this and wants to add them: We need to install cypress.io and test the functionality of the form and list.

This commit adds `firebase` and `react-firestore` as dependancies so that we can interact with our database.

A List component was created where we'll be able to house all the list's logic and display the list items that get added to the database.

Inside that List component, we've used `FirestoreCollection` which is a component that allows you to interact with a Firestore collection. Using this component, you can access the collection at a given path and provide sort options, perform queries, and paginate data.

This component will setup a listener and update whenever our collection is updated in Firestore.
This commit adds an AddItem component that is a form responsible for sending items up to firestore.

When we wrap this AddItem component in the higher-order component (HOC) `withFirestore` we're provided some handy dandy methods that make it easy to send documents up to the database.

Check out more documentation and examples of how `withFirestore` is used here: https://www.npmjs.com/package/react-firestore#withfirestore
Copy link
Collaborator

@stevelikesmusic stevelikesmusic left a comment

Choose a reason for hiding this comment

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

Thanks for jumping on this issue @stacietaylorcima! 👏👏👏

Nothing blocking—just a couple comments and questions.

Also, love the PR description

</a>
</header>
</div>
<main>
Copy link
Collaborator

Choose a reason for hiding this comment

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

No more bathtub soup 😆

const AddItem = ({ firestore }) => {
const [name, setName] = useState('');

// Send the new item to Firebase
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these comments just to bring participants up to speed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. In the past, since many participants are newer to react, we've been really generous with comments so that when they jump in to work on the code, they get a better idea of what each piece does.

Add Item:
<input value={name} type="text" onChange={handleChange} />
</label>
<input type="submit" value="Add Item" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to use input vs button for submission?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was originally using a button by then when I was putzing around in the React docs, I saw their example was using an input and wanted to keep it close to the available docs in case participants wanted to investigate. What would you prefer?

React form docs: https://reactjs.org/docs/forms.html#controlled-components

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would normally say button, but I get where you're coming from. Mirroring the docs will lead to less confusion 👍

};

return (
<form onSubmit={handleSubmit}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice accessible form 💯

<form onSubmit={handleSubmit}>
<label>
Add Item:
<input value={name} type="text" onChange={handleChange} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Super minor, but I usually default to adding placeholder attr.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm into that. Will do!

path="items"
// Sort the data
sort="name"
// isLoading = is a Boolean that represents the loading status for the firebase query. true until an initial payload from Firestore is received.
Copy link
Collaborator

Choose a reason for hiding this comment

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

As earlier, are these comments to be breadcrumbs for the next team picking up the next issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep! ❤️

return isLoading ? (
<Loading />
) : (
<main>
Copy link
Collaborator

Choose a reason for hiding this comment

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

If there aren't any styles, do we need this wrapping element? I usually try to keep main as the dominant element of a page, but looking at the markup, we'd essentially have:

<body>
  <main>
    <form></form>
    <section>
	  <main></main>
	</section>
  </main>
</body>

If we really needed the wrapping element, I think div would be fine as it would merely be for styling. Screen readers would pickup the ul element as something of interest and we can also use tabindex if we want to have greater control regarding keyboard nav. But going off the code as it is, wrapping the ul element seems unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No way. This was just a late-night oversight. Fixing now!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I hear you 😂

@@ -1,25 +1,13 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import List from './pages/List';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bit of a nitpick: I'm not sure I get the folder structure here. We have two modules that are in pages but they both make up the same page. I would expect a Home component to live in pages, and then AddItem and List would be components.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're totally right. Per the scope of this issue, the folder structure should be much more like you're mentioning.

I was working ahead and trying to work in the routing code that the other pair wrote but hasn't yet merged. In that PR they are routing to two separate pages, so I set this up so that we could have the List and AddItem components be separate pages.

I think lets leave this for now since it'll help give direction to the merge conflicts today.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah ok, that makes sense 👍

@@ -0,0 +1,7 @@
import React from 'react';

const Loading = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reusable loading state ❤️

@stevelikesmusic
Copy link
Collaborator

@stacietaylorcima I added cypress to the project with a simple test. It's skipped for now, since we don't have a way of getting a clean test state. The test works and passes, but we have to update Firebase to clear out all the 🥑.

Have we been integrating cypress with CI in other cohorts?

@stacietaylorcima
Copy link
Collaborator Author

We have not been updating Cypress with CI in other cohorts, @stevelikesmusic. ✨

@stacietaylorcima stacietaylorcima merged commit f5e8744 into master Dec 22, 2019
@segdeha segdeha deleted the stc-connect-firebase branch December 24, 2019 02:52
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.

1. As a component, I want to be able to read from and write to the Firestore database
2 participants