From b02bfe86ce26ef001420841673257c9c5326b45c Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 27 Jul 2018 17:59:52 +0200 Subject: [PATCH] Don't reset scroll position when opening a modal --- .../flavours/glitch/features/account_gallery/index.js | 6 +++++- .../flavours/glitch/features/account_timeline/index.js | 5 +++++ app/javascript/flavours/glitch/features/blocks/index.js | 6 +++++- .../flavours/glitch/features/bookmarked_statuses/index.js | 5 +++++ .../flavours/glitch/features/community_timeline/index.js | 5 +++++ .../flavours/glitch/features/direct_timeline/index.js | 5 +++++ .../flavours/glitch/features/domain_blocks/index.js | 6 +++++- .../flavours/glitch/features/favourited_statuses/index.js | 5 +++++ app/javascript/flavours/glitch/features/following/index.js | 6 +++++- .../flavours/glitch/features/hashtag_timeline/index.js | 5 +++++ .../flavours/glitch/features/pinned_statuses/index.js | 5 +++++ .../flavours/glitch/features/public_timeline/index.js | 5 +++++ .../glitch/features/standalone/community_timeline/index.js | 5 +++++ .../glitch/features/standalone/hashtag_timeline/index.js | 5 +++++ app/javascript/flavours/glitch/features/status/index.js | 6 +++++- 15 files changed, 75 insertions(+), 5 deletions(-) diff --git a/app/javascript/flavours/glitch/features/account_gallery/index.js b/app/javascript/flavours/glitch/features/account_gallery/index.js index ebd23a9717..de83189645 100644 --- a/app/javascript/flavours/glitch/features/account_gallery/index.js +++ b/app/javascript/flavours/glitch/features/account_gallery/index.js @@ -89,6 +89,10 @@ export default class AccountGallery extends ImmutablePureComponent { this.handleScrollToBottom(); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { medias, isLoading, hasMore } = this.props; @@ -110,7 +114,7 @@ export default class AccountGallery extends ImmutablePureComponent { - +
diff --git a/app/javascript/flavours/glitch/features/account_timeline/index.js b/app/javascript/flavours/glitch/features/account_timeline/index.js index 2216f91534..20ba0a1b1b 100644 --- a/app/javascript/flavours/glitch/features/account_timeline/index.js +++ b/app/javascript/flavours/glitch/features/account_timeline/index.js @@ -60,6 +60,10 @@ export default class AccountTimeline extends ImmutablePureComponent { this.props.dispatch(expandAccountTimeline(this.props.params.accountId, { maxId, withReplies: this.props.withReplies })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { statusIds, featuredStatusIds, isLoading, hasMore } = this.props; @@ -83,6 +87,7 @@ export default class AccountTimeline extends ImmutablePureComponent { isLoading={isLoading} hasMore={hasMore} onLoadMore={this.handleLoadMore} + shouldUpdateScroll={this.shouldUpdateScroll} /> ); diff --git a/app/javascript/flavours/glitch/features/blocks/index.js b/app/javascript/flavours/glitch/features/blocks/index.js index edd448921e..4c8b165040 100644 --- a/app/javascript/flavours/glitch/features/blocks/index.js +++ b/app/javascript/flavours/glitch/features/blocks/index.js @@ -42,6 +42,10 @@ export default class Blocks extends ImmutablePureComponent { } } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, accountIds } = this.props; @@ -56,7 +60,7 @@ export default class Blocks extends ImmutablePureComponent { return ( - +
{accountIds.map(id => diff --git a/app/javascript/flavours/glitch/features/bookmarked_statuses/index.js b/app/javascript/flavours/glitch/features/bookmarked_statuses/index.js index 9468ad81d7..f1b4f947ed 100644 --- a/app/javascript/flavours/glitch/features/bookmarked_statuses/index.js +++ b/app/javascript/flavours/glitch/features/bookmarked_statuses/index.js @@ -66,6 +66,10 @@ export default class Bookmarks extends ImmutablePureComponent { this.props.dispatch(expandBookmarkedStatuses()); }, 300, { leading: true }) + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props; const pinned = !!columnId; @@ -87,6 +91,7 @@ export default class Bookmarks extends ImmutablePureComponent { trackScroll={!pinned} statusIds={statusIds} scrollKey={`bookmarked_statuses-${columnId}`} + shouldUpdateScroll={this.shouldUpdateScroll} hasMore={hasMore} isLoading={isLoading} onLoadMore={this.handleLoadMore} diff --git a/app/javascript/flavours/glitch/features/community_timeline/index.js b/app/javascript/flavours/glitch/features/community_timeline/index.js index b5843ca164..e5006b4d3c 100644 --- a/app/javascript/flavours/glitch/features/community_timeline/index.js +++ b/app/javascript/flavours/glitch/features/community_timeline/index.js @@ -71,6 +71,10 @@ export default class CommunityTimeline extends React.PureComponent { this.props.dispatch(expandCommunityTimeline({ maxId })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, hasUnread, columnId, multiColumn } = this.props; const pinned = !!columnId; @@ -93,6 +97,7 @@ export default class CommunityTimeline extends React.PureComponent { } diff --git a/app/javascript/flavours/glitch/features/direct_timeline/index.js b/app/javascript/flavours/glitch/features/direct_timeline/index.js index 418db7c79d..25af49342e 100644 --- a/app/javascript/flavours/glitch/features/direct_timeline/index.js +++ b/app/javascript/flavours/glitch/features/direct_timeline/index.js @@ -71,6 +71,10 @@ export default class DirectTimeline extends React.PureComponent { this.props.dispatch(expandDirectTimeline({ maxId })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, hasUnread, columnId, multiColumn } = this.props; const pinned = !!columnId; @@ -93,6 +97,7 @@ export default class DirectTimeline extends React.PureComponent { } diff --git a/app/javascript/flavours/glitch/features/domain_blocks/index.js b/app/javascript/flavours/glitch/features/domain_blocks/index.js index 3b29e2a267..8b023e0bcb 100644 --- a/app/javascript/flavours/glitch/features/domain_blocks/index.js +++ b/app/javascript/flavours/glitch/features/domain_blocks/index.js @@ -40,6 +40,10 @@ export default class Blocks extends ImmutablePureComponent { this.props.dispatch(expandDomainBlocks()); }, 300, { leading: true }); + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, domains } = this.props; @@ -54,7 +58,7 @@ export default class Blocks extends ImmutablePureComponent { return ( - + {domains.map(domain => )} diff --git a/app/javascript/flavours/glitch/features/favourited_statuses/index.js b/app/javascript/flavours/glitch/features/favourited_statuses/index.js index d8fa1b84e0..6444931837 100644 --- a/app/javascript/flavours/glitch/features/favourited_statuses/index.js +++ b/app/javascript/flavours/glitch/features/favourited_statuses/index.js @@ -66,6 +66,10 @@ export default class Favourites extends ImmutablePureComponent { this.props.dispatch(expandFavouritedStatuses()); }, 300, { leading: true }) + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props; const pinned = !!columnId; @@ -87,6 +91,7 @@ export default class Favourites extends ImmutablePureComponent { trackScroll={!pinned} statusIds={statusIds} scrollKey={`favourited_statuses-${columnId}`} + shouldUpdateScroll={this.shouldUpdateScroll} hasMore={hasMore} isLoading={isLoading} onLoadMore={this.handleLoadMore} diff --git a/app/javascript/flavours/glitch/features/following/index.js b/app/javascript/flavours/glitch/features/following/index.js index c05742d4f3..e7a72d0367 100644 --- a/app/javascript/flavours/glitch/features/following/index.js +++ b/app/javascript/flavours/glitch/features/following/index.js @@ -56,6 +56,10 @@ export default class Following extends ImmutablePureComponent { this.props.dispatch(expandFollowing(this.props.params.accountId)); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { accountIds, hasMore } = this.props; @@ -77,7 +81,7 @@ export default class Following extends ImmutablePureComponent { - +
diff --git a/app/javascript/flavours/glitch/features/hashtag_timeline/index.js b/app/javascript/flavours/glitch/features/hashtag_timeline/index.js index 8f77ed42b5..b3e8b7a6e2 100644 --- a/app/javascript/flavours/glitch/features/hashtag_timeline/index.js +++ b/app/javascript/flavours/glitch/features/hashtag_timeline/index.js @@ -82,6 +82,10 @@ export default class HashtagTimeline extends React.PureComponent { this.props.dispatch(expandHashtagTimeline(this.props.params.id, { maxId })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { hasUnread, columnId, multiColumn } = this.props; const { id } = this.props.params; @@ -106,6 +110,7 @@ export default class HashtagTimeline extends React.PureComponent { scrollKey={`hashtag_timeline-${columnId}`} timelineId={`hashtag:${id}`} onLoadMore={this.handleLoadMore} + shouldUpdateScroll={this.shouldUpdateScroll} emptyMessage={} /> diff --git a/app/javascript/flavours/glitch/features/pinned_statuses/index.js b/app/javascript/flavours/glitch/features/pinned_statuses/index.js index f56d701760..e7fa7ac0d2 100644 --- a/app/javascript/flavours/glitch/features/pinned_statuses/index.js +++ b/app/javascript/flavours/glitch/features/pinned_statuses/index.js @@ -41,6 +41,10 @@ export default class PinnedStatuses extends ImmutablePureComponent { this.column = c; } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, statusIds, hasMore } = this.props; @@ -50,6 +54,7 @@ export default class PinnedStatuses extends ImmutablePureComponent { diff --git a/app/javascript/flavours/glitch/features/public_timeline/index.js b/app/javascript/flavours/glitch/features/public_timeline/index.js index a6c0b16889..3eb92cafa9 100644 --- a/app/javascript/flavours/glitch/features/public_timeline/index.js +++ b/app/javascript/flavours/glitch/features/public_timeline/index.js @@ -71,6 +71,10 @@ export default class PublicTimeline extends React.PureComponent { this.props.dispatch(expandPublicTimeline({ maxId })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl, columnId, hasUnread, multiColumn } = this.props; const pinned = !!columnId; @@ -95,6 +99,7 @@ export default class PublicTimeline extends React.PureComponent { onLoadMore={this.handleLoadMore} trackScroll={!pinned} scrollKey={`public_timeline-${columnId}`} + shouldUpdateScroll={this.shouldUpdateScroll} emptyMessage={} /> diff --git a/app/javascript/flavours/glitch/features/standalone/community_timeline/index.js b/app/javascript/flavours/glitch/features/standalone/community_timeline/index.js index c488f95417..08b9e9e57c 100644 --- a/app/javascript/flavours/glitch/features/standalone/community_timeline/index.js +++ b/app/javascript/flavours/glitch/features/standalone/community_timeline/index.js @@ -47,6 +47,10 @@ export default class CommunityTimeline extends React.PureComponent { this.props.dispatch(expandCommunityTimeline({ maxId })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { intl } = this.props; @@ -62,6 +66,7 @@ export default class CommunityTimeline extends React.PureComponent { timelineId='community' onLoadMore={this.handleLoadMore} scrollKey='standalone_public_timeline' + shouldUpdateScroll={this.shouldUpdateScroll} trackScroll={false} /> diff --git a/app/javascript/flavours/glitch/features/standalone/hashtag_timeline/index.js b/app/javascript/flavours/glitch/features/standalone/hashtag_timeline/index.js index dc02f1c917..d2b1971ec9 100644 --- a/app/javascript/flavours/glitch/features/standalone/hashtag_timeline/index.js +++ b/app/javascript/flavours/glitch/features/standalone/hashtag_timeline/index.js @@ -41,6 +41,10 @@ export default class HashtagTimeline extends React.PureComponent { this.props.dispatch(expandHashtagTimeline(this.props.hashtag, { maxId })); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { const { hashtag } = this.props; @@ -55,6 +59,7 @@ export default class HashtagTimeline extends React.PureComponent { diff --git a/app/javascript/flavours/glitch/features/status/index.js b/app/javascript/flavours/glitch/features/status/index.js index 333a8b0d2e..e1330b1834 100644 --- a/app/javascript/flavours/glitch/features/status/index.js +++ b/app/javascript/flavours/glitch/features/status/index.js @@ -342,6 +342,10 @@ export default class Status extends ImmutablePureComponent { this.setState({ fullscreen: isFullscreen() }); } + shouldUpdateScroll = (prevRouterProps, { location }) => { + return !(location.state && location.state.mastodonModalOpen) + } + render () { let ancestors, descendants; const { setExpansion } = this; @@ -385,7 +389,7 @@ export default class Status extends ImmutablePureComponent { )} /> - +
{ancestors}