refactor: initialise masto outside of functions/handlers

This commit is contained in:
Daniel Roe 2022-12-25 15:04:50 +01:00
parent 03d3775011
commit 720b5114af
No known key found for this signature in database
GPG key ID: 22D5008E4F5D9B55
13 changed files with 44 additions and 30 deletions

View file

@ -11,10 +11,11 @@ const isSelf = $computed(() => currentUser.value?.account.id === account.id)
const enable = $computed(() => !isSelf && currentUser.value)
const relationship = $computed(() => props.relationship || useRelationship(account).value)
const masto = useMasto()
async function toggleFollow() {
relationship!.following = !relationship!.following
try {
const newRel = await useMasto().accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
const newRel = await masto.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
Object.assign(relationship!, newRel)
}
catch {
@ -26,7 +27,7 @@ async function toggleFollow() {
async function unblock() {
relationship!.blocking = false
try {
const newRel = await useMasto().accounts.unblock(account.id)
const newRel = await masto.accounts.unblock(account.id)
Object.assign(relationship!, newRel)
}
catch {
@ -38,7 +39,7 @@ async function unblock() {
async function unmute() {
relationship!.muting = false
try {
const newRel = await useMasto().accounts.unmute(account.id)
const newRel = await masto.accounts.unmute(account.id)
Object.assign(relationship!, newRel)
}
catch {

View file

@ -9,29 +9,30 @@ let relationship = $(useRelationship(account))
const isSelf = $computed(() => currentUser.value?.account.id === account.id)
const masto = useMasto()
const toggleMute = async () => {
// TODO: Add confirmation
relationship!.muting = !relationship!.muting
relationship = relationship!.muting
? await useMasto().accounts.mute(account.id, {
? await masto.accounts.mute(account.id, {
// TODO support more options
})
: await useMasto().accounts.unmute(account.id)
: await masto.accounts.unmute(account.id)
}
const toggleBlockUser = async () => {
// TODO: Add confirmation
relationship!.blocking = !relationship!.blocking
relationship = await useMasto().accounts[relationship!.blocking ? 'block' : 'unblock'](account.id)
relationship = await masto.accounts[relationship!.blocking ? 'block' : 'unblock'](account.id)
}
const toggleBlockDomain = async () => {
// TODO: Add confirmation
relationship!.domainBlocking = !relationship!.domainBlocking
await useMasto().domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account))
await masto.domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account))
}
</script>