From 98e1938b9be30d2c1cf95da631d1c0d21d3ffd40 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Sun, 27 Mar 2016 15:23:22 +0900 Subject: [PATCH] Unify the logic for home --- src/actions/tweets.js | 11 +++++++++++ src/containers/timeline-container.js | 6 +----- src/utils/ipc-action.js | 13 +++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/actions/tweets.js b/src/actions/tweets.js index 7a4a833..3dfef0e 100644 --- a/src/actions/tweets.js +++ b/src/actions/tweets.js @@ -85,6 +85,17 @@ export const markAsRead = (tweet, account) => { return { type: MARK_AS_READ, tweet, account } } +export const loadHome = (account) => { + return dispatch => { + const client = new TwitterClient(account); + client.homeTimeline({ count: 50 }, (tweets) => { + for (let tweet of tweets) { + dispatch(addTweet(tweet, account)); + } + }); + } +} + export const loadList = (listId, account, reset = false) => { return dispatch => { const client = new TwitterClient(account); diff --git a/src/containers/timeline-container.js b/src/containers/timeline-container.js index 5a4f68d..61657d1 100644 --- a/src/containers/timeline-container.js +++ b/src/containers/timeline-container.js @@ -15,11 +15,7 @@ const mapDispatchToProps = (dispatch, props) => { return { loadHome: () => { - client.homeTimeline({ count: 50 }, (tweets) => { - for (let tweet of tweets) { - dispatch(Actions.addTweet(tweet, props.account)); - } - }); + dispatch(Actions.loadHome(props.account)); }, loadMentions: () => { client.mentionsTimeline((tweets) => { diff --git a/src/utils/ipc-action.js b/src/utils/ipc-action.js index a09b6eb..e8b4c08 100644 --- a/src/utils/ipc-action.js +++ b/src/utils/ipc-action.js @@ -53,19 +53,16 @@ export default class IpcAction { }); ipcRenderer.on('reload-timeline', (event) => { - this.client().homeTimeline({ count: 50 }, (tweets) => { - for (let tweet of tweets) { - this.dispatch(Actions.addTweet(tweet, this.state.activeAccount())); - } - }); + const account = this.state.activeAccount(); + this.dispatch(Actions.loadHome(account)); const listId = this.state.activeListId(); - if (listId) this.dispatch(Actions.loadList(listId, this.state.activeAccount())); + if (listId) this.dispatch(Actions.loadList(listId, account)); const query = this.state.activeSearchQuery(); - if (query) this.dispatch(Actions.loadSearch(query, this.state.activeAccount())); + if (query) this.dispatch(Actions.loadSearch(query, account)); - this.dispatch(Actions.reconnectStreaming(this.state.activeAccount())); + this.dispatch(Actions.reconnectStreaming(account)); }); }