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

49 lines
1.5 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 { Button } from 'flowbite-react'
import { FormattedMessage } from 'react-intl'
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-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
className="spoiler-text"
style={Object.assign({ wordWrap: 'break-word' }, props.style)}
dangerouslySetInnerHTML={{ __html: emojify(props.status.spoiler_text, props.status.emojis) }}
onClick={props.onClick}
/>
<Button size="xs" color="gray" className="focus:ring-0 my-1" onClick={() => setSpoilered(current => !current)}>
{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
2023-12-02 05:30:01 +01:00
className={`${props.className} raw-html`}
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-11-03 12:37:40 +01:00
</>
)
}