2023-12-11 16:00:44 +01:00
|
|
|
import { CustomFlowbiteTheme, Dropdown, Flowbite } from 'flowbite-react'
|
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'
|
2023-12-12 16:49:00 +01:00
|
|
|
import { FormattedMessage } from 'react-intl'
|
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
|
|
|
|
2023-12-11 16:00:44 +01:00
|
|
|
const customTheme: CustomFlowbiteTheme = {
|
|
|
|
dropdown: {
|
|
|
|
content: 'focus:outline-none',
|
|
|
|
floating: {
|
|
|
|
item: {
|
|
|
|
base: 'hidden'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-09 14:41:13 +01:00
|
|
|
export default function Actions(props: Props) {
|
2023-11-28 16:37:21 +01:00
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
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)
|
|
|
|
const dummy = document.getElementById('dummy-emoji-picker')
|
|
|
|
dummy.click()
|
|
|
|
props.onRefresh()
|
|
|
|
}
|
|
|
|
|
2023-12-12 16:49:00 +01:00
|
|
|
const report = () => {
|
|
|
|
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 (
|
|
|
|
<div className="flex gap-6">
|
2023-11-28 16:37:21 +01:00
|
|
|
<FaReply className={`w-4 text-gray-400 cursor-pointer hover:text-gray-600`} onClick={reply} />
|
2023-11-13 12:20:25 +01:00
|
|
|
<FaRetweet className={`${retweetColor(props.status)} w-4 cursor-pointer hover:text-gray-600`} onClick={reblog} />
|
|
|
|
<FaStar className={`${favouriteColor(props.status)} w-4 cursor-pointer hover:text-gray-600`} onClick={favourite} />
|
|
|
|
<FaBookmark className={`${bookmarkColor(props.status)} w-4 cursor-pointer hover:text-gray-600`} onClick={bookmark} />
|
2023-12-11 16:00:44 +01:00
|
|
|
{props.account.sns !== 'mastodon' && (
|
|
|
|
<Flowbite theme={{ theme: customTheme }}>
|
|
|
|
<Dropdown
|
|
|
|
label=""
|
|
|
|
dismissOnClick
|
|
|
|
renderTrigger={() => (
|
|
|
|
<span className="text-gray-400 hover:text-gray-600 cursor-pointer">
|
|
|
|
<FaFaceLaughBeam />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Picker data={data} onEmojiSelect={onEmojiSelect} previewPosition="none" set="native" perLine="7" theme="light" />
|
|
|
|
<Dropdown.Item>
|
|
|
|
<span id="dummy-emoji-picker" />
|
|
|
|
</Dropdown.Item>
|
|
|
|
</Dropdown>
|
|
|
|
</Flowbite>
|
|
|
|
)}
|
|
|
|
|
2023-12-12 16:49:00 +01:00
|
|
|
<Dropdown
|
|
|
|
label=""
|
|
|
|
dismissOnClick
|
|
|
|
renderTrigger={() => (
|
|
|
|
<span className="text-gray-400 hover:text-gray-600 cursor-pointer">
|
|
|
|
<FaEllipsis className="w-4" />
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<Dropdown.Item onClick={report}>
|
|
|
|
<FormattedMessage id="timeline.status.report" values={{ user: `@${props.status.account.acct}` }} />
|
|
|
|
</Dropdown.Item>
|
|
|
|
</Dropdown>
|
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) {
|
|
|
|
return 'text-rose-500'
|
|
|
|
} else {
|
|
|
|
return 'text-gray-400'
|
|
|
|
}
|
|
|
|
}
|