2023-11-13 12:20:25 +01:00
|
|
|
import { Entity, MegalodonInterface } from 'megalodon'
|
2023-11-28 16:37:21 +01:00
|
|
|
import { useRouter } from 'next/router'
|
2023-12-11 16:00:44 +01:00
|
|
|
import { FaBookmark, FaEllipsis, FaFaceLaughBeam, FaReply, FaRetweet, FaStar } from 'react-icons/fa6'
|
|
|
|
import Picker from '@emoji-mart/react'
|
|
|
|
import { data } from '@/utils/emojiData'
|
|
|
|
import { Account } from '@/db'
|
2024-01-30 16:51:36 +01:00
|
|
|
import { FormattedMessage, useIntl } from 'react-intl'
|
2024-01-09 13:30:05 +01:00
|
|
|
import { IconButton, List, ListItem, Popover, PopoverContent, PopoverHandler } from '@material-tailwind/react'
|
|
|
|
import { useState } from 'react'
|
2024-03-08 13:05:59 +01:00
|
|
|
import { invoke } from '@/utils/invoke'
|
2023-11-09 14:41:13 +01:00
|
|
|
|
2023-11-13 12:20:25 +01:00
|
|
|
type Props = {
|
|
|
|
status: Entity.Status
|
2023-12-11 16:00:44 +01:00
|
|
|
account: Account
|
2023-11-13 12:20:25 +01:00
|
|
|
client: MegalodonInterface
|
|
|
|
onRefresh: () => void
|
|
|
|
}
|
2023-11-09 14:41:13 +01:00
|
|
|
|
|
|
|
export default function Actions(props: Props) {
|
2024-01-09 13:30:05 +01:00
|
|
|
const [popoverDetail, setPopoverDetail] = useState(false)
|
|
|
|
const [popoverEmoji, setPopoverEmoji] = useState(false)
|
2023-11-28 16:37:21 +01:00
|
|
|
const router = useRouter()
|
2024-01-30 16:51:36 +01:00
|
|
|
const { formatMessage } = useIntl()
|
2023-11-28 16:37:21 +01:00
|
|
|
|
|
|
|
const reply = async () => {
|
|
|
|
router.push({ query: { id: router.query.id, timeline: router.query.timeline, reply_target_id: props.status.id, detail: true } })
|
|
|
|
}
|
|
|
|
|
2023-11-13 12:20:25 +01:00
|
|
|
const reblog = async () => {
|
|
|
|
if (props.status.reblogged) {
|
|
|
|
await props.client.unreblogStatus(props.status.id)
|
|
|
|
} else {
|
|
|
|
await props.client.reblogStatus(props.status.id)
|
|
|
|
}
|
|
|
|
props.onRefresh()
|
|
|
|
}
|
|
|
|
|
|
|
|
const favourite = async () => {
|
|
|
|
if (props.status.favourited) {
|
|
|
|
await props.client.unfavouriteStatus(props.status.id)
|
|
|
|
} else {
|
|
|
|
await props.client.favouriteStatus(props.status.id)
|
|
|
|
}
|
|
|
|
props.onRefresh()
|
|
|
|
}
|
|
|
|
|
|
|
|
const bookmark = async () => {
|
|
|
|
if (props.status.bookmarked) {
|
|
|
|
await props.client.unbookmarkStatus(props.status.id)
|
|
|
|
} else {
|
|
|
|
await props.client.bookmarkStatus(props.status.id)
|
|
|
|
}
|
|
|
|
props.onRefresh()
|
|
|
|
}
|
|
|
|
|
2023-12-11 16:00:44 +01:00
|
|
|
const onEmojiSelect = async emoji => {
|
|
|
|
await props.client.createEmojiReaction(props.status.id, emoji.native)
|
2024-01-13 13:44:43 +01:00
|
|
|
setPopoverEmoji(false)
|
2023-12-11 16:00:44 +01:00
|
|
|
props.onRefresh()
|
|
|
|
}
|
|
|
|
|
2024-01-13 13:44:43 +01:00
|
|
|
const original = () => {
|
|
|
|
setPopoverDetail(false)
|
2024-03-08 13:05:59 +01:00
|
|
|
invoke('open-browser', props.status.url)
|
2024-01-13 13:44:43 +01:00
|
|
|
}
|
|
|
|
|
2023-12-12 16:49:00 +01:00
|
|
|
const report = () => {
|
2024-01-09 13:30:05 +01:00
|
|
|
setPopoverDetail(false)
|
2023-12-12 16:49:00 +01:00
|
|
|
router.push({ query: { id: router.query.id, timeline: router.query.timeline, report_target_id: props.status.id, modal: true } })
|
|
|
|
}
|
|
|
|
|
2023-11-09 14:41:13 +01:00
|
|
|
return (
|
2024-01-09 13:30:05 +01:00
|
|
|
<div className="flex gap-2">
|
2024-01-30 16:51:36 +01:00
|
|
|
<IconButton
|
|
|
|
variant="text"
|
|
|
|
size="sm"
|
|
|
|
onClick={reply}
|
|
|
|
className="text-gray-400 text-base hover:text-gray-600"
|
|
|
|
title={formatMessage({ id: 'timeline.status.actions.reply' })}
|
|
|
|
>
|
2024-01-09 13:30:05 +01:00
|
|
|
<FaReply className="w-4" />
|
|
|
|
</IconButton>
|
2024-01-30 16:51:36 +01:00
|
|
|
<IconButton
|
|
|
|
variant="text"
|
|
|
|
size="sm"
|
|
|
|
onClick={reblog}
|
|
|
|
className={`${retweetColor(props.status)} text-base hover:text-gray-600`}
|
|
|
|
title={formatMessage({ id: 'timeline.status.actions.reblog' })}
|
|
|
|
>
|
2024-01-09 13:30:05 +01:00
|
|
|
<FaRetweet className="w-4" />
|
|
|
|
</IconButton>
|
2024-01-30 16:51:36 +01:00
|
|
|
<IconButton
|
|
|
|
variant="text"
|
|
|
|
size="sm"
|
|
|
|
onClick={favourite}
|
|
|
|
className={`${favouriteColor(props.status)} text-base hover:text-gray-600`}
|
|
|
|
title={formatMessage({ id: 'timeline.status.actions.favourite' })}
|
|
|
|
>
|
2024-01-09 13:30:05 +01:00
|
|
|
<FaStar className="w-4" />
|
|
|
|
</IconButton>
|
2024-01-30 16:51:36 +01:00
|
|
|
<IconButton
|
|
|
|
variant="text"
|
|
|
|
size="sm"
|
|
|
|
onClick={bookmark}
|
|
|
|
className={`${bookmarkColor(props.status)} text-base hover:text-gray-600`}
|
|
|
|
title={formatMessage({ id: 'timeline.status.actions.bookmark' })}
|
|
|
|
>
|
2024-01-09 13:30:05 +01:00
|
|
|
<FaBookmark className="w-4" />
|
|
|
|
</IconButton>
|
2023-12-11 16:00:44 +01:00
|
|
|
{props.account.sns !== 'mastodon' && (
|
2024-01-09 13:30:05 +01:00
|
|
|
<Popover open={popoverEmoji} handler={setPopoverEmoji}>
|
|
|
|
<PopoverHandler>
|
2024-01-30 16:51:36 +01:00
|
|
|
<IconButton
|
|
|
|
variant="text"
|
|
|
|
size="sm"
|
|
|
|
className="text-gray-400 hover:text-gray-600 text-base"
|
|
|
|
title={formatMessage({ id: 'timeline.status.actions.emoji_reaction' })}
|
|
|
|
>
|
2024-01-09 13:30:05 +01:00
|
|
|
<FaFaceLaughBeam />
|
|
|
|
</IconButton>
|
|
|
|
</PopoverHandler>
|
|
|
|
<PopoverContent className="z-10">
|
2023-12-11 16:00:44 +01:00
|
|
|
<Picker data={data} onEmojiSelect={onEmojiSelect} previewPosition="none" set="native" perLine="7" theme="light" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
2023-12-11 16:00:44 +01:00
|
|
|
)}
|
|
|
|
|
2024-01-09 13:30:05 +01:00
|
|
|
<Popover open={popoverDetail} handler={setPopoverDetail}>
|
|
|
|
<PopoverHandler>
|
2024-01-30 16:51:36 +01:00
|
|
|
<IconButton
|
|
|
|
variant="text"
|
|
|
|
size="sm"
|
|
|
|
className="text-gray-400 hover:text-gray-600 text-base"
|
|
|
|
title={formatMessage({ id: 'timeline.status.actions.detail' })}
|
|
|
|
>
|
2023-12-12 16:49:00 +01:00
|
|
|
<FaEllipsis className="w-4" />
|
2024-01-09 13:30:05 +01:00
|
|
|
</IconButton>
|
|
|
|
</PopoverHandler>
|
|
|
|
<PopoverContent className="z-10">
|
|
|
|
<List className="py-2 px-0">
|
2024-01-13 13:44:43 +01:00
|
|
|
<ListItem onClick={original} className="rounded-none">
|
|
|
|
<FormattedMessage id="timeline.status.open_original" />
|
|
|
|
</ListItem>
|
2024-01-09 13:30:05 +01:00
|
|
|
<ListItem onClick={report} className="rounded-none">
|
|
|
|
<FormattedMessage id="timeline.status.report" values={{ user: `@${props.status.account.acct}` }} />
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
2023-11-09 14:41:13 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2023-11-13 12:20:25 +01:00
|
|
|
|
|
|
|
const retweetColor = (status: Entity.Status) => {
|
|
|
|
if (status.reblogged) {
|
|
|
|
return 'text-blue-600'
|
|
|
|
} else {
|
|
|
|
return 'text-gray-400'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const favouriteColor = (status: Entity.Status) => {
|
|
|
|
if (status.favourited) {
|
|
|
|
return 'text-orange-400'
|
|
|
|
} else {
|
|
|
|
return 'text-gray-400'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const bookmarkColor = (status: Entity.Status) => {
|
|
|
|
if (status.bookmarked) {
|
2024-01-09 13:30:05 +01:00
|
|
|
return 'text-red-500'
|
2023-11-13 12:20:25 +01:00
|
|
|
} else {
|
|
|
|
return 'text-gray-400'
|
|
|
|
}
|
|
|
|
}
|