webapp/src/components/Inbox/DialogCard.tsx

57 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-11-10 15:06:02 +00:00
import styles from './DialogCard.module.scss'
import DialogAvatar from './DialogAvatar'
2022-11-15 14:24:50 +00:00
import type { Author, AuthResult } from '../../graphql/types.gen'
import { useSession } from '../../context/session'
2022-11-15 15:27:02 +00:00
import { createMemo } from 'solid-js'
2022-11-15 09:45:55 +00:00
import { apiClient } from '../../utils/apiClient'
2022-11-10 15:06:02 +00:00
2022-11-15 12:15:07 +00:00
type DialogProps = {
2022-11-10 15:06:02 +00:00
online?: boolean
message?: string
counter?: number
2022-11-14 17:09:51 +00:00
author?: Author
}
2022-11-10 15:06:02 +00:00
2022-11-15 09:45:55 +00:00
const createChat = async ({ title, members }: { title?: string; members?: string[] }): Promise<void> => {
await apiClient.createChat({ title, members })
}
2022-11-15 12:15:07 +00:00
const DialogCard = (props: DialogProps) => {
2022-11-15 14:24:50 +00:00
const { session } = useSession()
const currentSession = createMemo<AuthResult>(() => session)
2022-11-15 09:45:55 +00:00
const handleOpenChat = async () => {
try {
2022-11-15 13:55:00 +00:00
const initChat = await apiClient.createChat({
2022-11-15 09:45:55 +00:00
title: 'test chat',
2022-11-15 14:24:50 +00:00
members: [props.author.slug, currentSession().user.slug]
2022-11-15 09:45:55 +00:00
})
2022-11-15 15:27:02 +00:00
// console.log('!!! test:', test)
2022-11-15 14:24:50 +00:00
} catch (error) {
console.log('!!! errr:', error)
2022-11-15 09:45:55 +00:00
}
}
2022-11-10 15:06:02 +00:00
return (
2022-11-15 09:45:55 +00:00
<div class={styles.DialogCard} onClick={handleOpenChat}>
2022-11-10 15:06:02 +00:00
<div class={styles.avatar}>
2022-11-14 17:09:51 +00:00
<DialogAvatar name={props.author.name} url={props.author.userpic} online={props.online} />
2022-11-10 15:06:02 +00:00
</div>
2022-11-10 15:58:43 +00:00
<div class={styles.row}>
2022-11-14 17:09:51 +00:00
<div class={styles.name}>{props.author.name}</div>
2022-11-10 15:06:02 +00:00
<div class={styles.message}>
Указать предпочтительные языки для результатов поиска можно в разделе
</div>
</div>
<div class={styles.activity}>
<div class={styles.time}>22:22</div>
<div class={styles.counter}>
<span>12</span>
</div>
</div>
</div>
)
}
export default DialogCard