proper actions for accountId page
This commit is contained in:
parent
ad1c9cea66
commit
e53ed9bc40
|
@ -222,6 +222,14 @@ export async function getAccount(instanceName, accountId) {
|
|||
return result
|
||||
}
|
||||
|
||||
export async function setAccount(instanceName, account) {
|
||||
setInCache(accountsCache, instanceName, account.id, account)
|
||||
const db = await getDatabase(instanceName)
|
||||
return await dbPromise(db, ACCOUNTS_STORE, 'readwrite', (store) => {
|
||||
store.put(account)
|
||||
})
|
||||
}
|
||||
|
||||
//
|
||||
// lifecycle
|
||||
//
|
||||
|
|
|
@ -29,40 +29,20 @@
|
|||
import { store } from '../_utils/store.js'
|
||||
import HiddenFromSSR from '../_components/HiddenFromSSR'
|
||||
import DynamicPageBanner from '../_components/DynamicPageBanner.html'
|
||||
import { getAccount } from '../_utils/mastodon/user'
|
||||
import { database } from '../_utils/database/database'
|
||||
import { showAccountProfile } from './_actions/[accountId]'
|
||||
|
||||
export default {
|
||||
oncreate() {
|
||||
let currentInstance = this.store.get('currentInstance')
|
||||
let accessToken = this.store.get('accessToken')
|
||||
let accountId = this.get('params').accountId
|
||||
database.getAccount(currentInstance, accountId).then(account => {
|
||||
this.set({cachedAccount: account})
|
||||
})
|
||||
getAccount(currentInstance, accessToken, accountId).then(account => {
|
||||
this.set({remoteAccount: account})
|
||||
})
|
||||
showAccountProfile(accountId)
|
||||
},
|
||||
store: () => store,
|
||||
computed: {
|
||||
remoteProfileName: (remoteAccount) => {
|
||||
return remoteAccount && ('@' + remoteAccount.acct)
|
||||
profileName: ($currentAccountProfile) => {
|
||||
return $currentAccountProfile && ('@' + $currentAccountProfile.acct)
|
||||
},
|
||||
remoteShortProfileName: (remoteAccount) => {
|
||||
return remoteAccount && ('@' + remoteAccount.username)
|
||||
},
|
||||
cachedProfileName: (cachedAccount) => {
|
||||
return cachedAccount && ('@' + cachedAccount.acct)
|
||||
},
|
||||
cachedShortProfileName: (cachedAccount) => {
|
||||
return cachedAccount && ('@' + cachedAccount.username)
|
||||
},
|
||||
profileName: (remoteProfileName, cachedProfileName) => {
|
||||
return remoteProfileName || cachedProfileName || ''
|
||||
},
|
||||
shortProfileName: (remoteShortProfileName, cachedShortProfileName) => {
|
||||
return remoteShortProfileName || cachedShortProfileName || ''
|
||||
shortProfileName: ($currentAccountProfile) => {
|
||||
return $currentAccountProfile && ('@' + $currentAccountProfile.username)
|
||||
}
|
||||
},
|
||||
components: {
|
||||
|
|
24
routes/accounts/_actions/[accountId].js
Normal file
24
routes/accounts/_actions/[accountId].js
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { getAccount } from '../../_utils/mastodon/user'
|
||||
import { database } from '../../_utils/database/database'
|
||||
import { store } from '../../_utils/store'
|
||||
|
||||
export async function showAccountProfile(accountId) {
|
||||
store.set({currentAccountProfile: null})
|
||||
let instanceName = store.get('currentInstance')
|
||||
let accessToken = store.get('accessToken')
|
||||
|
||||
let localPromise = database.getAccount(instanceName, accountId)
|
||||
let remotePromise = getAccount(instanceName, accessToken, accountId).then(account => {
|
||||
database.setAccount(instanceName, account)
|
||||
return account
|
||||
})
|
||||
|
||||
let localAccount = await localPromise
|
||||
store.set({currentAccountProfile: localAccount})
|
||||
try {
|
||||
let remoteAccount = await remotePromise
|
||||
store.set({currentAccountProfile: remoteAccount})
|
||||
} catch (e) {
|
||||
console.error("couldn't fetch profile", e)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue