we can fetch timelines!

This commit is contained in:
Nolan Lawson 2018-01-07 22:13:15 -08:00
parent 9753b3d1c6
commit e7d8632154
3 changed files with 31 additions and 3 deletions

View file

@ -49,3 +49,14 @@ export function getAccessTokenFromAuthCode(instanceName, clientId, clientSecret,
}) })
}) })
} }
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}`
}
})
}

View file

@ -15,13 +15,29 @@
</Layout> </Layout>
<script> <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 { 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: { components: {
Layout Layout
} }
}; }
</script> </script>
<style> <style>
.banner { .banner {

View file

@ -45,6 +45,7 @@
import Layout from '../_components/Layout.html'; import Layout from '../_components/Layout.html';
import { registerApplication, generateAuthLink, getAccessTokenFromAuthCode } from '../_utils/mastodon' import { registerApplication, generateAuthLink, getAccessTokenFromAuthCode } from '../_utils/mastodon'
import { databasePromise } from '../_utils/database' import { databasePromise } from '../_utils/database'
import { goto } from 'sapper/runtime.js'
export default { export default {
oncreate: function () { oncreate: function () {
@ -65,7 +66,7 @@
)).json() )).json()
instanceData = Object.assign(instanceData, response) instanceData = Object.assign(instanceData, response)
await db.set(`instance`, instanceData) await db.set(`instance`, instanceData)
console.log('response', response) goto('/')
} }
})() })()
} }