refactor: inject masto instance via nuxt app (#134)
This commit is contained in:
parent
5c60497421
commit
39b005899e
26 changed files with 67 additions and 48 deletions
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue