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
|
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
|
// lifecycle
|
||||||
//
|
//
|
||||||
|
|
|
@ -29,40 +29,20 @@
|
||||||
import { store } from '../_utils/store.js'
|
import { store } from '../_utils/store.js'
|
||||||
import HiddenFromSSR from '../_components/HiddenFromSSR'
|
import HiddenFromSSR from '../_components/HiddenFromSSR'
|
||||||
import DynamicPageBanner from '../_components/DynamicPageBanner.html'
|
import DynamicPageBanner from '../_components/DynamicPageBanner.html'
|
||||||
import { getAccount } from '../_utils/mastodon/user'
|
import { showAccountProfile } from './_actions/[accountId]'
|
||||||
import { database } from '../_utils/database/database'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate() {
|
oncreate() {
|
||||||
let currentInstance = this.store.get('currentInstance')
|
|
||||||
let accessToken = this.store.get('accessToken')
|
|
||||||
let accountId = this.get('params').accountId
|
let accountId = this.get('params').accountId
|
||||||
database.getAccount(currentInstance, accountId).then(account => {
|
showAccountProfile(accountId)
|
||||||
this.set({cachedAccount: account})
|
|
||||||
})
|
|
||||||
getAccount(currentInstance, accessToken, accountId).then(account => {
|
|
||||||
this.set({remoteAccount: account})
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
store: () => store,
|
store: () => store,
|
||||||
computed: {
|
computed: {
|
||||||
remoteProfileName: (remoteAccount) => {
|
profileName: ($currentAccountProfile) => {
|
||||||
return remoteAccount && ('@' + remoteAccount.acct)
|
return $currentAccountProfile && ('@' + $currentAccountProfile.acct)
|
||||||
},
|
},
|
||||||
remoteShortProfileName: (remoteAccount) => {
|
shortProfileName: ($currentAccountProfile) => {
|
||||||
return remoteAccount && ('@' + remoteAccount.username)
|
return $currentAccountProfile && ('@' + $currentAccountProfile.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 || ''
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
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