pinafore/src/routes/_actions/setDomainBlocked.js

27 lines
952 B
JavaScript
Raw Normal View History

import { store } from '../_store/store'
import { blockDomain, unblockDomain } from '../_api/blockDomain'
2018-12-22 23:37:51 +00:00
import { toast } from '../_components/toast/toast'
import { updateRelationship } from './accounts'
import { formatIntl } from '../_utils/formatIntl'
export async function setDomainBlocked (accountId, domain, block, toastOnSuccess) {
2019-08-03 20:49:37 +00:00
const { currentInstance, accessToken } = store.get()
try {
if (block) {
await blockDomain(currentInstance, accessToken, domain)
} else {
await unblockDomain(currentInstance, accessToken, domain)
}
await updateRelationship(accountId)
if (toastOnSuccess) {
/* no await */ toast.say(block ? 'intl.hidDomain' : 'intl.unhidDomain')
}
} catch (e) {
console.error(e)
/* no await */ toast.say(block
? formatIntl('intl.unableToHideDomain', { error: (e.message || '') })
: formatIntl('intl.unableToUnhideDomain', { error: (e.message || '') })
)
}
}