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 Error from './Error.svelte'; | ||||
|     import { Client } from './client/client.js'; | ||||
|     import { parsePost } from './client/api.js'; | ||||
| 
 | ||||
|     let client = Client.get(); | ||||
|     let posts = []; | ||||
|  | @ -13,18 +14,32 @@ | |||
|         if (loading) return; // no spamming!! | ||||
|         loading = true; | ||||
| 
 | ||||
|         let new_posts = []; | ||||
|         if (posts.length === 0) new_posts = await client.getTimeline() | ||||
|         else new_posts = await client.getTimeline(posts[posts.length - 1].id); | ||||
|         let timeline_data; | ||||
|         if (posts.length === 0) timeline_data = await client.getTimeline() | ||||
|         else timeline_data = await client.getTimeline(posts[posts.length - 1].id); | ||||
| 
 | ||||
|         if (!new_posts) { | ||||
|             console.error(`Failed to retrieve timeline posts.`); | ||||
|         if (!timeline_data) { | ||||
|             console.error(`Failed to retrieve timeline.`); | ||||
|             loading = false; | ||||
|             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; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -92,6 +92,8 @@ export async function getTimeline(last_post_id) { | |||
|         headers: { "Authorization": "Bearer " + client.app.token } | ||||
|     }).then(res => res.json()); | ||||
| 
 | ||||
|     return data; | ||||
| 
 | ||||
|     let posts = []; | ||||
|     for (let i in data) { | ||||
|         const post_data = data[i]; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue