deferred post loading in timeline
This commit is contained in:
		
							parent
							
								
									de71066f19
								
							
						
					
					
						commit
						46f1f93329
					
				
					 2 changed files with 25 additions and 8 deletions
				
			
		|  | @ -2,6 +2,7 @@ | ||||||
|     import Post from './post/Post.svelte'; |     import Post from './post/Post.svelte'; | ||||||
|     import Error from './Error.svelte'; |     import Error from './Error.svelte'; | ||||||
|     import { Client } from './client/client.js'; |     import { Client } from './client/client.js'; | ||||||
|  |     import { parsePost } from './client/api.js'; | ||||||
| 
 | 
 | ||||||
|     let client = Client.get(); |     let client = Client.get(); | ||||||
|     let posts = []; |     let posts = []; | ||||||
|  | @ -13,18 +14,32 @@ | ||||||
|         if (loading) return; // no spamming!! |         if (loading) return; // no spamming!! | ||||||
|         loading = true; |         loading = true; | ||||||
| 
 | 
 | ||||||
|         let new_posts = []; |         let timeline_data; | ||||||
|         if (posts.length === 0) new_posts = await client.getTimeline() |         if (posts.length === 0) timeline_data = await client.getTimeline() | ||||||
|         else new_posts = await client.getTimeline(posts[posts.length - 1].id); |         else timeline_data = await client.getTimeline(posts[posts.length - 1].id); | ||||||
| 
 | 
 | ||||||
|         if (!new_posts) { |         if (!timeline_data) { | ||||||
|             console.error(`Failed to retrieve timeline posts.`); |             console.error(`Failed to retrieve timeline.`); | ||||||
|             loading = false; |             loading = false; | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         posts = [...posts, ...new_posts]; |         for (let i in timeline_data) { | ||||||
| 
 |             const post_data = timeline_data[i]; | ||||||
|  |             const post = await parsePost(post_data, 1); | ||||||
|  |             if (!post) { | ||||||
|  |                 if (post === null || post === undefined) { | ||||||
|  |                     if (post_data.id) { | ||||||
|  |                         console.warn("Failed to parse post #" + post_data.id); | ||||||
|  |                     } else { | ||||||
|  |                         console.warn("Failed to parse post:"); | ||||||
|  |                         console.warn(post_data); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |                 continue; | ||||||
|  |             } | ||||||
|  |             posts = [...posts, post]; | ||||||
|  |         } | ||||||
|         loading = false; |         loading = false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -92,6 +92,8 @@ export async function getTimeline(last_post_id) { | ||||||
|         headers: { "Authorization": "Bearer " + client.app.token } |         headers: { "Authorization": "Bearer " + client.app.token } | ||||||
|     }).then(res => res.json()); |     }).then(res => res.json()); | ||||||
| 
 | 
 | ||||||
|  |     return data; | ||||||
|  | 
 | ||||||
|     let posts = []; |     let posts = []; | ||||||
|     for (let i in data) { |     for (let i in data) { | ||||||
|         const post_data = data[i]; |         const post_data = data[i]; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue