2022-11-13 06:34:43 +01:00
|
|
|
<script setup lang="ts">
|
2022-11-14 03:20:07 +01:00
|
|
|
import type { Status } from 'masto'
|
2022-11-13 06:34:43 +01:00
|
|
|
|
2022-11-15 13:08:49 +01:00
|
|
|
const { status } = defineProps<{
|
2022-11-14 03:20:07 +01:00
|
|
|
status: Status
|
2022-11-13 06:34:43 +01:00
|
|
|
}>()
|
2022-11-15 13:08:49 +01:00
|
|
|
|
2022-11-16 22:07:24 +01: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 22:20:07 +01:00
|
|
|
try {
|
2022-11-16 22:07:24 +01:00
|
|
|
isLoading[action] = true
|
|
|
|
Object.assign(status, await newStatus)
|
2022-11-15 22:20:07 +01:00
|
|
|
}
|
|
|
|
finally {
|
2022-11-16 22:07:24 +01:00
|
|
|
isLoading[action] = false
|
2022-11-15 22:20:07 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-16 22:07:24 +01: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-13 06:34:43 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-16 22:07:24 +01:00
|
|
|
<div flex gap-8>
|
2022-11-21 11:12:48 +01:00
|
|
|
<RouterLink flex gap-1 items-center w-full rounded op50 hover="op100 text-blue" group :to="`/@${status.account.acct}/${status.id}`">
|
2022-11-14 03:56:48 +01:00
|
|
|
<div rounded-full p2 group-hover="bg-blue/10">
|
|
|
|
<div i-ri:chat-3-line />
|
|
|
|
</div>
|
|
|
|
<span v-if="status.repliesCount">{{ status.repliesCount }}</span>
|
2022-11-14 15:54:30 +01:00
|
|
|
</RouterLink>
|
2022-11-16 22:07:24 +01:00
|
|
|
<button
|
2022-11-21 11:12:48 +01:00
|
|
|
flex gap-1 items-center w-full rounded op50 hover="op100 text-green" group
|
|
|
|
:class="(status.reblogged ? 'text-green op100' : 'op50') + (isLoading.reblogged ? ' pointer-events-none' : '')"
|
2022-11-16 22:07:24 +01:00
|
|
|
@click="toggleReblog()"
|
|
|
|
>
|
2022-11-14 03:56:48 +01:00
|
|
|
<div rounded-full p2 group-hover="bg-green/10">
|
2022-11-16 22:07:24 +01:00
|
|
|
<div :class="status.reblogged ? 'i-ri:repeat-fill' : 'i-ri:repeat-line'" />
|
2022-11-14 03:56:48 +01:00
|
|
|
</div>
|
|
|
|
<span v-if="status.reblogsCount">{{ status.reblogsCount }}</span>
|
2022-11-13 06:34:43 +01:00
|
|
|
</button>
|
2022-11-15 13:08:49 +01:00
|
|
|
<button
|
|
|
|
flex gap-1 items-center w-full rounded hover="op100 text-rose" group
|
2022-11-21 11:12:48 +01:00
|
|
|
:class="status.favourited ? 'text-rose op100' : 'op50'"
|
2022-11-15 13:08:49 +01:00
|
|
|
@click="toggleFavourite()"
|
|
|
|
>
|
2022-11-14 03:56:48 +01:00
|
|
|
<div rounded-full p2 group-hover="bg-rose/10">
|
2022-11-16 22:07:24 +01:00
|
|
|
<div :class="(status.favourited ? 'i-ri:heart-3-fill' : 'i-ri:heart-3-line') + (isLoading.favourited ? ' pointer-events-none' : '')" />
|
2022-11-14 03:56:48 +01:00
|
|
|
</div>
|
|
|
|
<span v-if="status.favouritesCount">{{ status.favouritesCount }}</span>
|
2022-11-13 06:34:43 +01:00
|
|
|
</button>
|
2022-11-15 22:20:07 +01:00
|
|
|
<button
|
|
|
|
flex gap-1 items-center w-full rounded hover="op100 text-yellow" group
|
2022-11-21 11:12:48 +01:00
|
|
|
:class="status.bookmarked ? 'text-yellow op100' : 'op50'"
|
2022-11-15 22:20:07 +01:00
|
|
|
@click="toggleBookmark()"
|
|
|
|
>
|
|
|
|
<div rounded-full p2 group-hover="bg-rose/10">
|
2022-11-16 22:07:24 +01:00
|
|
|
<div :class="(status.bookmarked ? 'i-ri:bookmark-fill' : 'i-ri:bookmark-line') + (isLoading.bookmarked ? ' pointer-events-none' : '')" />
|
2022-11-15 22:20:07 +01:00
|
|
|
</div>
|
|
|
|
</button>
|
2022-11-23 08:46:34 +01:00
|
|
|
<!-- <button flex gap-1 items-center w-full rounded op50 hover="op100 text-purple" group>
|
2022-11-14 03:56:48 +01:00
|
|
|
<div rounded-full p2 group-hover="bg-purple/10">
|
|
|
|
<div i-ri:share-circle-line />
|
|
|
|
</div>
|
2022-11-23 08:46:34 +01:00
|
|
|
</button> -->
|
2022-11-13 06:34:43 +01:00
|
|
|
</div>
|
|
|
|
</template>
|