fix: pagination bug on misskey favourites
This commit is contained in:
		
							parent
							
								
									cd5dc461f6
								
							
						
					
					
						commit
						19be3779e3
					
				
					 2 changed files with 30 additions and 15 deletions
				
			
		|  | @ -285,13 +285,17 @@ export async function getTimeline(host, token, timeline, max_id, local_only, rem | ||||||
|         headers: { "Authorization": token ? `Bearer ${token}` : null } |         headers: { "Authorization": token ? `Bearer ${token}` : null } | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     let links = _parseLinkHeader(data.headers.get("Link")); |     let res = { | ||||||
|  |         data: await data.json() | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return { |     if(data.headers.has("Link")) { | ||||||
|         data: await data.json(), |         let links = _parseLinkHeader(data.headers.get("Link")); | ||||||
|         prev: links.find(f=>f.rel=="prev"), |         res["prev"] = links.find(f=>f.rel=="prev"); | ||||||
|         next: links.find(f=>f.rel=="next") |         res["next"] = links.find(f=>f.rel=="next"); | ||||||
|     }; |     } | ||||||
|  | 
 | ||||||
|  |     return res; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -312,14 +316,18 @@ export async function getFavourites(host, token, max_id) { | ||||||
|         method: 'GET', |         method: 'GET', | ||||||
|         headers: { "Authorization": token ? `Bearer ${token}` : null } |         headers: { "Authorization": token ? `Bearer ${token}` : null } | ||||||
|     }) |     }) | ||||||
|  |      | ||||||
|  |     let res = { | ||||||
|  |         data: await data.json() | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     let links = _parseLinkHeader(data.headers.get("Link")); |     if(data.headers.has("Link")) { | ||||||
|  |         let links = _parseLinkHeader(data.headers.get("Link")); | ||||||
|  |         res["prev"] = links.find(f=>f.rel=="prev"); | ||||||
|  |         res["next"] = links.find(f=>f.rel=="next"); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     return { |     return res; | ||||||
|         data: await data.json(), |  | ||||||
|         prev: links.find(f=>f.rel=="prev"), |  | ||||||
|         next: links.find(f=>f.rel=="next") |  | ||||||
|     }; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  |  | ||||||
|  | @ -10,12 +10,15 @@ export const timeline = writable([]); | ||||||
| const lang = Lang(); | const lang = Lang(); | ||||||
| 
 | 
 | ||||||
| let loading = false; | let loading = false; | ||||||
| let last_post = false; | let last_post = false;      // last post marker, used for fetching next sequence of posts
 | ||||||
|  | let at_end = false;         // at end of timeline, no next param to paginate
 | ||||||
| 
 | 
 | ||||||
| export async function getTimeline(timelineType = "home", clean, localOnly = false, remoteOnly = false) { | export async function getTimeline(timelineType = "home", clean, localOnly = false, remoteOnly = false) { | ||||||
|     if (loading) return; // no spamming!!
 |     if (loading) return; // no spamming!!
 | ||||||
|     loading = true; |     loading = true; | ||||||
| 
 | 
 | ||||||
|  |     if(at_end) return; | ||||||
|  | 
 | ||||||
|     if(clean) { |     if(clean) { | ||||||
|         timeline.set([]); |         timeline.set([]); | ||||||
|         last_post = false; |         last_post = false; | ||||||
|  | @ -49,9 +52,12 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (!clean) { |     if (!clean && timeline_data.next) { | ||||||
|         last_post = timeline_data.next.url.searchParams.get("max_id") |         last_post = timeline_data.next.url.searchParams.get("max_id") | ||||||
|     }  |     } else if(!timeline_data.next) { | ||||||
|  |         console.log(timeline_data) | ||||||
|  |         at_end = true; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     for (let i in timeline_data.data) { |     for (let i in timeline_data.data) { | ||||||
|         const post_data = timeline_data.data[i]; |         const post_data = timeline_data.data[i]; | ||||||
|  | @ -75,4 +81,5 @@ export async function getTimeline(timelineType = "home", clean, localOnly = fals | ||||||
| export function clearTimeline() { | export function clearTimeline() { | ||||||
|     timeline.set([]); |     timeline.set([]); | ||||||
|     last_post = false; |     last_post = false; | ||||||
|  |     at_end = false; | ||||||
| } | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue