sforkowany z mirror/soapbox
Status: implement actual Pull to Refresh on threads, add PullToRefresh custom component
rodzic
4eb9b3c26e
commit
16f6644602
|
@ -0,0 +1,43 @@
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import PTRComponent from 'react-simple-pull-to-refresh';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PullToRefresh:
|
||||||
|
* Wrapper around a third-party PTR component with Soapbox defaults.
|
||||||
|
*/
|
||||||
|
export default class PullToRefresh extends React.Component {
|
||||||
|
|
||||||
|
static propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
onRefresh: PropTypes.func,
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRefresh = () => {
|
||||||
|
const { onRefresh } = this.props;
|
||||||
|
|
||||||
|
if (onRefresh) {
|
||||||
|
return onRefresh();
|
||||||
|
} else {
|
||||||
|
// If not provided, do nothing
|
||||||
|
return new Promise(resolve => resolve());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { children, onRefresh, ...rest } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PTRComponent
|
||||||
|
onRefresh={this.handleRefresh}
|
||||||
|
pullingContent={null}
|
||||||
|
// `undefined` will fallback to the default, while `null` will render nothing
|
||||||
|
refreshingContent={onRefresh ? undefined : null}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</PTRComponent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import PullToRefresh from 'react-simple-pull-to-refresh';
|
import PullToRefresh from './pull_to_refresh';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pullable:
|
* Pullable:
|
||||||
|
@ -13,16 +13,11 @@ export default class Pullable extends React.Component {
|
||||||
children: PropTypes.node.isRequired,
|
children: PropTypes.node.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRefresh = () => {
|
|
||||||
return new Promise(resolve => resolve());
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children } = this.props;
|
const { children } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PullToRefresh
|
<PullToRefresh
|
||||||
onRefresh={this.handleRefresh}
|
|
||||||
pullingContent={null}
|
pullingContent={null}
|
||||||
refreshingContent={null}
|
refreshingContent={null}
|
||||||
>
|
>
|
||||||
|
|
|
@ -52,7 +52,7 @@ import ThreadStatus from './components/thread_status';
|
||||||
import PendingStatus from 'soapbox/features/ui/components/pending_status';
|
import PendingStatus from 'soapbox/features/ui/components/pending_status';
|
||||||
import SubNavigation from 'soapbox/components/sub_navigation';
|
import SubNavigation from 'soapbox/components/sub_navigation';
|
||||||
import { launchChat } from 'soapbox/actions/chats';
|
import { launchChat } from 'soapbox/actions/chats';
|
||||||
import Pullable from 'soapbox/components/pullable';
|
import PullToRefresh from 'soapbox/components/pull_to_refresh';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
title: { id: 'status.title', defaultMessage: 'Post' },
|
title: { id: 'status.title', defaultMessage: 'Post' },
|
||||||
|
@ -167,8 +167,13 @@ class Status extends ImmutablePureComponent {
|
||||||
emojiSelectorFocused: false,
|
emojiSelectorFocused: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fetchStatus = () => {
|
||||||
|
const { dispatch, params } = this.props;
|
||||||
|
return dispatch(fetchStatus(params.statusId));
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.dispatch(fetchStatus(this.props.params.statusId));
|
this.fetchStatus();
|
||||||
attachFullscreenListener(this.onFullScreenChange);
|
attachFullscreenListener(this.onFullScreenChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,6 +569,13 @@ class Status extends ImmutablePureComponent {
|
||||||
this.setState({ fullscreen: isFullscreen() });
|
this.setState({ fullscreen: isFullscreen() });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleRefresh = () => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
this.fetchStatus();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let ancestors, descendants;
|
let ancestors, descendants;
|
||||||
const { status, ancestorsIds, descendantsIds, intl, domain } = this.props;
|
const { status, ancestorsIds, descendantsIds, intl, domain } = this.props;
|
||||||
|
@ -627,7 +639,7 @@ class Status extends ImmutablePureComponent {
|
||||||
*/}
|
*/}
|
||||||
|
|
||||||
<div ref={this.setRef} className='thread'>
|
<div ref={this.setRef} className='thread'>
|
||||||
<Pullable>
|
<PullToRefresh onRefresh={this.handleRefresh}>
|
||||||
{ancestors && (
|
{ancestors && (
|
||||||
<div className='thread__ancestors'>{ancestors}</div>
|
<div className='thread__ancestors'>{ancestors}</div>
|
||||||
)}
|
)}
|
||||||
|
@ -678,7 +690,7 @@ class Status extends ImmutablePureComponent {
|
||||||
{descendants && (
|
{descendants && (
|
||||||
<div className='thread__descendants'>{descendants}</div>
|
<div className='thread__descendants'>{descendants}</div>
|
||||||
)}
|
)}
|
||||||
</Pullable>
|
</PullToRefresh>
|
||||||
</div>
|
</div>
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
|
|
Ładowanie…
Reference in New Issue