2024-05-31 19:49:46 +05:30
|
|
|
import React from 'react';
|
2026-06-01 17:21:11 -04:00
|
|
|
import parse from 'html-react-parser';
|
2024-05-31 19:49:46 +05:30
|
|
|
import { as, Box, Header, Icon, IconButton, Icons, Modal, Scroll, Text } from 'folds';
|
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
import Linkify from 'linkify-react';
|
2026-06-18 22:46:19 -04:00
|
|
|
import { useModalStyle } from '../../hooks/useModalStyle';
|
2024-05-31 19:49:46 +05:30
|
|
|
import * as css from './style.css';
|
|
|
|
|
import { LINKIFY_OPTS, scaleSystemEmoji } from '../../plugins/react-custom-html-parser';
|
2026-06-01 17:21:11 -04:00
|
|
|
import { sanitizeCustomHtml } from '../../utils/sanitize';
|
|
|
|
|
import { RoomTopicContent } from '../../hooks/useRoomMeta';
|
2024-05-31 19:49:46 +05:30
|
|
|
|
|
|
|
|
export const RoomTopicViewer = as<
|
|
|
|
|
'div',
|
|
|
|
|
{
|
|
|
|
|
name: string;
|
2026-06-01 17:21:11 -04:00
|
|
|
topic: string | RoomTopicContent;
|
2024-05-31 19:49:46 +05:30
|
|
|
requestClose: () => void;
|
|
|
|
|
}
|
2026-06-01 17:21:11 -04:00
|
|
|
>(({ name, topic, requestClose, className, ...props }, ref) => {
|
|
|
|
|
const topicStr = typeof topic === 'string' ? topic : topic.topic;
|
2026-06-18 18:11:24 -04:00
|
|
|
const modalStyle = useModalStyle(480);
|
2026-06-01 17:21:11 -04:00
|
|
|
const isFormatted =
|
|
|
|
|
typeof topic !== 'string' &&
|
|
|
|
|
topic.format === 'org.matrix.custom.html' &&
|
|
|
|
|
typeof topic.formatted_body === 'string';
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
size="300"
|
|
|
|
|
flexHeight
|
|
|
|
|
className={classNames(css.ModalFlex, className)}
|
|
|
|
|
aria-labelledby="room-topic-title"
|
2026-06-18 18:11:24 -04:00
|
|
|
style={modalStyle}
|
2026-06-01 17:21:11 -04:00
|
|
|
{...props}
|
|
|
|
|
ref={ref}
|
|
|
|
|
>
|
|
|
|
|
<Header className={css.ModalHeader} variant="Surface" size="500">
|
|
|
|
|
<Box grow="Yes">
|
|
|
|
|
<Text as="h2" size="H4" truncate id="room-topic-title">
|
|
|
|
|
{name}
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
<IconButton size="300" onClick={requestClose} radii="300" aria-label="Close">
|
|
|
|
|
<Icon src={Icons.Cross} />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Header>
|
|
|
|
|
<Scroll className={css.ModalScroll} size="300" hideTrack>
|
|
|
|
|
<Box className={css.ModalContent} direction="Column" gap="100">
|
|
|
|
|
<Text size="T300" className={css.ModalTopic} priority="400">
|
|
|
|
|
{isFormatted ? (
|
|
|
|
|
parse(sanitizeCustomHtml((topic as RoomTopicContent).formatted_body!))
|
|
|
|
|
) : (
|
|
|
|
|
<Linkify options={LINKIFY_OPTS}>{scaleSystemEmoji(topicStr)}</Linkify>
|
|
|
|
|
)}
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
</Scroll>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
});
|