refactor: inject masto instance via nuxt app (#134)

This commit is contained in:
Daniel Roe 2022-11-26 15:42:58 +00:00 committed by GitHub
parent 5c60497421
commit 39b005899e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 67 additions and 48 deletions

View file

@ -11,7 +11,7 @@ let relationship = $(useRelationship(account))
async function toggleFollow() {
relationship!.following = !relationship!.following
try {
relationship = await masto.accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
relationship = await useMasto().accounts[relationship!.following ? 'follow' : 'unfollow'](account.id)
}
catch {
// TODO error handling

View file

@ -13,24 +13,24 @@ const toggleMute = async () => {
relationship!.muting = !relationship!.muting
relationship = relationship!.muting
? await masto.accounts.mute(account.id, {
? await useMasto().accounts.mute(account.id, {
// TODO support more options
})
: await masto.accounts.unmute(account.id)
: await useMasto().accounts.unmute(account.id)
}
const toggleBlockUser = async () => {
// TODO: Add confirmation
relationship!.blocking = !relationship!.blocking
relationship = await masto.accounts[relationship!.blocking ? 'block' : 'unblock'](account.id)
relationship = await useMasto().accounts[relationship!.blocking ? 'block' : 'unblock'](account.id)
}
const toggleBlockDomain = async () => {
// TODO: Add confirmation
relationship!.domainBlocking = !relationship!.domainBlocking
await masto.domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account))
await useMasto().domainBlocks[relationship!.domainBlocking ? 'block' : 'unblock'](getServerName(account))
}
</script>

View file

@ -76,7 +76,7 @@ async function toggleSensitive() {
async function uploadAttachments(files: File[]) {
isUploading = true
for (const file of files) {
const attachment = await masto.mediaAttachments.create({
const attachment = await useMasto().mediaAttachments.create({
file,
})
draft.attachments.push(attachment)
@ -114,9 +114,9 @@ async function publish() {
isSending = true
if (!draft.editingStatus)
await masto.statuses.create(payload)
await useMasto().statuses.create(payload)
else
await masto.statuses.update(draft.editingStatus.id, payload)
await useMasto().statuses.update(draft.editingStatus.id, payload)
draft = getDefaultDraft({ inReplyToId })
isPublishDialogOpen.value = false

View file

@ -43,7 +43,7 @@ async function toggleStatusAction(action: Action, newStatus: Promise<Status>, co
}
const toggleReblog = () => toggleStatusAction(
'reblogged',
masto.statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
if (status.reblogged)
// returns the original status
return res.reblog!
@ -54,17 +54,17 @@ const toggleReblog = () => toggleStatusAction(
const toggleFavourite = () => toggleStatusAction(
'favourited',
masto.statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
'favouritesCount',
)
const toggleBookmark = () => toggleStatusAction(
'bookmarked',
masto.statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
)
const togglePin = async () => toggleStatusAction(
'pinned',
masto.statuses[status.pinned ? 'unpin' : 'pin'](status.id),
useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
)
const { toggle: _toggleTranslation, translation, enabled: isTranslationEnabled } = useTranslation(_status)
@ -80,7 +80,7 @@ const copyLink = async () => {
const deleteStatus = async () => {
// TODO confirm to delete
await masto.statuses.remove(status.id)
await useMasto().statuses.remove(status.id)
if (route.name === '@user-post')
router.back()
@ -90,7 +90,7 @@ const deleteStatus = async () => {
const deleteAndRedraft = async () => {
// TODO confirm to delete
const { text } = await masto.statuses.remove(status.id)
const { text } = await useMasto().statuses.remove(status.id)
if (!dialogDraft.isEmpty) {
// TODO confirm to overwrite

View file

@ -5,7 +5,7 @@ const { status } = defineProps<{
status: Status
}>()
const { data: statusEdits } = useAsyncData(`status:history:${status.id}`, () => masto.statuses.fetchHistory(status.id).then(res => res.reverse()))
const { data: statusEdits } = useAsyncData(`status:history:${status.id}`, () => useMasto().statuses.fetchHistory(status.id).then(res => res.reverse()))
const showHistory = (edit: StatusEdit) => {
openEditHistoryDialog(edit)