forked from clintonwoo/hackernews-react-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbest.tsx
45 lines (36 loc) · 1.22 KB
/
best.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
import gql from 'graphql-tag';
import * as React from 'react';
import { useQuery } from '@apollo/react-hooks';
import { NewsFeed, newsFeedNewsItemFragment } from '../src/components/news-feed';
import { FeedType } from '../src/data/models';
import { withDataAndRouter } from '../src/helpers/with-data';
import { MainLayout } from '../src/layouts/main-layout';
import { POSTS_PER_PAGE } from '../src/config';
const query = gql`
query bestNewsItems($type: FeedType!, $first: Int!, $skip: Int!) {
feed(type: $type, first: $first, skip: $skip) {
...NewsFeed
}
}
${newsFeedNewsItemFragment}
`;
export interface IBestNewsFeedProps {
options: {
currentUrl: string;
first: number;
skip: number;
};
}
export function BestPage(props): JSX.Element {
const { router } = props;
const pageNumber = (router.query && +router.query.p) || 0;
const first = POSTS_PER_PAGE;
const skip = POSTS_PER_PAGE * pageNumber;
const { data } = useQuery(query, { variables: { first, skip, type: FeedType.BEST } });
return (
<MainLayout currentUrl={router.pathname}>
<NewsFeed data={data} currentUrl={router.pathname} first={first} skip={skip} />
</MainLayout>
);
}
export default withDataAndRouter(BestPage);