diff --git a/components/account/AccountFollowButton.vue b/components/account/AccountFollowButton.vue index 1822a1971..3b4f52399 100644 --- a/components/account/AccountFollowButton.vue +++ b/components/account/AccountFollowButton.vue @@ -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 { diff --git a/components/account/AccountMoreButton.vue b/components/account/AccountMoreButton.vue index fcb477f5c..031270ea3 100644 --- a/components/account/AccountMoreButton.vue +++ b/components/account/AccountMoreButton.vue @@ -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)) } diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index c0ae1449d..a1991e2e7 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -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 diff --git a/components/status/edit/StatusEditHistory.vue b/components/status/edit/StatusEditHistory.vue index 31f94e8ed..a7f9fe39e 100644 --- a/components/status/edit/StatusEditHistory.vue +++ b/components/status/edit/StatusEditHistory.vue @@ -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) diff --git a/composables/status.ts b/composables/status.ts index f4ee29c56..900e51d74 100644 --- a/composables/status.ts +++ b/composables/status.ts @@ -9,6 +9,7 @@ export interface StatusActionsProps { export function useStatusActions(props: StatusActionsProps) { let status = $ref({ ...props.status }) + const masto = useMasto() watch( () => props.status, @@ -42,7 +43,7 @@ export function useStatusActions(props: StatusActionsProps) { } const toggleReblog = () => toggleStatusAction( 'reblogged', - () => useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => { + () => masto.statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => { if (status.reblogged) // returns the original status return res.reblog! @@ -53,18 +54,18 @@ export function useStatusActions(props: StatusActionsProps) { const toggleFavourite = () => toggleStatusAction( 'favourited', - () => useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id), + () => masto.statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id), 'favouritesCount', ) const toggleBookmark = () => toggleStatusAction( 'bookmarked', - () => useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id), + () => masto.statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id), ) const togglePin = async () => toggleStatusAction( 'pinned', - () => useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id), + () => masto.statuses[status.pinned ? 'unpin' : 'pin'](status.id), ) return { diff --git a/pages/[[server]]/@[account]/[status].vue b/pages/[[server]]/@[account]/[status].vue index 8a59fc815..6d4716c36 100644 --- a/pages/[[server]]/@[account]/[status].vue +++ b/pages/[[server]]/@[account]/[status].vue @@ -17,7 +17,8 @@ const { data: status, pending, refresh: refreshStatus } = useAsyncData(`status:$ window.history.state?.status as Status | undefined) ?? await fetchStatus(id), ) -const { data: context, pending: pendingContext, refresh: refreshContext } = useAsyncData(`context:${id}`, () => useMasto().statuses.fetchContext(id)) +const masto = useMasto() +const { data: context, pending: pendingContext, refresh: refreshContext } = useAsyncData(`context:${id}`, () => masto.statuses.fetchContext(id)) const replyDraft = $computed(() => status.value ? getReplyDraft(status.value) : null) diff --git a/pages/[[server]]/explore/tags.vue b/pages/[[server]]/explore/tags.vue index cd2d80b3e..4ba209492 100644 --- a/pages/[[server]]/explore/tags.vue +++ b/pages/[[server]]/explore/tags.vue @@ -4,8 +4,9 @@ import { STORAGE_KEY_HIDE_EXPLORE_TAGS_TIPS } from '~~/constants' const { t } = useI18n() +const masto = useMasto() const { data, pending, error } = useLazyAsyncData( - () => useMasto().trends.fetchTags({ limit: 20 }), + () => masto.trends.fetchTags({ limit: 20 }), { immediate: true }, ) diff --git a/pages/[[server]]/explore/users.vue b/pages/[[server]]/explore/users.vue index f306d0f48..cb2b01664 100644 --- a/pages/[[server]]/explore/users.vue +++ b/pages/[[server]]/explore/users.vue @@ -2,8 +2,9 @@ const { t } = useI18n() // limit: 20 is the default configuration of the official client +const masto = useMasto() const { data, pending, error } = useLazyAsyncData( - () => useMasto().suggestions.fetchAll({ limit: 20 }), + () => masto.suggestions.fetchAll({ limit: 20 }), { immediate: true }, ) diff --git a/pages/[[server]]/tags/[tag].vue b/pages/[[server]]/tags/[tag].vue index ba40d6844..a1afe7701 100644 --- a/pages/[[server]]/tags/[tag].vue +++ b/pages/[[server]]/tags/[tag].vue @@ -2,10 +2,11 @@ const params = useRoute().params const tagName = $(computedEager(() => params.tag as string)) -const { data: tag, refresh } = $(await useAsyncData(() => useMasto().tags.fetch(tagName))) +const masto = useMasto() +const { data: tag, refresh } = $(await useAsyncData(() => masto.tags.fetch(tagName))) -const paginator = useMasto().timelines.iterateHashtag(tagName) -const stream = await useMasto().stream.streamTagTimeline(tagName) +const paginator = masto.timelines.iterateHashtag(tagName) +const stream = await masto.stream.streamTagTimeline(tagName) onBeforeUnmount(() => stream.disconnect()) if (tag) { diff --git a/pages/domain_blocks.vue b/pages/domain_blocks.vue index fe601afb7..ed25088fe 100644 --- a/pages/domain_blocks.vue +++ b/pages/domain_blocks.vue @@ -3,14 +3,15 @@ definePageMeta({ middleware: 'auth', }) -const paginator = useMasto().domainBlocks.iterate() +const masto = useMasto() +const paginator = masto.domainBlocks.iterate() useHeadFixed({ title: 'Blocked domains', }) const unblock = async (domain: string) => { - await useMasto().domainBlocks.unblock(domain) + await masto.domainBlocks.unblock(domain) } diff --git a/pages/home.vue b/pages/home.vue index 995f5cb61..f02498408 100644 --- a/pages/home.vue +++ b/pages/home.vue @@ -11,8 +11,9 @@ if (useRoute().path === '/signin/callback') { useRouter().push('/home') } -const paginator = useMasto().timelines.iterateHome() -const stream = await useMasto().stream.streamUser() +const masto = useMasto() +const paginator = masto.timelines.iterateHome() +const stream = await masto.stream.streamUser() onBeforeUnmount(() => stream.disconnect()) const { t } = useI18n() diff --git a/pages/notifications/index.vue b/pages/notifications/index.vue index cf6d66b2a..08bf4aaba 100644 --- a/pages/notifications/index.vue +++ b/pages/notifications/index.vue @@ -1,13 +1,14 @@