From 67824bb5e1657d8aedf5ab11a027a920bf844195 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Fri, 5 Jun 2020 21:45:58 -0400 Subject: [PATCH] Added pull to refresh capability to StatusList, ScrollableList for HomeTimeline to start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - pull to refresh capability to StatusList, ScrollableList for HomeTimeline to start • Updated: - PullToRefresher styles • Todo: - Will add to additional timelines soon --- .../gabsocial/components/pull_to_refresher.js | 7 ++++-- .../gabsocial/components/scrollable_list.js | 8 +++++-- .../gabsocial/components/status_list.js | 24 ++++++++++++++----- app/javascript/styles/global.css | 2 +- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/javascript/gabsocial/components/pull_to_refresher.js b/app/javascript/gabsocial/components/pull_to_refresher.js index 54bfb543..e5f41e47 100644 --- a/app/javascript/gabsocial/components/pull_to_refresher.js +++ b/app/javascript/gabsocial/components/pull_to_refresher.js @@ -1,14 +1,17 @@ import { BREAKPOINT_EXTRA_SMALL } from '../constants' import Responsive from '../features/ui//util/responsive_component' import Icon from './icon' +import Text from './text' export default class PullToRefresher extends PureComponent { render() { return ( -
- +
+
+ +
) diff --git a/app/javascript/gabsocial/components/scrollable_list.js b/app/javascript/gabsocial/components/scrollable_list.js index b05a52df..3b7ffd24 100644 --- a/app/javascript/gabsocial/components/scrollable_list.js +++ b/app/javascript/gabsocial/components/scrollable_list.js @@ -31,6 +31,7 @@ export default class ScrollableList extends PureComponent { } state = { + pullToRefreshTriggered: false, cachedMediaWidth: 250, // Default media/card width using default Gab Social theme } @@ -126,8 +127,11 @@ export default class ScrollableList extends PureComponent { const { innerHeight } = this.window; const offset = scrollHeight - scrollTop - innerHeight; - if (scrollTop < -60 && this.props.onReload) { - // reload + if (scrollTop < -80 && this.props.onReload && !this.state.pullToRefreshTriggered) { + this.setState({ pullToRefreshTriggered: true }) + } else if (scrollTop > -10 && this.props.onReload && this.state.pullToRefreshTriggered) { + this.props.onReload() + this.setState({ pullToRefreshTriggered: false }) } if (600 > offset && this.props.onLoadMore && this.props.hasMore && !this.props.isLoading) { diff --git a/app/javascript/gabsocial/components/status_list.js b/app/javascript/gabsocial/components/status_list.js index a13a55c1..93c65a0a 100644 --- a/app/javascript/gabsocial/components/status_list.js +++ b/app/javascript/gabsocial/components/status_list.js @@ -106,13 +106,20 @@ class StatusList extends ImmutablePureComponent { } state = { + refreshing: false, fetchedContext: false, } componentDidMount() { this.handleDequeueTimeline(); this.fetchPromotedStatus(); - }; + } + + componentDidUpdate(prevProps, prevState) { + if (prevState.refreshing) { + this.setState({ refreshing: false }) + } + } fetchPromotedStatus() { const { promotion, promotedStatus, fetchStatus } = this.props; @@ -157,9 +164,13 @@ class StatusList extends ImmutablePureComponent { this.props.onLoadMore(this.props.statusIds.size > 0 ? this.props.statusIds.last() : undefined) }, 300, { leading: true }) - handleReload = debounce(() => { - this.props.onLoadMore() - }, 300, { leading: true }) + handleOnReload = debounce(() => { + // Only pull to refresh on home timeline for now + if (this.props.scrollKey === 'home_timeline' && !this.state.refreshing) { + this.props.onLoadMore() + this.setState({ refreshing: true }) + } + }, 300, { trailing: true }) _selectChild(index, align_top) { const container = this.node.node; @@ -200,7 +211,7 @@ class StatusList extends ImmutablePureComponent { promotedStatus, ...other } = this.props - const { fetchedContext } = this.state + const { fetchedContext, refreshing } = this.state if (isPartial) { return @@ -262,8 +273,9 @@ class StatusList extends ImmutablePureComponent { {scrollableContent} diff --git a/app/javascript/styles/global.css b/app/javascript/styles/global.css index d57cdbb5..ce323410 100644 --- a/app/javascript/styles/global.css +++ b/app/javascript/styles/global.css @@ -420,7 +420,7 @@ body { /* */ -.topNeg80PX { top: -80px; } +.topNeg50PX { top: -50px; } .top0 { top: 0; } .top120PX { top: 120px; } .top60PC { top: 60%; }