more refinements to fetching and offline

This commit is contained in:
Nolan Lawson 2018-01-18 21:52:58 -08:00
parent b0c1844ed2
commit 42fd153364
5 changed files with 30 additions and 7 deletions

View File

@ -17,9 +17,11 @@
<script> <script>
import VirtualListItem from './VirtualListItem' import VirtualListItem from './VirtualListItem'
import { virtualListStore } from '../_utils/virtualListStore' import { virtualListStore } from '../_utils/virtualListStore'
import throttle from 'lodash/throttle'
import { mark, stop } from '../_utils/marks' import { mark, stop } from '../_utils/marks'
const DISTANCE_FROM_BOTTOM_TO_FIRE = 200 const DISTANCE_FROM_BOTTOM_TO_FIRE = 400
const SCROLL_TO_BOTTOM_DELAY = 1000
export default { export default {
oncreate () { oncreate () {
@ -29,6 +31,9 @@
items: items items: items
}) })
stop('set items') stop('set items')
this.fireScrollToBottom = throttle(() => {
this.fire('scrollToBottom')
}, SCROLL_TO_BOTTOM_DELAY)
}) })
let observedOnce = false let observedOnce = false
@ -40,7 +45,7 @@
} }
if (distanceFromBottom >= 0 && if (distanceFromBottom >= 0 &&
distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) { distanceFromBottom <= DISTANCE_FROM_BOTTOM_TO_FIRE) {
this.fire('scrollToBottom') this.fireScrollToBottom()
} }
}) })
}, },

View File

@ -2,9 +2,10 @@ const WEBSITE = 'https://pinafore.social'
const SCOPES = 'read write follow' const SCOPES = 'read write follow'
const CLIENT_NAME = 'Pinafore' const CLIENT_NAME = 'Pinafore'
import { post, get, paramsString } from '../ajax' import { post, get, paramsString } from '../ajax'
import { basename } from './utils'
export function registerApplication(instanceName, redirectUri) { export function registerApplication(instanceName, redirectUri) {
const url = `https://${instanceName}/api/v1/apps` const url = `${basename(instanceName)}/api/v1/apps`
return post(url, { return post(url, {
client_name: CLIENT_NAME, client_name: CLIENT_NAME,
redirect_uris: redirectUri, redirect_uris: redirectUri,
@ -20,11 +21,11 @@ export function generateAuthLink(instanceName, clientId, redirectUri) {
'response_type': 'code', 'response_type': 'code',
'scope': SCOPES 'scope': SCOPES
}) })
return `https://${instanceName}/oauth/authorize?${params}` return `${basename(instanceName)}/oauth/authorize?${params}`
} }
export function getAccessTokenFromAuthCode(instanceName, clientId, clientSecret, code, redirectUri) { export function getAccessTokenFromAuthCode(instanceName, clientId, clientSecret, code, redirectUri) {
let url = `https://${instanceName}/oauth/token` let url = `${basename(instanceName)}/oauth/token`
return post(url, { return post(url, {
client_id: clientId, client_id: clientId,
client_secret: clientSecret, client_secret: clientSecret,

View File

@ -1,7 +1,8 @@
import { get, paramsString } from '../ajax' import { get, paramsString } from '../ajax'
import { basename } from './utils'
export function getHomeTimeline(instanceName, accessToken, maxId, since) { export function getHomeTimeline(instanceName, accessToken, maxId, since) {
let url = `https://${instanceName}/api/v1/timelines/home` let url = `${basename(instanceName)}/api/v1/timelines/home`
let params = {} let params = {}
if (since) { if (since) {

View File

@ -1,7 +1,8 @@
import { get } from '../ajax' import { get } from '../ajax'
import { basename } from './utils'
export function getThisUserAccount(instanceName, accessToken) { export function getThisUserAccount(instanceName, accessToken) {
let url = `https://${instanceName}/api/v1/accounts/verify_credentials` let url = `${basename(instanceName)}/api/v1/accounts/verify_credentials`
return get(url, { return get(url, {
'Authorization': `Bearer ${accessToken}` 'Authorization': `Bearer ${accessToken}`
}) })

View File

@ -0,0 +1,15 @@
const isLocalhost = process.browser && process.env.NODE_ENV !== 'production' &&
(document.location.hostname === 'localhost' ||
document.location.hostname === '127.0.0.1')
function targetIsLocalhost(instanceName) {
return process.browser && process.env.NODE_ENV !== 'production' &&
(instanceName === 'localhost:3000' || instanceName === '127.0.0.1:3000')
}
export function basename(instanceName) {
if (isLocalhost && targetIsLocalhost(instanceName)) {
return `http://${instanceName}`
}
return `https://${instanceName}`
}