From cf6ab0987b53e8818c84c293cc6d7a2c7fcc9de1 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 11:48:46 +0200 Subject: [PATCH 01/10] add action creator current_sort_contact --- src/actions/contacts.js | 8 ++++++++ src/components/sortContact/SortContactContainer.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/actions/contacts.js b/src/actions/contacts.js index e3cb4be..4af413a 100644 --- a/src/actions/contacts.js +++ b/src/actions/contacts.js @@ -27,3 +27,11 @@ export const addNetworkListToContact = (networkListId, contactId) => { } } } + +export const CURRENT_SORT_CONTACT = 'CURRENT_SORT_CONTACT' +export const currentSortContact = (currentContact) => { + return { + type: CURRENT_SORT_CONTACT, + payload: currentContact + } +} diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index 96b8208..f308364 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -1,7 +1,7 @@ import React, { PureComponent, PropTypes } from 'react' import { connect } from 'react-redux' import { submit } from 'redux-form' -import { updateContact } from '../../actions/contacts' +import { updateContact, currentSortContact } from '../../actions/contacts' import {formFieldsContactDetails as formFields} from '../../helpers/formData' import Media from 'react-media' import ZeroContacts from './ZeroContacts' From 06d29dd47a7f0e42627a4b6bf2f225bf1b0be1b3 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 11:49:15 +0200 Subject: [PATCH 02/10] calling getOnecontact in willMount and refactor getOnecontact to dispatch --- src/components/sortContact/SortContactContainer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index f308364..90c8a58 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -33,6 +33,10 @@ class SortContactContainer extends PureComponent { contacts: PropTypes.array.isRequired, addedContactIds: PropTypes.array.isRequired } + componentWillMount() { + console.log('WILLMOUNT') + this.getOneContact() + } componentDidMount () { window.addEventListener('keydown', this.handleContainerKeyPress) From 1e50529a6a12871353697f72f4b4947305cfbb23 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 11:49:27 +0200 Subject: [PATCH 03/10] calling getOnecontact in willMount and refactor getOnecontact to dispatch --- src/components/sortContact/SortContactContainer.js | 3 ++- src/reducers/contacts.js | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index 90c8a58..3ff6296 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -64,9 +64,10 @@ class SortContactContainer extends PureComponent { getOneContact () { const { contacts } = this.props const { contactIndex } = this.state - return contacts.filter((contact, index) => { + const theNeededContact = contacts.filter((contact, index) => { return index === contactIndex }) + return this.props.dispatch(currentSortContact(theNeededContact)) } onSubmit (values, dispatch, props) { diff --git a/src/reducers/contacts.js b/src/reducers/contacts.js index c0661b8..041894d 100644 --- a/src/reducers/contacts.js +++ b/src/reducers/contacts.js @@ -268,7 +268,6 @@ export default function contacts(state = initialState, { type, payload } = {}) { switch (type) { case UPDATE_CONTACT : - return state.map((contact) => { if (contact.id === payload.contactId) { const updatedContactAttributes = payload.contactFields From 41fb0af216ed22daa380d2b4496013d27cbed2c6 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 11:49:47 +0200 Subject: [PATCH 04/10] add current_sort_contact to sortcontact reducer --- src/reducers/sortContactReducer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/reducers/sortContactReducer.js b/src/reducers/sortContactReducer.js index 01f001f..a286c56 100644 --- a/src/reducers/sortContactReducer.js +++ b/src/reducers/sortContactReducer.js @@ -1,4 +1,5 @@ import { ADD_CONTACT_TO_NETWORKLIST } from '../actions/networklists' +import { CURRENT_SORT_CONTACT } from '../actions/contacts' const initialState = { addedContactIds: [] @@ -12,6 +13,9 @@ export default function sortContactReducer(state = initialState, { type, payload } return { ...state, addedContactIds: [...state.addedContactIds, payload.contactId] } + case CURRENT_SORT_CONTACT: + return state + default: return state From ac5d4027939a62f4f5a213d5a2e8870ed87a11b9 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 13:03:03 +0200 Subject: [PATCH 05/10] add note in networklist reducer --- src/reducers/networklists.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reducers/networklists.js b/src/reducers/networklists.js index 3c47952..629db67 100644 --- a/src/reducers/networklists.js +++ b/src/reducers/networklists.js @@ -61,6 +61,7 @@ const networklists = (state = initialState, action) => { // console.log(action.payload, 'networklists action.payload') // const newNetworkList = Object.assign({}, action.payload) // return [newNetworkList].concat(state) + // NOTE: maybe we can use {type, payload} = {} as params return [ ...state, networklist(undefined, action) From 00fc81f16b0961f6223026ba11aa35c3e7ab87e1 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 13:03:30 +0200 Subject: [PATCH 06/10] add theonecontact as array to sortcontact reducer --- src/reducers/sortContactReducer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reducers/sortContactReducer.js b/src/reducers/sortContactReducer.js index a286c56..07d8878 100644 --- a/src/reducers/sortContactReducer.js +++ b/src/reducers/sortContactReducer.js @@ -2,7 +2,8 @@ import { ADD_CONTACT_TO_NETWORKLIST } from '../actions/networklists' import { CURRENT_SORT_CONTACT } from '../actions/contacts' const initialState = { - addedContactIds: [] + addedContactIds: [], + theOneContact: [] } export default function sortContactReducer(state = initialState, { type, payload } = {}) { From c09f266d09de02d19689a79a7c42c2f90c397deb Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 13:03:51 +0200 Subject: [PATCH 07/10] add current_sort_contact case --- src/reducers/sortContactReducer.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/reducers/sortContactReducer.js b/src/reducers/sortContactReducer.js index 07d8878..14abc96 100644 --- a/src/reducers/sortContactReducer.js +++ b/src/reducers/sortContactReducer.js @@ -15,8 +15,10 @@ export default function sortContactReducer(state = initialState, { type, payload return { ...state, addedContactIds: [...state.addedContactIds, payload.contactId] } case CURRENT_SORT_CONTACT: - return state - + // newCurrentContact = Object.assign({}, payload) + // return [newCurrentContact].concat(state) + return {...state, theOneContact: payload} + default: return state From 616071b267aeda3a8d8fe5d6cf7a26dd1045e0f7 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Thu, 25 May 2017 13:46:51 +0200 Subject: [PATCH 08/10] add currentcontact to state' ' --- src/components/sortContact/SortContactContainer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index 3ff6296..f9ce009 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -138,6 +138,7 @@ class SortContactContainer extends PureComponent { render () { const { curContactNumb, totalContacts, completedProgress, snackOpen } = this.state + console.log('currentContact', this.props.currentContact) // if (this.props.contacts === []) return return (
@@ -182,7 +183,8 @@ class SortContactContainer extends PureComponent { const mapStateToProps = (state) => { return { contacts: state.contacts, - addedContactIds: state.sortContact.addedContactIds + addedContactIds: state.sortContact.addedContactIds, + currentContact: state.sortContact.theOneContact } } From 10c4abdaefa1b2f7586bb8f4bce469cb8c984e15 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Fri, 26 May 2017 16:20:38 +0200 Subject: [PATCH 09/10] remove dlogs --- src/components/sortContact/SortContactContainer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index f9ce009..1228c8d 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -64,10 +64,10 @@ class SortContactContainer extends PureComponent { getOneContact () { const { contacts } = this.props const { contactIndex } = this.state - const theNeededContact = contacts.filter((contact, index) => { + return contacts.filter((contact, index) => { return index === contactIndex }) - return this.props.dispatch(currentSortContact(theNeededContact)) + } onSubmit (values, dispatch, props) { From 740ce5ef07571a4530e5d40cefcbb2fc955d54e5 Mon Sep 17 00:00:00 2001 From: raptorzhezuzninya Date: Fri, 26 May 2017 16:20:51 +0200 Subject: [PATCH 10/10] dont need this escape return --- src/components/sortContact/SortContactContainer.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/components/sortContact/SortContactContainer.js b/src/components/sortContact/SortContactContainer.js index 1228c8d..6afc354 100644 --- a/src/components/sortContact/SortContactContainer.js +++ b/src/components/sortContact/SortContactContainer.js @@ -129,17 +129,9 @@ class SortContactContainer extends PureComponent { ) } - // NOTE i need to create renderHintText function that i will pass to HintFooter which will show different mila hints if a user clicks on next contact. - - // renderHintText() { - // const hints = ['Tip #1: Use keyboard shortcuts to sort contacts faster!', 'Tip #2: Use left and right arrow keys to sort next contact'] - // - // } - render () { const { curContactNumb, totalContacts, completedProgress, snackOpen } = this.state - console.log('currentContact', this.props.currentContact) - // if (this.props.contacts === []) return + return (
@@ -174,7 +166,6 @@ class SortContactContainer extends PureComponent { hintText='hint-text'/> )}/> -
) }