-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
import React from 'react'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
import List from './pages/List'; | ||
import AddItem from './pages/AddItem'; | ||
|
||
function App() { | ||
return ( | ||
<div className="App"> | ||
<header className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<p> | ||
Edit <code>src/App.js</code> and save to reload. | ||
</p> | ||
<a | ||
className="App-link" | ||
href="https://reactjs.org" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Learn React | ||
</a> | ||
</header> | ||
</div> | ||
<main> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No more bathtub soup 😆 |
||
<AddItem /> | ||
<List /> | ||
</main> | ||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react'; | ||
|
||
const Loading = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reusable loading state ❤️ |
||
return <p>loading...</p>; | ||
}; | ||
|
||
export default Loading; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { useState } from 'react'; | ||
import { withFirestore } from 'react-firestore'; | ||
|
||
const AddItem = ({ firestore }) => { | ||
const [name, setName] = useState(''); | ||
|
||
// Send the new item to Firebase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these comments just to bring participants up to speed? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const addItem = name => { | ||
firestore.collection('items').add({ name }); | ||
}; | ||
|
||
// The state every time an event happens | ||
const handleChange = event => { | ||
setName(event.target.value); | ||
}; | ||
|
||
// Handle the click of the Add Item button on the form | ||
const handleSubmit = event => { | ||
event.preventDefault(); | ||
addItem(name); | ||
setName(''); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice accessible form 💯 |
||
<label> | ||
Add Item: | ||
<input | ||
value={name} | ||
placeholder="apples" | ||
type="text" | ||
onChange={handleChange} | ||
/> | ||
</label> | ||
<input type="submit" value="Add Item" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to use There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would normally say |
||
</form> | ||
); | ||
}; | ||
// Wrap this component in the higher order component withFirestore to directly access the database | ||
export default withFirestore(AddItem); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { FirestoreCollection } from 'react-firestore'; | ||
import Loading from '../components/Loading'; | ||
|
||
const List = () => { | ||
return ( | ||
<section> | ||
<FirestoreCollection | ||
// Specify the path to the collection you're pulling data from | ||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! ❤️ |
||
// data = an Array containing all of the documents in the collection. Each item will contain an id along with the other data contained in the document. | ||
render={({ isLoading, data }) => { | ||
return isLoading ? ( | ||
<Loading /> | ||
) : ( | ||
<ul> | ||
{data.map(item => ( | ||
<li key={item.id}>{item.name}</li> | ||
))} | ||
</ul> | ||
); | ||
}} | ||
/> | ||
</section> | ||
); | ||
}; | ||
|
||
export default List; |
There was a problem hiding this comment.
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 aHome
component to live in pages, and thenAddItem
andList
would be components.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍