Skip to content

Firebase events - #27

Open
bigcheeseh wants to merge 2 commits into
masterfrom
firebaseEvents
Open

Firebase events#27
bigcheeseh wants to merge 2 commits into
masterfrom
firebaseEvents

Conversation

@bigcheeseh

Copy link
Copy Markdown
Contributor

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

postContext: ''
};

this.handleOpenModal = this.handleOpenModal.bind(this);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

if you will use arrow functions you don't need to bind actions!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know about this, but used official example, and didn't change it

Comment thread src/ActionsTYPES/TYPES.js
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';

@Kronenberg Kronenberg Jan 16, 2018

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

add more actions - pending + rejected + toInitial + success

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I understand this

Comment thread src/actions/events.js
firebase.database().ref(`groups/${post.groupTitle}/posts/${post.postIndex}`)
.set(post)
.then(() => {
dispatch({ type: SAVE_POST, payload: 'Success' })

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

'success' ? look at my reducer how it should be, if you want to update just status, u need to create property inside reducer

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will work on it

Comment thread src/actions/events.js
const posts = firebase.database().ref('groups/')

posts.on('value', function (snapshot) {
console.log(snapshot.val())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

remove all console logs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok

<div style={{padding: '20px'}}>
<div>
{this.props.groupStatus.pending ? 'Loading' : groups }
{this.props.groupStatus.pending && !groups ? 'Loading' : groups }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

&& !groups? - wrong logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

groups.length

Comment thread src/routs.js
<Switch>
<Route exact path='/' component={Home} />
<Route exact path='/:groupName' component={Programs} />
<Route exact path='/:groupTitle' component={GroupPage} />

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

it's not the title - its category!

Comment thread src/store/store.js


store.dispatch(runTheApp())
store.dispatch(fetchPosts())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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) => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why you remove the group map?
why you use _.mapValues? - why simple js map not working here?
why you create array with components?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why lodash?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And lodash, because lodash cool =)

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.

2 participants