forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Automattic#338 from Automattic/update/sharing-redux
Sharing: Implement Redux-based Publicize reducers and actions
- Loading branch information
Showing
24 changed files
with
951 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { Component, PropTypes } from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostEditStore from 'lib/posts/post-edit-store'; | ||
import { fetchConnections } from 'lib/sharing/publicize/actions'; | ||
import { getConnectionsBySiteId, hasFetchedConnections } from 'lib/sharing/publicize/selectors'; | ||
import EditorSharingAccordion from './accordion'; | ||
|
||
class EditorSharingContainer extends Component { | ||
constructor( props ) { | ||
super( props ); | ||
|
||
// Set state | ||
this.state = this.getState(); | ||
|
||
// Trigger connection fetch | ||
this.ensureHasConnections(); | ||
|
||
// Bind legacy store update handler | ||
this.boundUpdateState = this.updateState.bind( this ); | ||
PostEditStore.on( 'change', this.boundUpdateState ); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.ensureHasConnections(); | ||
} | ||
|
||
componentWillUnmount() { | ||
PostEditStore.off( 'change', this.boundUpdateState ); | ||
} | ||
|
||
ensureHasConnections() { | ||
if ( this.props.hasFetchedConnections ) { | ||
return; | ||
} | ||
|
||
this.fetchConnections(); | ||
} | ||
|
||
updateState() { | ||
this.setState( this.getState() ); | ||
} | ||
|
||
getState() { | ||
return { | ||
post: PostEditStore.get(), | ||
isNew: PostEditStore.isNew() | ||
}; | ||
} | ||
|
||
fetchConnections() { | ||
const { site, dispatch } = this.props; | ||
if ( ! site ) { | ||
return; | ||
} | ||
|
||
dispatch( fetchConnections( site.ID ) ); | ||
} | ||
|
||
render() { | ||
const { site, connections } = this.props; | ||
const { post, isNew } = this.state; | ||
|
||
return ( | ||
<EditorSharingAccordion | ||
site={ site } | ||
post={ post } | ||
isNew={ isNew } | ||
connections={ connections } | ||
fetchConnections={ this.fetchConnections.bind( this ) } | ||
className="editor-drawer__accordion" /> | ||
); | ||
} | ||
} | ||
|
||
EditorSharingContainer.propTypes = { | ||
site: PropTypes.object, | ||
dispatch: PropTypes.func.isRequired, | ||
hasFetchedConnections: PropTypes.bool, | ||
connections: PropTypes.array | ||
}; | ||
|
||
export default connect( | ||
( state, props ) => { | ||
return { | ||
hasFetchedConnections: props.site && hasFetchedConnections( state, props.site.ID ), | ||
connections: props.site ? getConnectionsBySiteId( state, props.site.ID ) : null | ||
}; | ||
} | ||
)( EditorSharingContainer ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
`create-redux-store` | ||
==================== | ||
|
||
This module exports a function which, when invoked, returns an instance of a [Redux store](http://redux.js.org/docs/basics/Store.html). The store instance is intended to reflect the global state of the application, and runs dispatched actions against all reducers defined in [`reducers.js`](./reducers.js). To include a reducer in the global store, simply add the reducing function to the combined reducer exported by `reducers.js`. | ||
|
||
## Usage | ||
|
||
```js | ||
import createReduxStore from 'lib/create-redux-store'; | ||
|
||
const store = createReduxStore(); | ||
``` |
Oops, something went wrong.