2022-11-13 08:34:43 +03:00
|
|
|
<script setup lang="ts">
|
2022-11-14 05:20:07 +03:00
|
|
|
import type { Status } from 'masto'
|
2022-11-13 08:34:43 +03:00
|
|
|
|
2022-11-24 13:35:03 +03:00
|
|
|
const { status: _status } = defineProps<{
|
2022-11-14 05:20:07 +03:00
|
|
|
status: Status
|
2022-11-13 08:34:43 +03:00
|
|
|
}>()
|
2022-11-24 13:35:03 +03:00
|
|
|
let status = $ref<Status>({ ..._status })
|
2022-11-15 15:08:49 +03:00
|
|
|
|
2022-11-24 13:35:03 +03:00
|
|
|
watch(() => _status, (val) => {
|
|
|
|
status = { ...val }
|
|
|
|
}, { deep: true, immediate: true })
|
2022-11-24 11:34:05 +03:00
|
|
|
|
|
|
|
const clipboard = useClipboard()
|
|
|
|
const router = useRouter()
|
|
|
|
const route = useRoute()
|
|
|
|
|
2022-11-24 18:48:52 +03:00
|
|
|
const isAuthor = $computed(() => status.account.id === currentUser.value?.account.id)
|
2022-11-24 13:35:03 +03:00
|
|
|
|
2022-11-17 00:07:24 +03:00
|
|
|
// Use different states to let the user press different actions right after the other
|
2022-11-24 13:35:03 +03:00
|
|
|
const isLoading = $ref({
|
|
|
|
reblogged: false,
|
|
|
|
favourited: false,
|
|
|
|
bookmarked: false,
|
|
|
|
pinned: false,
|
2022-11-25 03:14:16 +03:00
|
|
|
translation: false,
|
2022-11-24 13:35:03 +03:00
|
|
|
})
|
2022-11-25 12:23:34 +03:00
|
|
|
|
|
|
|
type Action = 'reblogged' | 'favourited' | 'bookmarked' | 'pinned'
|
|
|
|
type CountField = 'reblogsCount' | 'favouritesCount'
|
|
|
|
async function toggleStatusAction(action: Action, newStatus: Promise<Status>, countField?: CountField) {
|
2022-11-17 00:07:24 +03:00
|
|
|
// Optimistic update
|
2022-11-24 13:35:03 +03:00
|
|
|
status[action] = !status[action]
|
2022-11-25 12:23:34 +03:00
|
|
|
if (countField)
|
|
|
|
status[countField] += status[action] ? 1 : -1
|
|
|
|
|
2022-11-16 00:20:07 +03:00
|
|
|
try {
|
2022-11-17 00:07:24 +03:00
|
|
|
isLoading[action] = true
|
|
|
|
Object.assign(status, await newStatus)
|
2022-11-16 00:20:07 +03:00
|
|
|
}
|
|
|
|
finally {
|
2022-11-17 00:07:24 +03:00
|
|
|
isLoading[action] = false
|
2022-11-16 00:20:07 +03:00
|
|
|
}
|
|
|
|
}
|
2022-11-17 00:07:24 +03:00
|
|
|
const toggleReblog = () => toggleStatusAction(
|
|
|
|
'reblogged',
|
2022-11-26 18:42:58 +03:00
|
|
|
useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
|
2022-11-24 13:35:03 +03:00
|
|
|
if (status.reblogged)
|
|
|
|
// returns the original status
|
|
|
|
return res.reblog!
|
|
|
|
return res
|
|
|
|
}),
|
2022-11-25 12:23:34 +03:00
|
|
|
'reblogsCount',
|
2022-11-17 00:07:24 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const toggleFavourite = () => toggleStatusAction(
|
|
|
|
'favourited',
|
2022-11-26 18:42:58 +03:00
|
|
|
useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
|
2022-11-25 12:23:34 +03:00
|
|
|
'favouritesCount',
|
2022-11-17 00:07:24 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const toggleBookmark = () => toggleStatusAction(
|
|
|
|
'bookmarked',
|
2022-11-26 18:42:58 +03:00
|
|
|
useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
|
2022-11-17 00:07:24 +03:00
|
|
|
)
|
2022-11-24 14:35:26 +03:00
|
|
|
const togglePin = async () => toggleStatusAction(
|
|
|
|
'pinned',
|
2022-11-26 18:42:58 +03:00
|
|
|
useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
|
2022-11-24 14:35:26 +03:00
|
|
|
)
|
|
|
|
|
2022-11-25 03:14:16 +03:00
|
|
|
const { toggle: _toggleTranslation, translation, enabled: isTranslationEnabled } = useTranslation(_status)
|
|
|
|
const toggleTranslation = async () => {
|
|
|
|
isLoading.translation = true
|
|
|
|
await _toggleTranslation()
|
|
|
|
isLoading.translation = false
|
|
|
|
}
|
|
|
|
|
2022-11-24 11:34:05 +03:00
|
|
|
const copyLink = async () => {
|
2022-11-24 17:31:43 +03:00
|
|
|
await clipboard.copy(`${location.origin}${getStatusPath(status)}`)
|
2022-11-24 11:34:05 +03:00
|
|
|
}
|
|
|
|
const deleteStatus = async () => {
|
|
|
|
// TODO confirm to delete
|
|
|
|
|
2022-11-26 18:42:58 +03:00
|
|
|
await useMasto().statuses.remove(status.id)
|
2022-11-24 11:34:05 +03:00
|
|
|
if (route.name === '@user-post')
|
|
|
|
router.back()
|
|
|
|
|
|
|
|
// TODO when timeline, remove this item
|
|
|
|
}
|
2022-11-24 14:35:26 +03:00
|
|
|
|
|
|
|
const deleteAndRedraft = async () => {
|
|
|
|
// TODO confirm to delete
|
|
|
|
|
2022-11-26 18:42:58 +03:00
|
|
|
const { text } = await useMasto().statuses.remove(status.id)
|
2022-11-24 14:35:26 +03:00
|
|
|
|
|
|
|
if (!dialogDraft.isEmpty) {
|
|
|
|
// TODO confirm to overwrite
|
|
|
|
}
|
|
|
|
|
2022-11-24 17:32:20 +03:00
|
|
|
openPublishDialog({
|
2022-11-24 14:35:26 +03:00
|
|
|
params: { ...getParamsFromStatus(status), status: text! },
|
|
|
|
attachments: [],
|
2022-11-24 17:32:20 +03:00
|
|
|
})
|
2022-11-24 14:35:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function editStatus() {
|
|
|
|
if (!dialogDraft.isEmpty) {
|
|
|
|
// TODO confirm to overwrite
|
|
|
|
}
|
2022-11-24 17:32:20 +03:00
|
|
|
openPublishDialog({
|
2022-11-24 14:35:26 +03:00
|
|
|
editingStatus: status,
|
|
|
|
params: getParamsFromStatus(status),
|
|
|
|
attachments: [],
|
2022-11-24 17:32:20 +03:00
|
|
|
})
|
|
|
|
}
|
2022-11-13 08:34:43 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-25 10:49:43 +03:00
|
|
|
<div flex justify-between>
|
2022-11-25 01:11:38 +03:00
|
|
|
<CommonTooltip placement="bottom" content="Reply">
|
2022-11-26 02:46:25 +03:00
|
|
|
<StatusActionButton
|
|
|
|
as="router-link"
|
|
|
|
:to="getStatusPath(status)"
|
|
|
|
:text="status.repliesCount"
|
|
|
|
color="text-blue" hover="text-blue" group-hover="bg-blue/10"
|
|
|
|
icon="i-ri:chat-3-line"
|
|
|
|
/>
|
2022-11-24 11:34:05 +03:00
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<CommonTooltip placement="bottom" content="Boost">
|
|
|
|
<StatusActionButton
|
|
|
|
:text="status.reblogsCount"
|
|
|
|
color="text-green" hover="text-green" group-hover="bg-green/10"
|
|
|
|
icon="i-ri:repeat-line"
|
|
|
|
active-icon="i-ri:repeat-fill"
|
|
|
|
:active="status.reblogged"
|
|
|
|
:disabled="isLoading.reblogged"
|
|
|
|
@click="toggleReblog()"
|
|
|
|
/>
|
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<CommonTooltip placement="bottom" content="Favourite">
|
|
|
|
<StatusActionButton
|
|
|
|
:text="status.favouritesCount"
|
|
|
|
color="text-rose" hover="text-rose" group-hover="bg-rose/10"
|
|
|
|
icon="i-ri:heart-3-line"
|
|
|
|
active-icon="i-ri:heart-3-fill"
|
|
|
|
:active="status.favourited"
|
|
|
|
:disabled="isLoading.favourited"
|
|
|
|
|
|
|
|
@click="toggleFavourite()"
|
|
|
|
/>
|
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<CommonTooltip placement="bottom" content="Bookmark">
|
2022-11-24 08:04:20 +03:00
|
|
|
<StatusActionButton
|
2022-11-24 11:34:05 +03:00
|
|
|
color="text-yellow" hover="text-yellow" group-hover="bg-yellow/10"
|
|
|
|
icon="i-ri:bookmark-line"
|
|
|
|
active-icon="i-ri:bookmark-fill"
|
|
|
|
:active="status.bookmarked"
|
|
|
|
:disabled="isLoading.bookmarked"
|
|
|
|
@click="toggleBookmark()"
|
2022-11-24 08:04:20 +03:00
|
|
|
/>
|
2022-11-24 11:34:05 +03:00
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<CommonDropdown placement="bottom">
|
|
|
|
<CommonTooltip placement="bottom" content="More">
|
2022-11-25 10:49:43 +03:00
|
|
|
<StatusActionButton
|
|
|
|
color="text-purple" hover="text-purple" group-hover="bg-purple/10"
|
|
|
|
icon="i-ri:more-line"
|
|
|
|
/>
|
2022-11-24 11:34:05 +03:00
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<template #popper>
|
|
|
|
<div flex="~ col">
|
|
|
|
<CommonDropdownItem icon="i-ri:link" @click="copyLink">
|
|
|
|
Copy link to this post
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
2022-11-25 14:39:21 +03:00
|
|
|
<NuxtLink :to="status.url" target="_blank">
|
|
|
|
<CommonDropdownItem v-if="status.url" icon="i-ri:arrow-right-up-line">
|
|
|
|
Open in original site
|
|
|
|
</CommonDropdownItem>
|
|
|
|
</NuxtLink>
|
2022-11-24 11:34:05 +03:00
|
|
|
|
2022-11-25 14:24:19 +03:00
|
|
|
<CommonDropdownItem v-if="isTranslationEnabled && status.language !== languageCode" icon="i-ri:translate" @click="toggleTranslation">
|
|
|
|
<template v-if="!translation.visible">
|
|
|
|
Translate post
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
2022-11-25 14:24:55 +03:00
|
|
|
Show untranslated
|
2022-11-25 14:24:19 +03:00
|
|
|
</template>
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
2022-11-24 11:34:05 +03:00
|
|
|
<template v-if="isAuthor">
|
2022-11-24 13:35:03 +03:00
|
|
|
<CommonDropdownItem
|
2022-11-24 17:32:20 +03:00
|
|
|
icon="i-ri:pushpin-line"
|
2022-11-24 13:35:03 +03:00
|
|
|
@click="togglePin"
|
|
|
|
>
|
|
|
|
{{ status.pinned ? 'Unpin on profile' : 'Pin on profile' }}
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
2022-11-24 17:32:20 +03:00
|
|
|
<CommonDropdownItem icon="i-ri:edit-line" @click="editStatus">
|
2022-11-24 11:34:05 +03:00
|
|
|
Edit
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
|
|
|
<CommonDropdownItem
|
2022-11-24 17:32:20 +03:00
|
|
|
icon="i-ri:delete-bin-line" text-red-600
|
2022-11-24 11:34:05 +03:00
|
|
|
@click="deleteStatus"
|
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</CommonDropdownItem>
|
2022-11-24 13:35:03 +03:00
|
|
|
|
|
|
|
<CommonDropdownItem
|
2022-11-24 17:32:20 +03:00
|
|
|
icon="i-ri:eraser-line" text-red-600
|
2022-11-24 14:35:26 +03:00
|
|
|
@click="deleteAndRedraft"
|
2022-11-24 13:35:03 +03:00
|
|
|
>
|
|
|
|
Delete & re-draft
|
|
|
|
</CommonDropdownItem>
|
2022-11-24 11:34:05 +03:00
|
|
|
</template>
|
2022-11-24 17:32:20 +03:00
|
|
|
<!-- TODO not available when not the same server -->
|
|
|
|
<template v-else>
|
|
|
|
<CommonDropdownItem
|
|
|
|
icon="i-ri:at-line"
|
2022-11-25 14:39:21 +03:00
|
|
|
@click="mentionUser(status.account)"
|
2022-11-24 17:32:20 +03:00
|
|
|
>
|
|
|
|
Mention @{{ status.account.acct }}
|
|
|
|
</CommonDropdownItem>
|
|
|
|
</template>
|
2022-11-24 08:04:20 +03:00
|
|
|
</div>
|
2022-11-24 11:34:05 +03:00
|
|
|
</template>
|
|
|
|
</CommonDropdown>
|
2022-11-13 08:34:43 +03:00
|
|
|
</div>
|
|
|
|
</template>
|