Chat list [WiP]
This commit is contained in:
parent
85f82d4898
commit
ba7395f4b7
|
@ -1,6 +1,6 @@
|
||||||
import styles from './DialogCard.module.scss'
|
import styles from './DialogCard.module.scss'
|
||||||
import DialogAvatar from './DialogAvatar'
|
import DialogAvatar from './DialogAvatar'
|
||||||
import type { Author } from '../../graphql/types.gen'
|
import type { Author, User } from '../../graphql/types.gen'
|
||||||
import { apiClient } from '../../utils/apiClient'
|
import { apiClient } from '../../utils/apiClient'
|
||||||
import { t } from '../../utils/intl'
|
import { t } from '../../utils/intl'
|
||||||
import { useInbox } from '../../context/inbox'
|
import { useInbox } from '../../context/inbox'
|
||||||
|
@ -9,19 +9,21 @@ type DialogProps = {
|
||||||
online?: boolean
|
online?: boolean
|
||||||
message?: string
|
message?: string
|
||||||
counter?: number
|
counter?: number
|
||||||
author?: Author
|
users: User[]
|
||||||
ownSlug: Author['slug']
|
ownSlug: User['slug']
|
||||||
}
|
}
|
||||||
|
|
||||||
const DialogCard = (props: DialogProps) => {
|
const DialogCard = (props: DialogProps) => {
|
||||||
|
// @ts-ignore
|
||||||
|
const participants = props.users.filter((user) => user !== props.ownSlug)
|
||||||
|
console.log('!!! participants:', participants)
|
||||||
|
// @ts-ignore
|
||||||
return (
|
return (
|
||||||
//DialogCardView - подумать
|
//DialogCardView - подумать
|
||||||
<div class={styles.DialogCard}>
|
<div class={styles.DialogCard}>
|
||||||
<div class={styles.avatar}>
|
<div class={styles.avatar}>{/*<DialogAvatar name={participants[0]} online={props.online} />*/}</div>
|
||||||
<DialogAvatar name={props.author.name} url={props.author.userpic} online={props.online} />
|
|
||||||
</div>
|
|
||||||
<div class={styles.row}>
|
<div class={styles.row}>
|
||||||
<div class={styles.name}>{props.author.name}</div>
|
{/*<div class={styles.name}>{participants[0]}</div>*/}
|
||||||
<div class={styles.message}>
|
<div class={styles.message}>
|
||||||
Указать предпочтительные языки для результатов поиска можно в разделе
|
Указать предпочтительные языки для результатов поиска можно в разделе
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { For, createSignal, Show, onMount, createEffect, createMemo } from 'solid-js'
|
import { For, createSignal, Show, onMount, createEffect, createMemo } from 'solid-js'
|
||||||
import type { Author } from '../../graphql/types.gen'
|
import type { Author, Chat } from '../../graphql/types.gen'
|
||||||
import { AuthorCard } from '../Author/Card'
|
import { AuthorCard } from '../Author/Card'
|
||||||
import { Icon } from '../_shared/Icon'
|
import { Icon } from '../_shared/Icon'
|
||||||
import { Loading } from '../Loading'
|
import { Loading } from '../Loading'
|
||||||
|
@ -58,18 +58,10 @@ const postMessage = async (msg: string) => {
|
||||||
return response.data.createComment
|
return response.data.createComment
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleGetChats = async () => {
|
|
||||||
try {
|
|
||||||
const response = await loadChats()
|
|
||||||
console.log('!!! handleGetChats:', response)
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const InboxView = () => {
|
export const InboxView = () => {
|
||||||
const [messages, setMessages] = createSignal([])
|
const [messages, setMessages] = createSignal([])
|
||||||
const [recipients, setRecipients] = createSignal<Author[]>([])
|
const [recipients, setRecipients] = createSignal<Author[]>([])
|
||||||
|
const [chats, setChats] = createSignal<Chat[]>([])
|
||||||
const [cashedRecipients, setCashedRecipients] = createSignal<Author[]>([])
|
const [cashedRecipients, setCashedRecipients] = createSignal<Author[]>([])
|
||||||
const [postMessageText, setPostMessageText] = createSignal('')
|
const [postMessageText, setPostMessageText] = createSignal('')
|
||||||
const [loading, setLoading] = createSignal<boolean>(false)
|
const [loading, setLoading] = createSignal<boolean>(false)
|
||||||
|
@ -116,6 +108,13 @@ export const InboxView = () => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await loadChats()
|
||||||
|
setChats(response as unknown as Chat[])
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
|
@ -129,18 +128,19 @@ export const InboxView = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let formParent // autoresize ghost element
|
let textareaParent // textarea autoresize ghost element
|
||||||
const handleChangeMessage = (event) => {
|
const handleChangeMessage = (event) => {
|
||||||
setPostMessageText(event.target.value)
|
setPostMessageText(event.target.value)
|
||||||
}
|
}
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
formParent.dataset.replicatedValue = postMessageText()
|
textareaParent.dataset.replicatedValue = postMessageText()
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleOpenInviteModal = (event: Event) => {
|
const handleOpenInviteModal = (event: Event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
showModal('inviteToChat')
|
showModal('inviteToChat')
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="messages container">
|
<div class="messages container">
|
||||||
<Modal variant="narrow" name="inviteToChat">
|
<Modal variant="narrow" name="inviteToChat">
|
||||||
|
@ -160,14 +160,14 @@ export const InboxView = () => {
|
||||||
<li>
|
<li>
|
||||||
<strong>{t('All')}</strong>
|
<strong>{t('All')}</strong>
|
||||||
</li>
|
</li>
|
||||||
<li onClick={handleGetChats}>{t('Personal')}</li>
|
<li>{t('Personal')}</li>
|
||||||
<li>{t('Groups')}</li>
|
<li>{t('Groups')}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="holder">
|
<div class="holder">
|
||||||
<div class="dialogs">
|
<div class="dialogs">
|
||||||
<For each={recipients()}>
|
<For each={chats()}>
|
||||||
{(author) => <DialogCard ownSlug={currentSlug()} author={author} online={true} />}
|
{(chat) => <DialogCard users={chat.users} ownSlug={currentSlug()} />}
|
||||||
</For>
|
</For>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -198,7 +198,7 @@ export const InboxView = () => {
|
||||||
|
|
||||||
<div class="message-form">
|
<div class="message-form">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<div class="grow-wrap" ref={formParent}>
|
<div class="grow-wrap" ref={textareaParent}>
|
||||||
<textarea
|
<textarea
|
||||||
value={postMessageText()}
|
value={postMessageText()}
|
||||||
rows={1}
|
rows={1}
|
||||||
|
|
|
@ -272,8 +272,7 @@ export const apiClient = {
|
||||||
// inbox
|
// inbox
|
||||||
getChats: async (options: QueryLoadChatsArgs) => {
|
getChats: async (options: QueryLoadChatsArgs) => {
|
||||||
const resp = await privateGraphQLClient.query(myChats, options).toPromise()
|
const resp = await privateGraphQLClient.query(myChats, options).toPromise()
|
||||||
console.debug('[loadChats]', resp)
|
return resp.data.loadChats.chats
|
||||||
return resp.data.loadChats
|
|
||||||
},
|
},
|
||||||
|
|
||||||
createChat: async (options: MutationCreateChatArgs) => {
|
createChat: async (options: MutationCreateChatArgs) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user