perf: avoid importing the DB for non-logged-in users (#1998)

This commit is contained in:
Nolan Lawson 2021-03-15 17:25:20 -07:00 committed by GitHub
parent c3fb1e2038
commit a7fb2e68dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 13 deletions

View file

@ -8,26 +8,13 @@
import { store } from '../_store/store.js'
import TimelineHomePage from '../_components/TimelineHomePage.html'
import { observe } from 'svelte-extras'
import { showShareDialogIfNecessary } from '../_actions/showShareDialogIfNecessary'
import { doQuickLoginIfNecessary } from '../_actions/doQuickLoginIfNecessary'
export default {
async oncreate () {
doQuickLoginIfNecessary()
let observed = false
this.observe('currentVerifyCredentials', verifyCredentials => {
if (verifyCredentials && !observed) {
// when the verifyCredentials object is available, we can check to see
// if the user is trying to share something, then share it
observed = true
/* no await */ showShareDialogIfNecessary()
}
})
},
store: () => store,
computed: {
currentVerifyCredentials: ({ $currentVerifyCredentials }) => $currentVerifyCredentials
},
methods: {
observe
},

View file

@ -7,6 +7,7 @@ import { customScrollbarObservers } from './customScrollbarObservers'
import { customEmojiObservers } from './customEmojiObservers'
import { cleanup } from './cleanup'
import { wordFilterObservers } from './wordFilterObservers'
import { showShareDialogObservers } from './showShareDialogObservers'
// These observers can be lazy-loaded when the user is actually logged in.
// Prevents circular dependencies and reduces the size of main.js
@ -19,5 +20,6 @@ export function loggedInObservers () {
notificationPermissionObservers()
customScrollbarObservers()
customEmojiObservers()
showShareDialogObservers()
cleanup()
}

View file

@ -0,0 +1,19 @@
import { store } from '../store'
import { showShareDialogIfNecessary } from '../../_actions/showShareDialogIfNecessary'
// If the user is logged in, and if the Service Worker handled a POST and set special data
// in IndexedDB, then we want to handle it on the home page.
export function showShareDialogObservers () {
let observedOnce = false
store.observe('currentVerifyCredentials', verifyCredentials => {
if (verifyCredentials && !observedOnce) {
// when the verifyCredentials object is available, we can check to see
// if the user is trying to share something, then share it
observedOnce = true
const { currentPage } = store.get()
if (currentPage === 'home') {
/* no await */ showShareDialogIfNecessary()
}
}
})
}