Whalebird-desktop-client-ma.../renderer/components/timelines/status/Body.tsx

51 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-03 12:37:40 +01:00
import { Entity } from 'megalodon'
2023-11-25 06:50:46 +01:00
import { Dispatch, HTMLAttributes, SetStateAction } from 'react'
2023-11-03 12:37:40 +01:00
import emojify from '@/utils/emojify'
2023-11-25 06:50:46 +01:00
import { FormattedMessage } from 'react-intl'
import { Button } from '@material-tailwind/react'
2023-11-03 12:37:40 +01:00
type Props = {
status: Entity.Status
2023-11-25 06:50:46 +01:00
spoilered: boolean
setSpoilered: Dispatch<SetStateAction<boolean>>
2023-12-02 16:52:51 +01:00
onClick?: (e: any) => void
2023-11-03 12:37:40 +01:00
} & HTMLAttributes<HTMLElement>
export default function Body(props: Props) {
2023-11-25 06:50:46 +01:00
const { spoilered, setSpoilered } = props
const spoiler = () => {
if (props.status.spoiler_text.length > 0) {
return (
2023-12-02 05:30:01 +01:00
<div className="raw-html">
2023-11-25 06:50:46 +01:00
<div
2024-09-01 07:21:03 +02:00
className="spoiler-text font-thin"
2023-11-25 06:50:46 +01:00
style={Object.assign({ wordWrap: 'break-word' }, props.style)}
dangerouslySetInnerHTML={{ __html: emojify(props.status.spoiler_text, props.status.emojis) }}
onClick={props.onClick}
/>
<Button size="sm" onClick={() => setSpoilered(current => !current)} variant="outlined" color="blue-gray">
2023-11-25 06:50:46 +01:00
{spoilered ? <FormattedMessage id="timeline.status.show_more" /> : <FormattedMessage id="timeline.status.show_less" />}
</Button>
</div>
)
} else {
return null
}
}
2023-11-03 12:37:40 +01:00
return (
<>
2023-11-25 06:50:46 +01:00
{spoiler()}
{!spoilered && (
<div
2024-09-01 07:21:03 +02:00
className={`${props.className} raw-html font-thin`}
2023-11-25 06:50:46 +01:00
style={Object.assign({ wordWrap: 'break-word' }, props.style)}
dangerouslySetInnerHTML={{ __html: emojify(props.status.content, props.status.emojis) }}
2023-12-02 16:52:51 +01:00
onClick={props.onClick}
2023-11-25 06:50:46 +01:00
/>
)}
2023-11-03 12:37:40 +01:00
</>
)
}