Firebase events - #27
Conversation
| postContext: '' | ||
| }; | ||
|
|
||
| this.handleOpenModal = this.handleOpenModal.bind(this); |
There was a problem hiding this comment.
if you will use arrow functions you don't need to bind actions!
There was a problem hiding this comment.
I know about this, but used official example, and didn't change it
| export const GET_ALL_GROUPS_PENDING = 'GET_ALL_GROUPS_PENDING'; | ||
| export const GET_ALL_GROUPS_SUCCESS = 'GET_ALL_GROUPS_SUCCESS'; | ||
| export const GET_ALL_GROUPS_REJECTED = 'GET_ALL_GROUPS_REJECTED'; | ||
| export const SAVE_POST = 'SAVE_POST'; |
There was a problem hiding this comment.
add more actions - pending + rejected + toInitial + success
There was a problem hiding this comment.
Ok, I understand this
| firebase.database().ref(`groups/${post.groupTitle}/posts/${post.postIndex}`) | ||
| .set(post) | ||
| .then(() => { | ||
| dispatch({ type: SAVE_POST, payload: 'Success' }) |
There was a problem hiding this comment.
'success' ? look at my reducer how it should be, if you want to update just status, u need to create property inside reducer
There was a problem hiding this comment.
I will work on it
| const posts = firebase.database().ref('groups/') | ||
|
|
||
| posts.on('value', function (snapshot) { | ||
| console.log(snapshot.val()) |
| <div style={{padding: '20px'}}> | ||
| <div> | ||
| {this.props.groupStatus.pending ? 'Loading' : groups } | ||
| {this.props.groupStatus.pending && !groups ? 'Loading' : groups } |
| <Switch> | ||
| <Route exact path='/' component={Home} /> | ||
| <Route exact path='/:groupName' component={Programs} /> | ||
| <Route exact path='/:groupTitle' component={GroupPage} /> |
There was a problem hiding this comment.
it's not the title - its category!
|
|
||
|
|
||
| store.dispatch(runTheApp()) | ||
| store.dispatch(fetchPosts()) |
There was a problem hiding this comment.
as you remember, here we add all listeners - fetch posts name is not relevant here
in future we will have one action with all listeners!
There was a problem hiding this comment.
Ok, I will find a better place for this event listener
| console.log(this.props.groupStatus); | ||
| var groups = []; | ||
| if(this.props.groupStatus && this.props.groupStatus.groups) { | ||
| _.mapValues(this.props.groupStatus.groups, (item) => { |
There was a problem hiding this comment.
why you remove the group map?
why you use _.mapValues? - why simple js map not working here?
why you create array with components?
There was a problem hiding this comment.
Because now it's object, not array. It's need for certain reasons(create readable routes and easely finding group by group name), and lodash don't create new array like native js map method, so I create new array manually.
There was a problem hiding this comment.
And lodash, because lodash cool =)
added: group page with very simple modal window for creating posts, post events (save and fetch).
changed firebase config and small changes in firebase data structure