[WiP] Quote in msg body

This commit is contained in:
ilya-bkv 2022-12-12 12:58:54 +03:00
parent 2ed61fd763
commit 0b82a5e379
4 changed files with 15 additions and 2 deletions

View File

@ -7,12 +7,15 @@ import type { Message, ChatMember } from '../../graphql/types.gen'
import formattedTime from '../../utils/formatDateTime' import formattedTime from '../../utils/formatDateTime'
import { Icon } from '../_shared/Icon' import { Icon } from '../_shared/Icon'
import { MessageActionsPopup } from './MessageActionsPopup' import { MessageActionsPopup } from './MessageActionsPopup'
import QuotedMessage from './QuotedMessage'
type Props = { type Props = {
content: Message content: Message
ownId: number ownId: number
members: ChatMember[] members: ChatMember[]
replyClick?: () => void replyClick?: () => void
replyBody?: string
replyAuthor?: string
} }
const md = new MarkdownIt({ const md = new MarkdownIt({
@ -38,6 +41,9 @@ const Message = (props: Props) => {
</div> </div>
<MessageActionsPopup trigger={<Icon name="menu" />} /> <MessageActionsPopup trigger={<Icon name="menu" />} />
</div> </div>
<Show when={props.replyBody}>
<QuotedMessage body={props.replyBody} variant="inline" />
</Show>
<div innerHTML={md.render(props.content.body)} /> <div innerHTML={md.render(props.content.body)} />
</div> </div>
</div> </div>

View File

@ -7,6 +7,7 @@ type QuotedMessage = {
body: string body: string
cancel?: () => void cancel?: () => void
author?: string author?: string
variant: 'inline' | 'reply'
} }
const QuotedMessage = (props: QuotedMessage) => { const QuotedMessage = (props: QuotedMessage) => {
@ -21,7 +22,7 @@ const QuotedMessage = (props: QuotedMessage) => {
</Show> </Show>
<div class={styles.quote}>{props.body}</div> <div class={styles.quote}>{props.body}</div>
</div> </div>
<Show when={props.cancel}> <Show when={props.cancel && props.variant !== 'inline'}>
<div class={clsx(styles.cancel, styles.icon)} onClick={props.cancel}> <div class={clsx(styles.cancel, styles.icon)} onClick={props.cancel}>
<Icon name="close-gray" /> <Icon name="close-gray" />
</div> </div>

View File

@ -134,6 +134,10 @@ export const InboxView = () => {
} }
} }
const findToReply = (messageId) => {
return messages().find((message) => message.id === messageId)
}
return ( return (
<div class={clsx('container', styles.Inbox)}> <div class={clsx('container', styles.Inbox)}>
<Modal variant="narrow" name="inviteToChat"> <Modal variant="narrow" name="inviteToChat">
@ -221,11 +225,11 @@ export const InboxView = () => {
content={message} content={message}
ownId={currentUserId()} ownId={currentUserId()}
members={currentDialog().members} members={currentDialog().members}
replyBody={message.replyTo && findToReply(message.replyTo).body}
replyClick={() => setMessageToReply(message)} replyClick={() => setMessageToReply(message)}
/> />
)} )}
</For> </For>
{/*<div class={styles.conversationDate}>*/} {/*<div class={styles.conversationDate}>*/}
{/* <time>12 сентября</time>*/} {/* <time>12 сентября</time>*/}
{/*</div>*/} {/*</div>*/}
@ -235,6 +239,7 @@ export const InboxView = () => {
<div class={styles.messageForm}> <div class={styles.messageForm}>
<Show when={messageToReply()}> <Show when={messageToReply()}>
<QuotedMessage <QuotedMessage
variant="reply"
author={ author={
currentDialog().members.find((member) => member.id === Number(messageToReply().author)) currentDialog().members.find((member) => member.id === Number(messageToReply().author))
.name .name

View File

@ -10,6 +10,7 @@ export default gql`
createdAt createdAt
id id
updatedAt updatedAt
replyTo
} }
} }
} }