forked from clintonwoo/hackernews-react-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathask.tsx
57 lines (49 loc) · 1.3 KB
/
ask.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
56
57
import { gql } from 'apollo-server-express';
import * as React from 'react';
import { graphql } from 'react-apollo';
import { NewsFeed, newsFeedNewsItemFragment } from '../components/news-feed';
import { FeedType } from '../data/models/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 IAskPageProps {
options: {
first: number;
skip: number;
};
}
const AskPageNewsFeedWithGraphQL = graphql<IAskPageProps>(query, {
options: ({ options: { first, skip } }) => ({
variables: {
first,
skip,
type: FeedType.ASK,
},
}),
props: ({ data }) => ({
data,
}),
})(NewsFeed);
export const AskPage = withData(props => {
const pageNumber = (props.url.query && +props.url.query.p) || 0;
return (
<MainLayout currentUrl={props.url.pathname}>
<AskPageNewsFeedWithGraphQL
options={{
currentUrl: props.url.pathname,
first: POSTS_PER_PAGE,
skip: POSTS_PER_PAGE * pageNumber,
}}
/>
</MainLayout>
);
});
export default AskPage;