@kiwicom/smart-faq
Version:
39 lines (33 loc) • 1.03 kB
JavaScript
// @flow
import type { Props as FuturePaginationRelayTypes } from './FutureBookingsPaginationContainer';
import type { Props as PastPaginationRelayTypes } from './PastBookingsPaginationContainer';
type PaginatorPropsType = {
props: FuturePaginationRelayTypes | PastPaginationRelayTypes,
+setState: (state?: Object, callback?: () => void) => void,
};
export const getFragmentVariables = (
prevVars: Object,
totalCount: number,
): Object => ({
...prevVars,
count: totalCount,
});
export const getVariables = (
props: Object,
{ count, cursor }: { count: number, cursor: ?string },
variables: Object,
): Object => ({
first: count,
after: cursor,
brand: variables.brand,
});
export const createPaginator = (paginatorProps: PaginatorPropsType) => {
const { relay } = paginatorProps.props;
if (relay.hasMore() && !relay.isLoading()) {
paginatorProps.setState({ isLoading: true }, () => {
relay.loadMore(3, () => {
paginatorProps.setState({ isLoading: false });
});
});
}
};