diff --git a/web/modals/threads/subchannels/subchannel.react.js b/web/modals/threads/subchannels/subchannel.react.js new file mode 100644 --- /dev/null +++ b/web/modals/threads/subchannels/subchannel.react.js @@ -0,0 +1,75 @@ +// @flow + +import * as React from 'react'; + +import { useMessagePreview } from 'lib/hooks/message-preview'; +import { type ChatThreadItem } from 'lib/selectors/chat-selectors'; +import { shortAbsoluteDate } from 'lib/utils/date-utils'; + +import { getDefaultTextMessageRules } from '../../../markdown/rules.react'; +import { useSelector } from '../../../redux/redux-utils'; +import { useOnClickThread } from '../../../selectors/nav-selectors'; +import SWMansionIcon from '../../../SWMansionIcon.react'; +import { useModalContext } from '../../modal-provider.react'; +import css from './subchannels-modal.css'; + +type Props = { + chatThreadItem: ChatThreadItem, +}; + +function Subchannel(props: Props): React.Node { + const { chatThreadItem } = props; + const { + threadInfo, + mostRecentMessageInfo, + lastUpdatedTimeIncludingSidebars, + } = chatThreadItem; + + const timeZone = useSelector(state => state.timeZone); + const { clearModal } = useModalContext(); + + const navigateToThread = useOnClickThread(threadInfo); + + const onClickThread = React.useCallback( + event => { + clearModal(); + navigateToThread(event); + }, + [clearModal, navigateToThread], + ); + + const lastActivity = React.useMemo( + () => shortAbsoluteDate(lastUpdatedTimeIncludingSidebars, timeZone), + [lastUpdatedTimeIncludingSidebars, timeZone], + ); + const { message, username } = useMessagePreview( + mostRecentMessageInfo, + threadInfo, + getDefaultTextMessageRules().simpleMarkdownRules, + ); + + const lastMessage = React.useMemo(() => { + if (!mostRecentMessageInfo) { + return