2021-07-05 03:19:04 +00:00
|
|
|
import { store } from '../_store/store.js'
|
|
|
|
import { importShowComposeDialog } from '../_components/dialog/asyncDialogs/importShowComposeDialog.js'
|
|
|
|
import { database } from '../_database/database.js'
|
|
|
|
import { doMediaUpload } from './media.js'
|
2019-02-14 02:38:44 +00:00
|
|
|
|
2021-03-21 20:49:59 +00:00
|
|
|
// show a compose dialog, typically invoked by the Web Share API or a PWA shortcut
|
|
|
|
export async function showComposeDialog () {
|
2021-03-14 17:20:23 +00:00
|
|
|
const { isUserLoggedIn } = store.get()
|
|
|
|
if (!isUserLoggedIn) {
|
|
|
|
return
|
|
|
|
}
|
2021-03-21 20:49:59 +00:00
|
|
|
const importShowComposeDialogPromise = importShowComposeDialog() // start promise early
|
|
|
|
|
2021-03-14 17:20:23 +00:00
|
|
|
const data = await database.getWebShareData()
|
|
|
|
|
2021-03-21 20:49:59 +00:00
|
|
|
if (data) {
|
|
|
|
await database.deleteWebShareData() // only need this data once; it came from Web Share (service worker)
|
|
|
|
}
|
2021-03-14 17:20:23 +00:00
|
|
|
|
|
|
|
console.log('share data', data)
|
2021-03-21 20:49:59 +00:00
|
|
|
const { title, text, url, file } = (data || {})
|
2021-03-14 17:20:23 +00:00
|
|
|
|
|
|
|
// url is currently ignored on Android, but one can dream
|
|
|
|
// https://web.dev/web-share-target/#verifying-shared-content
|
|
|
|
const composeText = [title, text, url].filter(Boolean).join('\n\n')
|
|
|
|
|
|
|
|
store.clearComposeData('dialog')
|
|
|
|
store.setComposeData('dialog', { text: composeText })
|
|
|
|
store.save()
|
|
|
|
|
2021-03-21 20:49:59 +00:00
|
|
|
const showComposeDialog = await importShowComposeDialogPromise
|
2021-03-14 17:20:23 +00:00
|
|
|
showComposeDialog()
|
|
|
|
if (file) { // start the upload once the dialog is in view so it shows the loading spinner and everything
|
|
|
|
/* no await */ doMediaUpload('dialog', file)
|
2019-02-14 02:38:44 +00:00
|
|
|
}
|
|
|
|
}
|