webapp/src/components/Inbox/DialogCard.tsx

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-11-10 15:06:02 +00:00
import './DialogCard.module.scss'
import styles from './DialogCard.module.scss'
import DialogAvatar from './DialogAvatar'
import type { Author } from '../../graphql/types.gen'
2022-11-15 09:45:55 +00:00
import { useAuthStore } from '../../stores/auth'
import { createEffect, createSignal } from 'solid-js'
import { apiClient } from '../../utils/apiClient'
const { session } = useAuthStore()
2022-11-10 15:06:02 +00:00
type Props = {
online?: boolean
message?: string
counter?: number
} & Author
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-10 15:06:02 +00:00
const DialogCard = (props: Props) => {
2022-11-15 09:45:55 +00:00
const [currentUser, setCurrentUser] = createSignal(undefined)
createEffect(() => {
setCurrentUser(session()?.user?.slug)
})
const handleOpenChat = async () => {
try {
const test = await apiClient.createChat({
title: 'test chat',
members: [props.slug, currentUser()]
})
console.log('!!! test:', test)
} catch (err) {
console.log('!!! errr:', err)
}
}
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}>
<DialogAvatar name={props.name} url={props.userpic} online={props.online} />
</div>
2022-11-10 15:58:43 +00:00
<div class={styles.row}>
2022-11-10 15:06:02 +00:00
<div class={styles.name}>{props.name}</div>
<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