2022-11-13 05:34:43 +00:00
|
|
|
<script setup lang="ts">
|
2022-11-14 02:20:07 +00:00
|
|
|
import type { Status } from 'masto'
|
2022-11-13 05:34:43 +00:00
|
|
|
|
2022-11-15 12:08:49 +00:00
|
|
|
const { status } = defineProps<{
|
2022-11-14 02:20:07 +00:00
|
|
|
status: Status
|
2022-11-13 05:34:43 +00:00
|
|
|
}>()
|
2022-11-15 12:08:49 +00:00
|
|
|
|
2022-11-24 08:34:05 +00:00
|
|
|
const isAuthor = $computed(() => status.account.id === currentUser.value?.account?.id)
|
|
|
|
|
|
|
|
const clipboard = useClipboard()
|
|
|
|
const router = useRouter()
|
|
|
|
const route = useRoute()
|
|
|
|
|
2022-11-16 21:07:24 +00:00
|
|
|
// Use different states to let the user press different actions right after the other
|
|
|
|
const isLoading = $ref({ reblogged: false, favourited: false, bookmarked: false })
|
|
|
|
async function toggleStatusAction(action: 'reblogged' | 'favourited' | 'bookmarked', newStatus: Promise<Status>) {
|
|
|
|
// Optimistic update
|
|
|
|
Object.assign(status, { [action]: !status[action] })
|
2022-11-15 21:20:07 +00:00
|
|
|
try {
|
2022-11-16 21:07:24 +00:00
|
|
|
isLoading[action] = true
|
|
|
|
Object.assign(status, await newStatus)
|
2022-11-15 21:20:07 +00:00
|
|
|
}
|
|
|
|
finally {
|
2022-11-16 21:07:24 +00:00
|
|
|
isLoading[action] = false
|
2022-11-15 21:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-16 21:07:24 +00:00
|
|
|
|
|
|
|
const toggleReblog = () => toggleStatusAction(
|
|
|
|
'reblogged',
|
|
|
|
masto.statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id),
|
|
|
|
)
|
|
|
|
|
|
|
|
const toggleFavourite = () => toggleStatusAction(
|
|
|
|
'favourited',
|
|
|
|
masto.statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
|
|
|
|
)
|
|
|
|
|
|
|
|
const toggleBookmark = () => toggleStatusAction(
|
|
|
|
'bookmarked',
|
|
|
|
masto.statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
|
|
|
|
)
|
2022-11-24 08:34:05 +00:00
|
|
|
const copyLink = async () => {
|
|
|
|
await clipboard.copy(location.href)
|
|
|
|
}
|
|
|
|
const openInOriginal = () => {
|
|
|
|
window.open(status.url!, '_blank')
|
|
|
|
}
|
|
|
|
const deleteStatus = async () => {
|
|
|
|
// TODO confirm to delete
|
|
|
|
|
|
|
|
await masto.statuses.remove(status.id)
|
|
|
|
if (route.name === '@user-post')
|
|
|
|
router.back()
|
|
|
|
|
|
|
|
// TODO when timeline, remove this item
|
|
|
|
}
|
2022-11-13 05:34:43 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-23 14:39:48 +00:00
|
|
|
<div flex justify-between gap-8>
|
2022-11-24 08:34:05 +00:00
|
|
|
<CommonTooltip placement="bottom" content="Replay">
|
|
|
|
<RouterLink :to="getStatusPath(status)">
|
|
|
|
<StatusActionButton
|
|
|
|
:text="status.repliesCount"
|
|
|
|
color="text-blue" hover="text-blue" group-hover="bg-blue/10"
|
|
|
|
icon="i-ri:chat-3-line"
|
|
|
|
/>
|
|
|
|
</RouterLink>
|
|
|
|
</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 05:04:20 +00:00
|
|
|
<StatusActionButton
|
2022-11-24 08:34:05 +00: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 05:04:20 +00:00
|
|
|
/>
|
2022-11-24 08:34:05 +00:00
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<CommonDropdown placement="bottom">
|
|
|
|
<CommonTooltip placement="bottom" content="More">
|
|
|
|
<button flex gap-1 items-center rounded op50 hover="op100 text-purple" group>
|
|
|
|
<div rounded-full p2 group-hover="bg-purple/10">
|
|
|
|
<div i-ri:more-line />
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</CommonTooltip>
|
|
|
|
|
|
|
|
<template #popper>
|
|
|
|
<div flex="~ col">
|
|
|
|
<CommonDropdownItem icon="i-ri:link" @click="copyLink">
|
|
|
|
Copy link to this post
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
|
|
|
<CommonDropdownItem v-if="status.url" icon="i-ri:arrow-right-up-line" @click="openInOriginal">
|
|
|
|
Open in original site
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
|
|
|
<!-- TODO -->
|
|
|
|
<template v-if="isAuthor">
|
|
|
|
<CommonDropdownItem v-if="isAuthor" icon="i-ri:edit-line">
|
|
|
|
Edit
|
|
|
|
</CommonDropdownItem>
|
|
|
|
|
|
|
|
<CommonDropdownItem
|
|
|
|
v-if="isAuthor" icon="i-ri:delete-bin-line" text-red-600
|
|
|
|
@click="deleteStatus"
|
|
|
|
>
|
|
|
|
Delete
|
|
|
|
</CommonDropdownItem>
|
|
|
|
</template>
|
2022-11-24 05:04:20 +00:00
|
|
|
</div>
|
2022-11-24 08:34:05 +00:00
|
|
|
</template>
|
|
|
|
</CommonDropdown>
|
2022-11-13 05:34:43 +00:00
|
|
|
</div>
|
|
|
|
</template>
|