-
Notifications
You must be signed in to change notification settings - Fork 0
/
LikedContentFeedConnected.js
86 lines (75 loc) · 2.4 KB
/
LikedContentFeedConnected.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { Query } from '@apollo/client/react/components';
import { get } from 'lodash';
import { BackgroundView, FeedView } from '@apollosproject/ui-kit';
import fetchMoreResolver from '../utils/fetchMoreResolver';
import ContentCardConnected from '../ContentCardConnected';
import GET_LIKED_CONTENT from './getLikedContent';
/** A FeedView wrapped in a query to pull content data. */
class LikedContentFeedConnected extends PureComponent {
static propTypes = {
Component: PropTypes.oneOfType([
PropTypes.node,
PropTypes.func,
PropTypes.object, // type check for React fragments
]),
ContentCardComponent: PropTypes.oneOfType([
PropTypes.node,
PropTypes.func,
PropTypes.object, // type check for React fragments
]),
/** Functions passed down from React Navigation to use in navigating to/from
* items in the feed.
*/
navigation: PropTypes.shape({
navigate: PropTypes.func,
}),
};
static defaultProps = {
Component: FeedView,
ContentCardComponent: ContentCardConnected,
};
/** Function that is called when a card in the feed is pressed.
* Takes the user to the ContentSingle
*/
handleOnPress = (item) =>
this.props.navigation.navigate('ContentSingle', {
itemId: item.id,
sharing: item.sharing,
});
getContent = (data) =>
get(data, 'likedContent.edges', []).map((edge) => edge.node);
fetchMore = (data, fetchMore, variables) =>
fetchMoreResolver({
collectionName: 'likedContent',
fetchMore,
variables,
data,
});
render() {
const { Component, ContentCardComponent } = this.props;
return (
<BackgroundView avoidHeader>
<Query
query={GET_LIKED_CONTENT}
fetchPolicy="cache-and-network"
variables={{ first: 20 }}
>
{({ loading, error, data, refetch, fetchMore, variables }) => (
<Component
ListItemComponent={ContentCardComponent}
content={this.getContent(data)}
isLoading={loading}
error={error}
refetch={refetch}
onPressItem={this.handleOnPress}
fetchMore={this.fetchMore(data, fetchMore, variables)}
/>
)}
</Query>
</BackgroundView>
);
}
}
export default LikedContentFeedConnected;