From 26ba1448a3113dd2b09ceaa544258161e6d32b89 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Wed, 7 Dec 2022 09:10:45 +0300 Subject: [PATCH 1/2] Fix messages after merge --- src/components/Author/Card.tsx | 6 ++--- src/components/Inbox/DialogCard.tsx | 16 +++++++++----- src/components/Inbox/DialogHeader.tsx | 1 - src/components/Inbox/Message.tsx | 2 +- src/components/Views/Inbox.tsx | 32 +++++++++++++++++++-------- src/context/inbox.tsx | 2 +- src/context/session.tsx | 1 - 7 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/components/Author/Card.tsx b/src/components/Author/Card.tsx index afeb6197..d7d9b757 100644 --- a/src/components/Author/Card.tsx +++ b/src/components/Author/Card.tsx @@ -46,8 +46,8 @@ export const AuthorCard = (props: AuthorCardProps) => { } // TODO: reimplement AuthorCard const { changeSearchParam } = useRouter() - const handleInitChat = () => { - openPage(router, 'inbox') + const initChat = () => { + openPage(router, `inbox`) changeSearchParam('openChat', `${props.author.id}`) } return ( @@ -134,7 +134,7 @@ export const AuthorCard = (props: AuthorCardProps) => { 'button--subscribe-topic': props.isAuthorsList, [styles.buttonWrite]: props.liteButtons && props.isAuthorsList }} - onClick={handleInitChat} + onClick={initChat} > {t('Write')} diff --git a/src/components/Inbox/DialogCard.tsx b/src/components/Inbox/DialogCard.tsx index 1ac2284b..4960658a 100644 --- a/src/components/Inbox/DialogCard.tsx +++ b/src/components/Inbox/DialogCard.tsx @@ -22,9 +22,11 @@ const DialogCard = (props: DialogProps) => { const companions = createMemo( () => props.members && props.members.filter((member) => member.id !== props.ownId) ) - const names = companions() - ?.map((companion) => companion.name) - .join(', ') + const names = createMemo(() => + companions() + ?.map((companion) => companion.name) + .join(', ') + ) return ( @@ -37,11 +39,15 @@ const DialogCard = (props: DialogProps) => {
-
{props.title}
+
+ + 1}>{props.title} + +
{props.message} - 1}>{names} + 1}>{names()}
diff --git a/src/components/Inbox/DialogHeader.tsx b/src/components/Inbox/DialogHeader.tsx index 7c2ecf17..46fb540e 100644 --- a/src/components/Inbox/DialogHeader.tsx +++ b/src/components/Inbox/DialogHeader.tsx @@ -6,7 +6,6 @@ type DialogHeader = { chat: Chat ownId: number } - const DialogHeader = (props: DialogHeader) => { return (
diff --git a/src/components/Inbox/Message.tsx b/src/components/Inbox/Message.tsx index 2bc3d3b8..b7e54a93 100644 --- a/src/components/Inbox/Message.tsx +++ b/src/components/Inbox/Message.tsx @@ -19,7 +19,7 @@ const md = new MarkdownIt({ const Message = (props: Props) => { // возвращать ID автора const isOwn = props.ownId === Number(props.content.author) - const user = props.members.find((m) => m.id === Number(props.content.author)) + const user = props.members?.find((m) => m.id === Number(props.content.author)) return (
diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 2055ac5c..0029348d 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -18,6 +18,8 @@ import DialogHeader from '../Inbox/DialogHeader' import { apiClient } from '../../utils/apiClient' import { createChatClient } from '../../graphql/privateGraphQLClient' import MessagesFallback from '../Inbox/MessagesFallback' +import { useRouter } from '../../stores/router' +import createChat from '../../graphql/mutation/create-chat' const userSearch = (array: Author[], keyword: string) => { const searchTerm = keyword.toLowerCase() @@ -96,9 +98,26 @@ export const InboxView = () => { const handleChangeMessage = (event) => { setPostMessageText(event.target.value) } - createEffect(() => { - if (!textareaParent) return - textareaParent.dataset.replicatedValue = postMessageText() + + const { actions } = useInbox() + const urlParams = new URLSearchParams(window.location.search) + const params = Object.fromEntries(urlParams) + console.log('!!! params:', params) + + createEffect(async () => { + if (textareaParent) { + textareaParent.dataset.replicatedValue = postMessageText() + } + if (params['openChat']) { + try { + const newChat = await actions.createChat([Number(params['chat'])], '') + console.log('!!! newChat:', newChat) + await handleOpenChat(newChat.chat) + await loadChats() + } catch (error) { + console.error(error) + } + } }) const handleOpenInviteModal = () => { @@ -109,7 +128,6 @@ export const InboxView = () => { const sorted = chats().sort((a, b) => { return a.updatedAt - b.updatedAt }) - console.log('!!! sorted:', sorted) if (sortByPerToPer()) { return sorted.filter((chat) => chat.title.trim().length === 0) } else if (sortByGroup()) { @@ -119,10 +137,6 @@ export const InboxView = () => { } } - createEffect(() => { - console.log('!!! currentDialog():', currentDialog()) - }) - return (
@@ -174,7 +188,7 @@ export const InboxView = () => { {(chat) => ( handleOpenChat(chat)} - title={chat.title || chat.members[0].name} + title={chat.title} members={chat.members} ownId={currentUserId()} lastUpdate={chat.updatedAt} diff --git a/src/context/inbox.tsx b/src/context/inbox.tsx index d9c445bb..62df01b6 100644 --- a/src/context/inbox.tsx +++ b/src/context/inbox.tsx @@ -6,7 +6,7 @@ import { apiClient } from '../utils/apiClient' type InboxContextType = { chats: Accessor actions: { - createChat: (members: number[], title: string) => Promise + createChat: (members: number[], title: string) => Promise<{ chat: Chat }> loadChats: () => Promise } } diff --git a/src/context/session.tsx b/src/context/session.tsx index d603149c..966d8d6f 100644 --- a/src/context/session.tsx +++ b/src/context/session.tsx @@ -23,7 +23,6 @@ const getSession = async (): Promise => { if (!authResult) { return null } - console.log('!!! authResult:', authResult) setToken(authResult.token) return authResult } catch (error) { From c41edc338704d5c474770e9b00d258024e60f329 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Wed, 7 Dec 2022 09:15:33 +0300 Subject: [PATCH 2/2] lint temp.fix --- src/components/EditorNew/Editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/EditorNew/Editor.tsx b/src/components/EditorNew/Editor.tsx index d8ea9ded..441ba1eb 100644 --- a/src/components/EditorNew/Editor.tsx +++ b/src/components/EditorNew/Editor.tsx @@ -59,7 +59,7 @@ export const Editor = () => { const handleSaveButtonClick = () => { const article: ShoutInput = { body: getHtml(editorViewRef.current.state), - community: 'discours', // ? + // community: 'discours', // ? Type 'string' is not assignable to type 'number'. slug: 'new-' + Math.floor(Math.random() * 1000000) } createArticle({ article })