forked from clintonwoo/hackernews-react-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
55 lines (48 loc) · 1.23 KB
/
index.tsx
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
import { gql } from 'apollo-server-express';
import * as React from 'react';
import { graphql } from 'react-apollo';
import { NewsFeed, newsFeedNewsItemFragment } from '../components/news-feed';
import { withData } from '../helpers/with-data';
import { MainLayout } from '../layouts/main-layout';
const POSTS_PER_PAGE = 30;
const query = gql`
query topNewsItems($type: FeedType!, $first: Int!, $skip: Int!) {
feed(type: $type, first: $first, skip: $skip) {
...NewsFeed
}
}
${newsFeedNewsItemFragment}
`;
export interface ITopNewsFeedProps {
options: {
first: number;
skip: number;
};
}
const TopNewsFeed = graphql<ITopNewsFeedProps>(query, {
options: ({ options: { first, skip } }) => ({
variables: {
first,
skip,
type: 'TOP',
},
}),
props: ({ data }) => ({
data,
}),
})(NewsFeed);
export const IndexPage = withData(props => {
const pageNumber = (props.url.query && +props.url.query.p) || 0;
return (
<MainLayout currentUrl={props.url.pathname}>
<TopNewsFeed
options={{
currentUrl: props.url.pathname,
first: POSTS_PER_PAGE,
skip: POSTS_PER_PAGE * pageNumber,
}}
/>
</MainLayout>
);
});
export default IndexPage;