| 101 | export const CardViewExample = props => { |
| 102 | let list = useAsyncList({ |
| 103 | async load({signal, cursor, items}) { |
| 104 | let page = cursor || 1; |
| 105 | let res = await fetch( |
| 106 | `https://api.unsplash.com/topics/nature/photos?page=${page}&per_page=30&client_id=AJuU-FPh11hn7RuumUllp4ppT8kgiLS7LtOHp_sp4nc`, |
| 107 | {signal} |
| 108 | ); |
| 109 | let nextItems = await res.json(); |
| 110 | // Filter duplicates which might be returned by the API. |
| 111 | let existingKeys = new Set(items.map(i => i.id)); |
| 112 | nextItems = nextItems.filter( |
| 113 | i => !existingKeys.has(i.id) && (i.description || i.alt_description) |
| 114 | ); |
| 115 | return {items: nextItems, cursor: nextItems.length ? page + 1 : null}; |
| 116 | } |
| 117 | }); |
| 118 | |
| 119 | let loadingState = props.loadingState === 'idle' ? list.loadingState : props.loadingState; |