Repository navigation
Expand file tree
/
Copy pathindex.tsx
More file actions
executable file
·82 lines (76 loc) · 2 KB
/
Copy pathindex.tsx
File metadata and controls
executable file
·82 lines (76 loc) · 2 KB
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
import Head from 'next/head';
import { gql, useQuery } from '@apollo/client';
import Link from 'next/link';
import { AwesomeLink } from '../components/AwesomeLink';
const AllLinksQuery = gql`
query allLinksQuery($first: Int, $after: String) {
links(first: $first, after: $after) {
pageInfo {
endCursor
hasNextPage
}
edges {
cursor
node {
imageUrl
url
title
category
description
id
}
}
}
}
`;
function Home() {
const { data, loading, error, fetchMore } = useQuery(AllLinksQuery, {
variables: { first: 3 },
});
if (loading) return <p>Loading...</p>;
if (error) return <p>Oh no... {error.message}</p>;
const { endCursor, hasNextPage } = data?.links.pageInfo;
return (
<div>
<Head>
<title>Awesome Links</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<div className="container mx-auto max-w-5xl my-20 px-5">
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5">
{data?.links.edges.map(({ node }, i) => (
<Link href={`/link/${node.id}`} key={i}>
<a>
<AwesomeLink
title={node.title}
category={node.category}
url={node.url}
id={node.id}
description={node.description}
imageUrl={node.imageUrl}
/>
</a>
</Link>
))}
</div>
{hasNextPage ? (
<button
className="px-4 py-2 bg-blue-500 text-white rounded my-10"
=> {
fetchMore({
variables: { after: endCursor },
});
}}
>
more
</button>
) : (
<p className="my-10 text-center font-medium">
You've reached the end!
</p>
)}
</div>
</div>
);
}
export default Home;