refactor: initialise masto
outside of functions/handlers
This commit is contained in:
parent
03d3775011
commit
720b5114af
13 changed files with 44 additions and 30 deletions
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -94,10 +94,12 @@ async function toggleSensitive() {
|
|||
draft.params.sensitive = !draft.params.sensitive
|
||||
}
|
||||
|
||||
const masto = useMasto()
|
||||
|
||||
async function uploadAttachments(files: File[]) {
|
||||
isUploading = true
|
||||
for (const file of files) {
|
||||
const attachment = await useMasto().mediaAttachments.create({
|
||||
const attachment = await masto.mediaAttachments.create({
|
||||
file,
|
||||
})
|
||||
draft.attachments.push(attachment)
|
||||
|
@ -107,7 +109,7 @@ async function uploadAttachments(files: File[]) {
|
|||
|
||||
async function setDescription(att: Attachment, description: string) {
|
||||
att.description = description
|
||||
await useMasto().mediaAttachments.update(att.id, { description: att.description })
|
||||
await masto.mediaAttachments.update(att.id, { description: att.description })
|
||||
}
|
||||
|
||||
function removeAttachment(index: number) {
|
||||
|
@ -141,9 +143,9 @@ async function publish() {
|
|||
isSending = true
|
||||
|
||||
if (!draft.editingStatus)
|
||||
await useMasto().statuses.create(payload)
|
||||
await masto.statuses.create(payload)
|
||||
else
|
||||
await useMasto().statuses.update(draft.editingStatus.id, payload)
|
||||
await masto.statuses.update(draft.editingStatus.id, payload)
|
||||
|
||||
draft = initial()
|
||||
isPublishDialogOpen.value = false
|
||||
|
|
|
@ -5,7 +5,8 @@ const { status } = defineProps<{
|
|||
status: Status
|
||||
}>()
|
||||
|
||||
const { data: statusEdits } = useAsyncData(`status:history:${status.id}`, () => useMasto().statuses.fetchHistory(status.id).then(res => res.reverse()))
|
||||
const masto = useMasto()
|
||||
const { data: statusEdits } = useAsyncData(`status:history:${status.id}`, () => masto.statuses.fetchHistory(status.id).then(res => res.reverse()))
|
||||
|
||||
const showHistory = (edit: StatusEdit) => {
|
||||
openEditHistoryDialog(edit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue