@@ -25,6 +25,7 @@ import {
2525 reconcilePledge ,
2626 refundCampaign ,
2727 softDeleteCampaign ,
28+ CampaignListResponse ,
2829} from "./services/api" ;
2930import {
3031 submitFreighterClaim ,
@@ -123,6 +124,7 @@ function App() {
123124 const connectedWallet = freighter . publicKey ;
124125
125126 const [ campaigns , setCampaigns ] = useState < Campaign [ ] > ( [ ] ) ;
127+ const [ campaignsPagination , setCampaignsPagination ] = useState < { total : number ; page : number ; pageSize : number ; hasMore : boolean } > ( { total : 0 , page : 1 , pageSize : 20 , hasMore : false } ) ;
126128 const [ issues , setIssues ] = useState < OpenIssue [ ] > ( [ ] ) ;
127129 const [ history , setHistory ] = useState < CampaignEvent [ ] > ( [ ] ) ;
128130 const [ appConfig , setAppConfig ] = useState < AppConfig | null > ( null ) ;
@@ -189,16 +191,22 @@ function App() {
189191 } ;
190192 } , [ transactionPreview ] ) ;
191193
192- async function refreshCampaigns ( searchQuery : string = '' , nextSelectedId ?: string | null ) : Promise < Campaign [ ] > {
194+ async function refreshCampaigns ( searchQuery : string = '' , nextSelectedId ?: string | null , page : number = 1 ) : Promise < Campaign [ ] > {
193195 setIsCampaignsLoading ( true ) ;
194196 try {
195- const data = await listCampaigns ( { search : searchQuery } ) ;
196- setCampaigns ( data ) ;
197+ const response = await listCampaigns ( { search : searchQuery , page, pageSize : 20 } ) ;
198+ setCampaigns ( response . data ) ;
199+ setCampaignsPagination ( {
200+ total : response . total ,
201+ page : response . page ,
202+ pageSize : response . pageSize ,
203+ hasMore : response . hasMore ,
204+ } ) ;
197205
198206 const requestedId = nextSelectedId ?? selectedCampaignId ;
199- const nextId = requestedId ?? data [ 0 ] ?. id ?? null ;
200- const exists = nextId ? data . some ( ( campaign ) => campaign . id === nextId ) : false ;
201- const resolvedId = exists ? nextId : data [ 0 ] ?. id ?? null ;
207+ const nextId = requestedId ?? response . data [ 0 ] ?. id ?? null ;
208+ const exists = nextId ? response . data . some ( ( campaign ) => campaign . id === nextId ) : false ;
209+ const resolvedId = exists ? nextId : response . data [ 0 ] ?. id ?? null ;
202210
203211 setInvalidUrlCampaignId ( requestedId && ! exists ? requestedId : null ) ;
204212 setSelectedCampaignId ( resolvedId ) ;
@@ -208,7 +216,7 @@ function App() {
208216 setHistory ( [ ] ) ;
209217 }
210218
211- return data ;
219+ return response . data ;
212220 } finally {
213221 setIsCampaignsLoading ( false ) ;
214222 }
@@ -253,7 +261,7 @@ function App() {
253261 const [ configResult , issuesResult , campaignsResult ] = await Promise . allSettled ( [
254262 getAppConfig ( ) ,
255263 listOpenIssues ( ) ,
256- listCampaigns ( { search : '' } ) ,
264+ listCampaigns ( { search : '' , page : 1 , pageSize : 20 } ) ,
257265 ] ) ;
258266
259267 if ( cancelled ) {
@@ -271,12 +279,18 @@ function App() {
271279 }
272280
273281 if ( campaignsResult . status === "fulfilled" ) {
274- const data = campaignsResult . value ;
275- setCampaigns ( data ) ;
282+ const response = campaignsResult . value ;
283+ setCampaigns ( response . data ) ;
284+ setCampaignsPagination ( {
285+ total : response . total ,
286+ page : response . page ,
287+ pageSize : response . pageSize ,
288+ hasMore : response . hasMore ,
289+ } ) ;
276290
277- const nextId = requestedCampaignId ?? data [ 0 ] ?. id ?? null ;
278- const exists = nextId ? data . some ( ( campaign ) => campaign . id === nextId ) : false ;
279- const resolvedId = exists ? nextId : data [ 0 ] ?. id ?? null ;
291+ const nextId = requestedCampaignId ?? response . data [ 0 ] ?. id ?? null ;
292+ const exists = nextId ? response . data . some ( ( campaign ) => campaign . id === nextId ) : false ;
293+ const resolvedId = exists ? nextId : response . data [ 0 ] ?. id ?? null ;
280294
281295 setInvalidUrlCampaignId ( requestedCampaignId && ! exists ? requestedCampaignId : null ) ;
282296 setSelectedCampaignId ( resolvedId ) ;
@@ -633,10 +647,16 @@ function App() {
633647 selectedCampaignId = { selectedCampaignId }
634648 onSelect = { handleSelect }
635649 onSearchChange = { ( query ) => {
636- void refreshCampaigns ( query ) ;
650+ void refreshCampaigns ( query , undefined , 1 ) ;
651+ } }
652+ onPageChange = { ( page ) => {
653+ void refreshCampaigns ( "" , undefined , page ) ;
637654 } }
638655 isLoading = { isCampaignsLoading || initialLoad }
639656 invalidUrlCampaignId = { invalidUrlCampaignId }
657+ currentPage = { campaignsPagination . page }
658+ hasMore = { campaignsPagination . hasMore }
659+ totalCampaigns = { campaignsPagination . total }
640660 />
641661 </ ErrorBoundary >
642662
0 commit comments