-
Notifications
You must be signed in to change notification settings - Fork 484
/
Pagination.story.js
65 lines (57 loc) · 1.64 KB
/
Pagination.story.js
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
import React from 'react'
import {storiesOf} from '@storybook/react'
import Board from '../src'
storiesOf('Basic Functions', module).add(
'Infinite Scrolling',
() => {
const PER_PAGE = 15
function delayedPromise(durationInMs, resolutionPayload) {
return new Promise(function(resolve) {
setTimeout(function() {
resolve(resolutionPayload)
}, durationInMs)
})
}
function generateCards(requestedPage = 1) {
const cards = []
let fetchedItems = (requestedPage - 1) * PER_PAGE
for (let i = fetchedItems + 1; i <= fetchedItems + PER_PAGE; i++) {
cards.push({
id: `${i}`,
title: `Card${i}`,
description: `Description for #${i}`
})
}
return cards
}
function paginate(requestedPage, laneId) {
// simulate no more cards after page 2
if (requestedPage > 2) {
return delayedPromise(2000, [])
}
let newCards = generateCards(requestedPage)
return delayedPromise(2000, newCards)
}
const data = {
lanes: [
{
id: 'Lane1',
title: 'Lane1',
cards: generateCards()
}
]
}
return <Board data={data} laneSortFunction={(card1, card2) => parseInt(card1.id) - parseInt(card2.id)} onLaneScroll={paginate} />
},
{
info: `
Infinite scroll with onLaneScroll function callback to fetch more items
The callback function passed to onLaneScroll will be of the following form
~~~js
function paginate(requestedPage, laneId) {
return fetchCardsFromBackend(laneId, requestedPage);
};
~~~
`
}
)