bigbuffet-rw/app/soapbox/components/pull-to-refresh.tsx
marcin mikołajczak 1e74c6d3d7 TypeScript, FC, styles and fixes
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2022-05-28 18:03:19 +02:00

43 lines
1.2 KiB
TypeScript

import React from 'react';
import PTRComponent from 'react-simple-pull-to-refresh';
import { Spinner } from 'soapbox/components/ui';
interface IPullToRefresh {
onRefresh?: () => Promise<any>;
refreshingContent?: JSX.Element | string;
pullingContent?: JSX.Element | string;
}
/**
* PullToRefresh:
* Wrapper around a third-party PTR component with Soapbox defaults.
*/
const PullToRefresh: React.FC<IPullToRefresh> = ({ children, onRefresh, ...rest }): JSX.Element => {
const handleRefresh = () => {
if (onRefresh) {
return onRefresh();
} else {
// If not provided, do nothing
return Promise.resolve();
}
};
return (
<PTRComponent
onRefresh={handleRefresh}
pullingContent={<></>}
// `undefined` will fallback to the default, while `<></>` will render nothing
refreshingContent={onRefresh ? <Spinner size={30} withText={false} /> : <></>}
pullDownThreshold={67}
maxPullDownDistance={95}
resistance={2}
{...rest}
>
{/* This thing really wants a single JSX element as its child (TypeScript), so wrap it in one */}
<>{children}</>
</PTRComponent>
);
};
export default PullToRefresh;