2022-11-13 14:34:43 +09:00
|
|
|
<script setup lang="ts">
|
2022-11-14 11:20:07 +09:00
|
|
|
import type { Status } from 'masto'
|
2022-11-13 14:34:43 +09:00
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
const { status: _status, details, command } = defineProps<{
|
2022-11-14 11:20:07 +09:00
|
|
|
status: Status
|
2022-11-28 19:23:33 +09:00
|
|
|
details?: boolean
|
2022-11-29 17:15:05 +09:00
|
|
|
command?: boolean
|
2022-11-13 14:34:43 +09:00
|
|
|
}>()
|
2022-11-24 19:35:03 +09:00
|
|
|
let status = $ref<Status>({ ..._status })
|
2022-11-15 21:08:49 +09:00
|
|
|
|
2022-11-24 19:35:03 +09:00
|
|
|
watch(() => _status, (val) => {
|
|
|
|
status = { ...val }
|
|
|
|
}, { deep: true, immediate: true })
|
2022-11-24 17:34:05 +09:00
|
|
|
|
|
|
|
const clipboard = useClipboard()
|
|
|
|
const router = useRouter()
|
|
|
|
const route = useRoute()
|
|
|
|
|
2022-11-25 00:48:52 +09:00
|
|
|
const isAuthor = $computed(() => status.account.id === currentUser.value?.account.id)
|
2022-11-24 19:35:03 +09:00
|
|
|
|
2022-11-17 06:07:24 +09:00
|
|
|
// Use different states to let the user press different actions right after the other
|
2022-11-24 19:35:03 +09:00
|
|
|
const isLoading = $ref({
|
|
|
|
reblogged: false,
|
|
|
|
favourited: false,
|
|
|
|
bookmarked: false,
|
|
|
|
pinned: false,
|
2022-11-25 09:14:16 +09:00
|
|
|
translation: false,
|
2022-11-24 19:35:03 +09:00
|
|
|
})
|
2022-11-25 18:23:34 +09:00
|
|
|
|
|
|
|
type Action = 'reblogged' | 'favourited' | 'bookmarked' | 'pinned'
|
|
|
|
type CountField = 'reblogsCount' | 'favouritesCount'
|
|
|
|
async function toggleStatusAction(action: Action, newStatus: Promise<Status>, countField?: CountField) {
|
2022-11-17 06:07:24 +09:00
|
|
|
// Optimistic update
|
2022-11-24 19:35:03 +09:00
|
|
|
status[action] = !status[action]
|
2022-11-25 18:23:34 +09:00
|
|
|
if (countField)
|
|
|
|
status[countField] += status[action] ? 1 : -1
|
|
|
|
|
2022-11-16 06:20:07 +09:00
|
|
|
try {
|
2022-11-17 06:07:24 +09:00
|
|
|
isLoading[action] = true
|
|
|
|
Object.assign(status, await newStatus)
|
2022-11-16 06:20:07 +09:00
|
|
|
}
|
|
|
|
finally {
|
2022-11-17 06:07:24 +09:00
|
|
|
isLoading[action] = false
|
2022-11-16 06:20:07 +09:00
|
|
|
}
|
|
|
|
}
|
2022-11-17 06:07:24 +09:00
|
|
|
const toggleReblog = () => toggleStatusAction(
|
|
|
|
'reblogged',
|
2022-11-27 00:42:58 +09:00
|
|
|
useMasto().statuses[status.reblogged ? 'unreblog' : 'reblog'](status.id).then((res) => {
|
2022-11-24 19:35:03 +09:00
|
|
|
if (status.reblogged)
|
|
|
|
// returns the original status
|
|
|
|
return res.reblog!
|
|
|
|
return res
|
|
|
|
}),
|
2022-11-25 18:23:34 +09:00
|
|
|
'reblogsCount',
|
2022-11-17 06:07:24 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const toggleFavourite = () => toggleStatusAction(
|
|
|
|
'favourited',
|
2022-11-27 00:42:58 +09:00
|
|
|
useMasto().statuses[status.favourited ? 'unfavourite' : 'favourite'](status.id),
|
2022-11-25 18:23:34 +09:00
|
|
|
'favouritesCount',
|
2022-11-17 06:07:24 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
const toggleBookmark = () => toggleStatusAction(
|
|
|
|
'bookmarked',
|
2022-11-27 00:42:58 +09:00
|
|
|
useMasto().statuses[status.bookmarked ? 'unbookmark' : 'bookmark'](status.id),
|
2022-11-17 06:07:24 +09:00
|
|
|
)
|
2022-11-24 20:35:26 +09:00
|
|
|
const togglePin = async () => toggleStatusAction(
|
|
|
|
'pinned',
|
2022-11-27 00:42:58 +09:00
|
|
|
useMasto().statuses[status.pinned ? 'unpin' : 'pin'](status.id),
|
2022-11-24 20:35:26 +09:00
|
|
|
)
|
|
|
|
|
2022-11-25 09:14:16 +09:00
|
|
|
const { toggle: _toggleTranslation, translation, enabled: isTranslationEnabled } = useTranslation(_status)
|
|
|
|
const toggleTranslation = async () => {
|
|
|
|
isLoading.translation = true
|
|
|
|
await _toggleTranslation()
|
|
|
|
isLoading.translation = false
|
|
|
|
}
|
|
|
|
|
2022-11-29 20:18:11 +09:00
|
|
|
const copyLink = async (url: string) => {
|
|
|
|
await clipboard.copy(url)
|
2022-11-24 17:34:05 +09:00
|
|
|
}
|
|
|
|
const deleteStatus = async () => {
|
|
|
|
// TODO confirm to delete
|
2022-11-27 14:08:13 +09:00
|
|
|
if (process.dev) {
|
2022-11-28 19:23:33 +09:00
|
|
|
// eslint-disable-next-line no-alert
|
2022-11-27 14:08:13 +09:00
|
|
|
const result = confirm('[DEV] Are you sure you want to delete this post?')
|
|
|
|
if (!result)
|
|
|
|
return
|
|
|
|
}
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-27 00:42:58 +09:00
|
|
|
await useMasto().statuses.remove(status.id)
|
2022-11-27 14:08:13 +09:00
|
|
|
|
|
|
|
if (route.name === '@account-status')
|
2022-11-24 17:34:05 +09:00
|
|
|
router.back()
|
|
|
|
|
|
|
|
// TODO when timeline, remove this item
|
|
|
|
}
|
2022-11-24 20:35:26 +09:00
|
|
|
|
|
|
|
const deleteAndRedraft = async () => {
|
|
|
|
// TODO confirm to delete
|
2022-11-29 02:46:00 +09:00
|
|
|
if (process.dev) {
|
|
|
|
// eslint-disable-next-line no-alert
|
|
|
|
const result = confirm('[DEV] Are you sure you want to delete and re-draft this post?')
|
|
|
|
if (!result)
|
|
|
|
return
|
|
|
|
}
|
2022-11-24 20:35:26 +09:00
|
|
|
|
2022-11-27 00:42:58 +09:00
|
|
|
const { text } = await useMasto().statuses.remove(status.id)
|
2022-11-28 19:23:33 +09:00
|
|
|
openPublishDialog('dialog', getDraftFromStatus(status, text), true)
|
|
|
|
}
|
2022-11-24 20:35:26 +09:00
|
|
|
|
2022-11-28 19:23:33 +09:00
|
|
|
const reply = () => {
|
|
|
|
if (details) {
|
|
|
|
// TODO focus to editor
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const { key, draft } = getReplyDraft(status)
|
|
|
|
openPublishDialog(key, draft())
|
2022-11-24 20:35:26 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editStatus() {
|
2022-11-28 16:55:57 +09:00
|
|
|
openPublishDialog(`edit-${status.id}`, {
|
2022-11-28 19:23:33 +09:00
|
|
|
...getDraftFromStatus(status),
|
2022-11-24 20:35:26 +09:00
|
|
|
editingStatus: status,
|
2022-11-24 23:32:20 +09:00
|
|
|
})
|
|
|
|
}
|
2022-11-13 14:34:43 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-25 16:49:43 +09:00
|
|
|
<div flex justify-between>
|
2022-11-28 00:11:34 +09:00
|
|
|
<div flex-1>
|
2022-11-26 08:46:25 +09:00
|
|
|
<StatusActionButton
|
2022-11-28 00:11:34 +09:00
|
|
|
content="Reply"
|
2022-11-26 08:46:25 +09:00
|
|
|
:text="status.repliesCount"
|
|
|
|
color="text-blue" hover="text-blue" group-hover="bg-blue/10"
|
|
|
|
icon="i-ri:chat-3-line"
|
2022-11-29 17:15:05 +09:00
|
|
|
:command="command"
|
2022-11-28 19:23:33 +09:00
|
|
|
@click="reply"
|
2022-11-26 08:46:25 +09:00
|
|
|
/>
|
2022-11-28 00:11:34 +09:00
|
|
|
</div>
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-28 00:11:34 +09:00
|
|
|
<div flex-1>
|
2022-11-24 17:34:05 +09:00
|
|
|
<StatusActionButton
|
2022-11-28 00:11:34 +09:00
|
|
|
content="Boost"
|
2022-11-24 17:34:05 +09:00
|
|
|
: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"
|
2022-11-29 17:15:05 +09:00
|
|
|
:command="command"
|
2022-11-24 17:34:05 +09:00
|
|
|
@click="toggleReblog()"
|
|
|
|
/>
|
2022-11-28 00:11:34 +09:00
|
|
|
</div>
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-28 00:11:34 +09:00
|
|
|
<div flex-1>
|
2022-11-24 17:34:05 +09:00
|
|
|
<StatusActionButton
|
2022-11-28 00:11:34 +09:00
|
|
|
content="Favourite"
|
2022-11-24 17:34:05 +09:00
|
|
|
: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"
|
2022-11-29 17:15:05 +09:00
|
|
|
:command="command"
|
2022-11-24 17:34:05 +09:00
|
|
|
@click="toggleFavourite()"
|
|
|
|
/>
|
2022-11-28 00:11:34 +09:00
|
|
|
</div>
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-28 00:11:34 +09:00
|
|
|
<div flex-none>
|
2022-11-24 14:04:20 +09:00
|
|
|
<StatusActionButton
|
2022-11-28 00:11:34 +09:00
|
|
|
content="Bookmark"
|
2022-11-24 17:34:05 +09: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"
|
2022-11-29 17:15:05 +09:00
|
|
|
:command="command"
|
2022-11-24 17:34:05 +09:00
|
|
|
@click="toggleBookmark()"
|
2022-11-24 14:04:20 +09:00
|
|
|
/>
|
2022-11-28 00:11:34 +09:00
|
|
|
</div>
|
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
<CommonDropdown flex-none ml3 placement="bottom" :eager-mount="command">
|
2022-11-28 00:11:34 +09:00
|
|
|
<StatusActionButton
|
|
|
|
content="More"
|
|
|
|
color="text-purple" hover="text-purple" group-hover="bg-purple/10"
|
|
|
|
icon="i-ri:more-line"
|
|
|
|
/>
|
2022-11-24 17:34:05 +09:00
|
|
|
|
|
|
|
<template #popper>
|
|
|
|
<div flex="~ col">
|
2022-11-29 17:15:05 +09:00
|
|
|
<CommonDropdownItem
|
|
|
|
text="Copy link to this post"
|
|
|
|
icon="i-ri:link"
|
|
|
|
:command="command"
|
2022-11-29 20:18:11 +09:00
|
|
|
@click="copyLink(status.url)"
|
2022-11-29 17:15:05 +09:00
|
|
|
/>
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-25 20:39:21 +09:00
|
|
|
<NuxtLink :to="status.url" target="_blank">
|
2022-11-29 17:15:05 +09:00
|
|
|
<CommonDropdownItem
|
|
|
|
v-if="status.url"
|
|
|
|
text="Open in original site"
|
|
|
|
icon="i-ri:arrow-right-up-line"
|
|
|
|
:command="command"
|
|
|
|
/>
|
2022-11-25 20:39:21 +09:00
|
|
|
</NuxtLink>
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
<CommonDropdownItem
|
|
|
|
v-if="isTranslationEnabled && status.language !== languageCode"
|
|
|
|
:text="translation.visible ? 'Show untranslated' : 'Translate post'"
|
|
|
|
icon="i-ri:translate"
|
|
|
|
:command="command"
|
|
|
|
@click="toggleTranslation"
|
|
|
|
/>
|
2022-11-25 20:24:19 +09:00
|
|
|
|
2022-11-29 02:37:50 +09:00
|
|
|
<template v-if="currentUser">
|
|
|
|
<template v-if="isAuthor">
|
|
|
|
<CommonDropdownItem
|
2022-11-29 17:15:05 +09:00
|
|
|
:text="status.pinned ? 'Unpin on profile' : 'Pin on profile'"
|
2022-11-29 02:37:50 +09:00
|
|
|
icon="i-ri:pushpin-line"
|
2022-11-29 17:15:05 +09:00
|
|
|
:command="command"
|
2022-11-29 02:37:50 +09:00
|
|
|
@click="togglePin"
|
2022-11-29 17:15:05 +09:00
|
|
|
/>
|
2022-11-29 02:37:50 +09:00
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
<CommonDropdownItem
|
|
|
|
text="Edit"
|
|
|
|
icon="i-ri:edit-line"
|
|
|
|
:command="command"
|
|
|
|
@click="editStatus"
|
|
|
|
/>
|
2022-11-29 02:37:50 +09:00
|
|
|
|
|
|
|
<CommonDropdownItem
|
2022-11-29 17:15:05 +09:00
|
|
|
text="Delete"
|
|
|
|
icon="i-ri:delete-bin-line"
|
|
|
|
text-red-600
|
|
|
|
:command="command"
|
2022-11-29 02:37:50 +09:00
|
|
|
@click="deleteStatus"
|
2022-11-29 17:15:05 +09:00
|
|
|
/>
|
2022-11-29 02:37:50 +09:00
|
|
|
|
|
|
|
<CommonDropdownItem
|
2022-11-29 17:15:05 +09:00
|
|
|
text="Delete & re-draft"
|
|
|
|
icon="i-ri:eraser-line"
|
|
|
|
text-red-600
|
|
|
|
:command="command"
|
2022-11-29 02:37:50 +09:00
|
|
|
@click="deleteAndRedraft"
|
2022-11-29 17:15:05 +09:00
|
|
|
/>
|
2022-11-29 02:37:50 +09:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<CommonDropdownItem
|
2022-11-29 17:15:05 +09:00
|
|
|
:text="`Mention @${status.account.acct}`"
|
2022-11-29 02:37:50 +09:00
|
|
|
icon="i-ri:at-line"
|
2022-11-29 17:15:05 +09:00
|
|
|
:command="command"
|
2022-11-29 02:37:50 +09:00
|
|
|
@click="mentionUser(status.account)"
|
2022-11-29 17:15:05 +09:00
|
|
|
/>
|
2022-11-29 02:37:50 +09:00
|
|
|
</template>
|
2022-11-24 23:32:20 +09:00
|
|
|
</template>
|
2022-11-24 14:04:20 +09:00
|
|
|
</div>
|
2022-11-24 17:34:05 +09:00
|
|
|
</template>
|
|
|
|
</CommonDropdown>
|
2022-11-13 14:34:43 +09:00
|
|
|
</div>
|
|
|
|
</template>
|