Skip to content
This repository has been archived by the owner on Apr 7, 2023. It is now read-only.

Commit

Permalink
Unify the logic for home
Browse files Browse the repository at this point in the history
  • Loading branch information
Takashi Kokubun committed Mar 27, 2016
1 parent 9566027 commit 98e1938
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/actions/tweets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/containers/timeline-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
13 changes: 5 additions & 8 deletions src/utils/ipc-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down

0 comments on commit 98e1938

Please sign in to comment.