Skip to content

Commit

Permalink
Type the tracker connect
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Sep 19, 2016
1 parent 6b45249 commit 73af0af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions shared/actions/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function _getTrackToken (state, username) {
return trackerState && trackerState.type === 'tracker' ? trackerState.trackToken : null
}

export function onFollow (username: string, localIgnore: bool): (dispatch: Dispatch, getState: () => {tracker: RootTrackerState}) => void {
export function onFollow (username: string, localIgnore?: bool): (dispatch: Dispatch, getState: () => {tracker: RootTrackerState}) => void {
return (dispatch, getState) => {
const trackToken = _getTrackToken(getState(), username)

Expand All @@ -311,7 +311,7 @@ export function onFollow (username: string, localIgnore: bool): (dispatch: Dispa
}

dispatch(onWaiting(username, true))
trackUser(trackToken, localIgnore)
trackUser(trackToken, localIgnore || false)
.then(dispatchFollowedAction)
.catch(err => {
console.warn("Couldn't track user: ", err)
Expand Down
3 changes: 2 additions & 1 deletion shared/constants/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export type TrackerState = {

export type NonUserState = {
type: 'nonUser',
error: ?string,
closed: boolean,
hidden: boolean,
name: string,
Expand All @@ -156,7 +157,7 @@ export type NonUserState = {

export type TrackerOrNonUserState = TrackerState | NonUserState

function isLoading (state: ?TrackerState): boolean {
function isLoading (state: ?TrackerOrNonUserState): boolean {
// TODO (mm) ideally userInfo should be null until we get a response from the server
// Same with proofs (instead of empty array). So we know the difference between
// not having data and having empty data.
Expand Down
1 change: 1 addition & 0 deletions shared/reducers/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function initialTrackerState (username: string): TrackerState {
function initialNonUserState (assertion: string): NonUserState {
return {
closed: true,
error: null,
hidden: true,
inviteLink: null,
isPrivate: false,
Expand Down
24 changes: 14 additions & 10 deletions shared/tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {isLoading} from '../constants/tracker'

import type {RenderPropsUnshaped} from './render'
import type {Proof, SimpleProofState, UserInfo} from '../constants/tracker'
import type {TypedState} from '../constants/reducer'

export type TrackerProps = {
actionBarReady: boolean,
Expand Down Expand Up @@ -78,29 +79,32 @@ class Tracker extends Component<void, TrackerProps, void> {
}
}

// $FlowIssue type this connector
type OwnProps = {
username: string,
}

export default connect(
(state, ownProps) => {
(state: TypedState, ownProps: OwnProps) => {
const trackerState = state.tracker.trackers[ownProps.username]
return {
...state.tracker,
nonUser: trackerState && trackerState.type === 'nonUser',
loggedIn: state.config && state.config.loggedIn,
loading: isLoading(trackerState),
actionBarReady: !trackerState.serverActive && !state.error,
actionBarReady: !trackerState.serverActive && !trackerState.error,
...trackerState,
...ownProps,
}
},
(dispatch, ownProps) => {
(dispatch: any, ownProps: OwnProps) => {
const actions = bindActionCreators(trackerActions, dispatch)
return {
...actions,
onClose: () => actions.onClose(ownProps.username),
onFollow: () => actions.onFollow(ownProps.username),
onIgnore: () => actions.onIgnore(ownProps.username),
onRefollow: () => actions.onRefollow(ownProps.username),
onUnfollow: () => actions.onUnfollow(ownProps.username),
onClose: () => { actions.onClose(ownProps.username) },
onFollow: () => { actions.onFollow(ownProps.username) },
onIgnore: () => { actions.onIgnore(ownProps.username) },
onRefollow: () => { actions.onRefollow(ownProps.username) },
onUnfollow: () => { actions.onUnfollow(ownProps.username) },
startTimer: () => { actions.startTimer() },
onClickAvatar: (username, uid) => { dispatch(onClickAvatar(username, uid, true)) },
onClickFollowers: (username, uid) => { dispatch(onClickFollowers(username, uid, true)) },
onClickFollowing: (username, uid) => { dispatch(onClickFollowing(username, uid, true)) },
Expand Down

0 comments on commit 73af0af

Please sign in to comment.