-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add two types of offset-based pagination
- Loading branch information
1 parent
64b7d47
commit 278ceb8
Showing
7 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query getDealsOffsetBased($limit: Float!, $offset: Float!) { | ||
dealsOffsetBased(limit: $limit, offset: $offset) { | ||
id | ||
description | ||
title | ||
__typename | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
query getDealsOffsetBasedExpanded($limitTotal: Float!, $offsetTotal: Float!) { | ||
dealsOffsetBasedExpanded(limitTotal: $limitTotal, offsetTotal: $offsetTotal) { | ||
deals { | ||
description | ||
id | ||
title | ||
} | ||
totalCount | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
GetDealsOffsetBasedDocument, | ||
GetDealsOffsetBasedExpandedDocument, | ||
useGetDealsOffsetBasedExpandedQuery, | ||
useGetDealsOffsetBasedQuery, | ||
} from "@/generated/graphql"; | ||
import { addApolloState, initializeApollo } from "@/utils/apolloClient"; | ||
|
||
export default function BasedPagitanionPage() { | ||
const { data, fetchMore, loading } = useGetDealsOffsetBasedExpandedQuery({ | ||
variables: { | ||
limitTotal: 3, | ||
offsetTotal: 0, | ||
}, | ||
}); | ||
|
||
/* const { data, fetchMore } = useGetDealsOffsetBasedQuery({ | ||
variables: { | ||
limit: 3, | ||
offset: 0, | ||
}, | ||
}); */ | ||
|
||
/* const loadMore = () => { | ||
const currentLength = data.dealsOffsetBased.length || 0; | ||
console.log(currentLength); | ||
fetchMore({ | ||
variables: { | ||
offset: currentLength, | ||
limit: 3, | ||
}, | ||
}); | ||
}; */ | ||
|
||
const loadMore = () => { | ||
const currentLength = data.dealsOffsetBasedExpanded.deals.length || 0; | ||
console.log(currentLength); | ||
fetchMore({ | ||
variables: { | ||
offsetTotal: currentLength, | ||
limitTotal: 3, | ||
}, | ||
}); | ||
}; | ||
|
||
console.log(data); | ||
if (loading) { | ||
return <div>loading</div>; | ||
} | ||
|
||
return ( | ||
<main> | ||
<div> | ||
{data.dealsOffsetBasedExpanded.deals && | ||
data.dealsOffsetBasedExpanded.deals.map((deal) => ( | ||
<div key={deal.id}> | ||
<h1>{deal.title}</h1> | ||
</div> | ||
))} | ||
{/* {data.dealsOffsetBased.deals.map((deal) => ( | ||
<div key={deal.id}> | ||
<h1>{deal.title}</h1> | ||
</div> | ||
))} */} | ||
<button onClick={loadMore}>Načíst další</button> | ||
</div> | ||
</main> | ||
); | ||
} | ||
|
||
export async function getServerSideProps() { | ||
const apolloClient = initializeApollo(); | ||
|
||
/* await apolloClient.query({ | ||
query: GetDealsOffsetBasedDocument, | ||
variables: { | ||
limit: 3, | ||
offset: 0, | ||
}, | ||
}); */ | ||
/* await apolloClient.query({ | ||
query: GetDealsOffsetBasedExpandedDocument, | ||
variables: { | ||
limitTotal: 3, | ||
offsetTotal: 0, | ||
}, | ||
}); */ | ||
|
||
return addApolloState(apolloClient, { | ||
props: {}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters