we can fetch timelines!
This commit is contained in:
		
							parent
							
								
									9753b3d1c6
								
							
						
					
					
						commit
						e7d8632154
					
				
					 3 changed files with 31 additions and 3 deletions
				
			
		|  | @ -48,4 +48,15 @@ export function getAccessTokenFromAuthCode(instanceName, clientId, clientSecret, | |||
|       code: code | ||||
|     }) | ||||
|   }) | ||||
| } | ||||
| 
 | ||||
| export function getHomeTimeline(instanceName, accessToken) { | ||||
|   let url = `https://${instanceName}/api/v1/timelines/home` | ||||
|   return fetch(url, { | ||||
|     method: 'GET', | ||||
|     headers: { | ||||
|       'Accept': 'application/json', | ||||
|       'Authorization': `Bearer ${accessToken}` | ||||
|     } | ||||
|   }) | ||||
| } | ||||
|  | @ -15,13 +15,29 @@ | |||
| </Layout> | ||||
| 
 | ||||
| <script> | ||||
| 	import Layout from './_components/Layout.html'; | ||||
| 	import Layout from './_components/Layout.html' | ||||
| 	import { databasePromise } from './_utils/database' | ||||
|   import { getHomeTimeline } from './_utils/mastodon' | ||||
| 
 | ||||
| 	export default { | ||||
| 	  oncreate: function () { | ||||
|       if (process.browser) { | ||||
|         (async () => { | ||||
|           let db = await databasePromise | ||||
|           let instanceData = await db.get('instance') | ||||
|           if (!instanceData) { | ||||
|             return | ||||
|           } | ||||
|           let response = await (await getHomeTimeline(instanceData.instanceName, instanceData.access_token)).json() | ||||
|           console.log(response) | ||||
| 
 | ||||
|         })() | ||||
|       } | ||||
|     }, | ||||
| 		components: { | ||||
| 			Layout | ||||
| 		} | ||||
| 	}; | ||||
| 	} | ||||
| </script> | ||||
| <style> | ||||
|   .banner { | ||||
|  |  | |||
|  | @ -45,6 +45,7 @@ | |||
|   import Layout from '../_components/Layout.html'; | ||||
|   import { registerApplication, generateAuthLink, getAccessTokenFromAuthCode } from '../_utils/mastodon' | ||||
|   import { databasePromise } from '../_utils/database' | ||||
|   import { goto } from 'sapper/runtime.js' | ||||
| 
 | ||||
|   export default { | ||||
|     oncreate: function () { | ||||
|  | @ -65,7 +66,7 @@ | |||
|             )).json() | ||||
|             instanceData = Object.assign(instanceData, response) | ||||
|             await db.set(`instance`, instanceData) | ||||
|             console.log('response', response) | ||||
|             goto('/') | ||||
|           } | ||||
|         })() | ||||
|       } | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue