From f0f791bb76bbe1e8ea4329b3c5ebcbb9f7076b0d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 16 Oct 2016 19:23:17 +0200 Subject: [PATCH] Don't preload timelines as props, load them when timeline component is mounted This prevents the bug where if you go "back" to the UI after navigating to another page it loads with the old set of statuses --- .../javascripts/components/containers/mastodon.jsx | 6 ------ .../components/features/home_timeline/index.jsx | 12 +++++++++++- .../components/features/mentions_timeline/index.jsx | 12 +++++++++++- .../components/features/public_timeline/index.jsx | 4 ++++ app/helpers/home_helper.rb | 8 +------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/components/containers/mastodon.jsx b/app/assets/javascripts/components/containers/mastodon.jsx index 1327dba3e1b57..e5c0887a95cad 100644 --- a/app/assets/javascripts/components/containers/mastodon.jsx +++ b/app/assets/javascripts/components/containers/mastodon.jsx @@ -41,12 +41,6 @@ const Mastodon = React.createClass({ store.dispatch(setAccessToken(this.props.token)); store.dispatch(setAccountSelf(JSON.parse(this.props.account))); - for (var timelineType in this.props.timelines) { - if (this.props.timelines.hasOwnProperty(timelineType)) { - store.dispatch(refreshTimelineSuccess(timelineType, JSON.parse(this.props.timelines[timelineType]))); - } - } - if (typeof App !== 'undefined') { this.subscription = App.cable.subscriptions.create('TimelineChannel', { diff --git a/app/assets/javascripts/components/features/home_timeline/index.jsx b/app/assets/javascripts/components/features/home_timeline/index.jsx index 1f4b25450dda5..9be3f3964be8e 100644 --- a/app/assets/javascripts/components/features/home_timeline/index.jsx +++ b/app/assets/javascripts/components/features/home_timeline/index.jsx @@ -1,11 +1,21 @@ +import { connect } from 'react-redux'; import PureRenderMixin from 'react-addons-pure-render-mixin'; import StatusListContainer from '../ui/containers/status_list_container'; import Column from '../ui/components/column'; +import { refreshTimeline } from '../../actions/timelines'; const HomeTimeline = React.createClass({ + propTypes: { + dispatch: React.PropTypes.func.isRequired + }, + mixins: [PureRenderMixin], + componentWillMount () { + this.props.dispatch(refreshTimeline('home')); + }, + render () { return ( @@ -16,4 +26,4 @@ const HomeTimeline = React.createClass({ }); -export default HomeTimeline; +export default connect()(HomeTimeline); diff --git a/app/assets/javascripts/components/features/mentions_timeline/index.jsx b/app/assets/javascripts/components/features/mentions_timeline/index.jsx index d9d0963d064a5..a1b511d3e80da 100644 --- a/app/assets/javascripts/components/features/mentions_timeline/index.jsx +++ b/app/assets/javascripts/components/features/mentions_timeline/index.jsx @@ -1,11 +1,21 @@ +import { connect } from 'react-redux'; import PureRenderMixin from 'react-addons-pure-render-mixin'; import StatusListContainer from '../ui/containers/status_list_container'; import Column from '../ui/components/column'; +import { refreshTimeline } from '../../actions/timelines'; const MentionsTimeline = React.createClass({ + propTypes: { + dispatch: React.PropTypes.func.isRequired + }, + mixins: [PureRenderMixin], + componentWillMount () { + this.props.dispatch(refreshTimeline('mentions')); + }, + render () { return ( @@ -16,4 +26,4 @@ const MentionsTimeline = React.createClass({ }); -export default MentionsTimeline; +export default connect()(MentionsTimeline); diff --git a/app/assets/javascripts/components/features/public_timeline/index.jsx b/app/assets/javascripts/components/features/public_timeline/index.jsx index 7d3739214cea8..8b2a869471ce6 100644 --- a/app/assets/javascripts/components/features/public_timeline/index.jsx +++ b/app/assets/javascripts/components/features/public_timeline/index.jsx @@ -9,6 +9,10 @@ import { const PublicTimeline = React.createClass({ + propTypes: { + dispatch: React.PropTypes.func.isRequired + }, + mixins: [PureRenderMixin], componentWillMount () { diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 6b51517775e04..86cce4c018d00 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -2,13 +2,7 @@ module HomeHelper def default_props { token: @token, - - account: render(file: 'api/v1/accounts/show', locals: { account: current_user.account }, formats: :json), - - timelines: { - home: render(file: 'api/v1/statuses/index', locals: { statuses: @home }, formats: :json), - mentions: render(file: 'api/v1/statuses/index', locals: { statuses: @mentions }, formats: :json) - } + account: render(file: 'api/v1/accounts/show', locals: { account: current_user.account }, formats: :json) } end end