Fix messages after merge
This commit is contained in:
parent
80577c2cd3
commit
26ba1448a3
|
@ -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}
|
||||
>
|
||||
<Icon name="comment" class={styles.icon} />
|
||||
<Show when={!props.liteButtons}>{t('Write')}</Show>
|
||||
|
|
|
@ -22,9 +22,11 @@ const DialogCard = (props: DialogProps) => {
|
|||
const companions = createMemo(
|
||||
() => props.members && props.members.filter((member) => member.id !== props.ownId)
|
||||
)
|
||||
const names = companions()
|
||||
const names = createMemo(() =>
|
||||
companions()
|
||||
?.map((companion) => companion.name)
|
||||
.join(', ')
|
||||
)
|
||||
|
||||
return (
|
||||
<Show when={props.members}>
|
||||
|
@ -37,11 +39,15 @@ const DialogCard = (props: DialogProps) => {
|
|||
</Switch>
|
||||
</div>
|
||||
<div class={styles.row}>
|
||||
<div class={styles.name}>{props.title}</div>
|
||||
<div class={styles.name}>
|
||||
<Switch fallback={names()}>
|
||||
<Match when={companions().length > 1}>{props.title}</Match>
|
||||
</Switch>
|
||||
</div>
|
||||
<div class={styles.message}>
|
||||
<Switch>
|
||||
<Match when={props.message && !props.isChatHeader}>{props.message}</Match>
|
||||
<Match when={props.isChatHeader && companions().length > 1}>{names}</Match>
|
||||
<Match when={props.isChatHeader && companions().length > 1}>{names()}</Match>
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,6 @@ type DialogHeader = {
|
|||
chat: Chat
|
||||
ownId: number
|
||||
}
|
||||
|
||||
const DialogHeader = (props: DialogHeader) => {
|
||||
return (
|
||||
<header class={styles.DialogHeader}>
|
||||
|
|
|
@ -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 (
|
||||
<div class={clsx(styles.Message, isOwn && styles.own)}>
|
||||
<Show when={!isOwn}>
|
||||
|
|
|
@ -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
|
||||
|
||||
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 (
|
||||
<div class="messages container">
|
||||
<Modal variant="narrow" name="inviteToChat">
|
||||
|
@ -174,7 +188,7 @@ export const InboxView = () => {
|
|||
{(chat) => (
|
||||
<DialogCard
|
||||
onClick={() => handleOpenChat(chat)}
|
||||
title={chat.title || chat.members[0].name}
|
||||
title={chat.title}
|
||||
members={chat.members}
|
||||
ownId={currentUserId()}
|
||||
lastUpdate={chat.updatedAt}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { apiClient } from '../utils/apiClient'
|
|||
type InboxContextType = {
|
||||
chats: Accessor<Chat[]>
|
||||
actions: {
|
||||
createChat: (members: number[], title: string) => Promise<void>
|
||||
createChat: (members: number[], title: string) => Promise<{ chat: Chat }>
|
||||
loadChats: () => Promise<void>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ const getSession = async (): Promise<AuthResult> => {
|
|||
if (!authResult) {
|
||||
return null
|
||||
}
|
||||
console.log('!!! authResult:', authResult)
|
||||
setToken(authResult.token)
|
||||
return authResult
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user