From 072213fcc0578ef417a9f7aae5ae26761d411c1c Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Mon, 12 Dec 2022 09:09:06 +0300 Subject: [PATCH] Quoted message --- src/components/Inbox/Message.tsx | 3 ++ .../Inbox/QuotedMessage.module.scss | 33 ++++++++++++++++++ src/components/Inbox/QuotedMessage.tsx | 33 ++++++++++++++++++ src/components/Views/Inbox.tsx | 33 +++++++----------- src/graphql/mutation/create-chat-message.ts | 4 +-- src/styles/Inbox.module.scss | 34 ------------------- 6 files changed, 84 insertions(+), 56 deletions(-) create mode 100644 src/components/Inbox/QuotedMessage.module.scss create mode 100644 src/components/Inbox/QuotedMessage.tsx diff --git a/src/components/Inbox/Message.tsx b/src/components/Inbox/Message.tsx index af78f306..a4a7c44b 100644 --- a/src/components/Inbox/Message.tsx +++ b/src/components/Inbox/Message.tsx @@ -40,6 +40,9 @@ const Message = (props: Props) => {
+ + Repl to {props.content.replyTo} +
{formattedTime(props.content.createdAt)}
) diff --git a/src/components/Inbox/QuotedMessage.module.scss b/src/components/Inbox/QuotedMessage.module.scss new file mode 100644 index 00000000..c0876a20 --- /dev/null +++ b/src/components/Inbox/QuotedMessage.module.scss @@ -0,0 +1,33 @@ +.QuotedMessage { + display: flex; + flex-direction: row; + align-items: center; + border-top: 2px solid #ccc; + padding: 12px 0; + gap: 12px; + font-size: 14px; + + .icon { + width: 40px; + height: 40px; + + &.cancel { + cursor: pointer; + } + } + + .body { + flex-grow: 1; + overflow: hidden; + + .author { + font-weight: 600; + } + + .quote { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + } +} diff --git a/src/components/Inbox/QuotedMessage.tsx b/src/components/Inbox/QuotedMessage.tsx new file mode 100644 index 00000000..315a4bf0 --- /dev/null +++ b/src/components/Inbox/QuotedMessage.tsx @@ -0,0 +1,33 @@ +import { Show } from 'solid-js' +import styles from './QuotedMessage.module.scss' +import { Icon } from '../_shared/Icon' +import { clsx } from 'clsx' + +type QuotedMessage = { + body: string + cancel?: () => void + author?: string +} + +const QuotedMessage = (props: QuotedMessage) => { + return ( +
+
+ +
+
+ +
{props.author}
+
+
{props.body}
+
+ +
+ +
+
+
+ ) +} + +export default QuotedMessage diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 769c5c10..f694cda0 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -17,6 +17,7 @@ import MessagesFallback from '../Inbox/MessagesFallback' import { useRouter } from '../../stores/router' import { clsx } from 'clsx' import styles from '../../styles/Inbox.module.scss' +import QuotedMessage from '../Inbox/QuotedMessage' const userSearch = (array: Author[], keyword: string) => { const searchTerm = keyword.toLowerCase() @@ -79,10 +80,12 @@ export const InboxView = () => { try { const post = await apiClient.createMessage({ body: postMessageText().toString(), - chat: currentDialog().id.toString() + chat: currentDialog().id.toString(), + replyTo: messageToReply()?.id }) setMessages((prev) => [...prev, post.message]) setPostMessageText('') + setMessageToReply(null) chatWindow.scrollTop = chatWindow.scrollHeight } catch (error) { console.error('[post message error]:', error) @@ -98,10 +101,10 @@ export const InboxView = () => { const urlParams = new URLSearchParams(window.location.search) const params = Object.fromEntries(urlParams) createEffect(async () => { - console.log('!!! postMessageText:', postMessageText()) if (textareaParent) { textareaParent.dataset.replicatedValue = postMessageText() } + console.log('!!! messages:', messages()) if (params['initChat']) { try { const newChat = await actions.createChat([Number(params['initChat'])], '') @@ -231,24 +234,14 @@ export const InboxView = () => {
-
-
- -
-
-
- { - currentDialog().members.find( - (member) => member.id === Number(messageToReply().author) - ).name - } -
-
{messageToReply().body}
-
-
setMessageToReply(null)}> - -
-
+ member.id === Number(messageToReply().author)) + .name + } + body={messageToReply().body} + cancel={() => setMessageToReply(undefined)} + />
diff --git a/src/graphql/mutation/create-chat-message.ts b/src/graphql/mutation/create-chat-message.ts index f2e0f589..ef13221c 100644 --- a/src/graphql/mutation/create-chat-message.ts +++ b/src/graphql/mutation/create-chat-message.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - mutation createMessage($chat: String!, $body: String!) { - createMessage(chat: $chat, body: $body) { + mutation createMessage($chat: String!, $body: String!, $replyTo: Int) { + createMessage(chat: $chat, body: $body, replyTo: $replyTo) { error message { id diff --git a/src/styles/Inbox.module.scss b/src/styles/Inbox.module.scss index 59ea98c2..2f0fca7b 100644 --- a/src/styles/Inbox.module.scss +++ b/src/styles/Inbox.module.scss @@ -131,40 +131,6 @@ main { background: #fff; padding: 2px 0 12px; - .reply { - display: flex; - flex-direction: row; - align-items: center; - border-top: 2px solid #ccc; - padding: 12px 0; - gap: 12px; - font-size: 14px; - - .icon { - width: 40px; - height: 40px; - - &.cancel { - cursor: pointer; - } - } - - .body { - flex-grow: 1; - overflow: hidden; - - .author { - font-weight: 600; - } - - .quote { - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - } - } - } - .wrapper { border: 2px solid #ccc; border-radius: 16px;