2022-12-01 06:00:51 +00:00
|
|
|
import { Show, Switch, Match, createMemo, For } from 'solid-js'
|
2022-11-10 15:06:02 +00:00
|
|
|
import DialogAvatar from './DialogAvatar'
|
2022-11-29 07:04:38 +00:00
|
|
|
import type { ChatMember } from '../../graphql/types.gen'
|
2022-11-29 05:36:32 +00:00
|
|
|
import GroupDialogAvatar from './GroupDialogAvatar'
|
2022-12-01 06:00:51 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import styles from './DialogCard.module.scss'
|
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-28 04:10:13 +00:00
|
|
|
title?: string
|
2022-11-27 11:45:36 +00:00
|
|
|
ownSlug: string
|
2022-11-27 18:08:11 +00:00
|
|
|
members: ChatMember[]
|
2022-12-01 06:00:51 +00:00
|
|
|
onClick?: () => void
|
|
|
|
isChatHeader?: boolean
|
2022-11-15 09:45:55 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 12:15:07 +00:00
|
|
|
const DialogCard = (props: DialogProps) => {
|
2022-12-01 06:00:51 +00:00
|
|
|
const companions = createMemo(
|
|
|
|
() => props.members && props.members.filter((member) => member.slug !== props.ownSlug)
|
|
|
|
)
|
|
|
|
const names = createMemo(() =>
|
|
|
|
companions()
|
|
|
|
.map((companion) => companion.name)
|
|
|
|
.join(', ')
|
|
|
|
)
|
2022-11-10 15:06:02 +00:00
|
|
|
return (
|
2022-12-01 03:26:44 +00:00
|
|
|
<Show when={props.members}>
|
2022-12-01 06:00:51 +00:00
|
|
|
<div class={clsx(styles.DialogCard, { [styles.header]: props.isChatHeader })} onClick={props.onClick}>
|
2022-12-01 03:26:44 +00:00
|
|
|
<div class={styles.avatar}>
|
2022-12-01 06:00:51 +00:00
|
|
|
<Switch fallback={<DialogAvatar name={props.members[0].name} url={props.members[0].userpic} />}>
|
|
|
|
<Match when={companions().length > 2}>
|
|
|
|
<GroupDialogAvatar users={companions()} />
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
2022-11-10 15:06:02 +00:00
|
|
|
</div>
|
2022-12-01 03:26:44 +00:00
|
|
|
<div class={styles.row}>
|
2022-12-01 06:00:51 +00:00
|
|
|
<Switch fallback={<div class={styles.name}>{companions()[0].name}</div>}>
|
|
|
|
<Match when={companions().length > 1}>
|
|
|
|
<div class={styles.name}>{props.title}</div>
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
2022-12-01 03:26:44 +00:00
|
|
|
<div class={styles.message}>
|
2022-12-01 06:00:51 +00:00
|
|
|
<Switch fallback={'Chat last message'}>
|
|
|
|
<Match when={props.isChatHeader && companions().length > 1}>{names}</Match>
|
|
|
|
</Switch>
|
2022-12-01 03:26:44 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-01 06:00:51 +00:00
|
|
|
<Show when={!props.isChatHeader}>
|
|
|
|
<div class={styles.activity}>
|
|
|
|
<div class={styles.time}>22:22</div>
|
|
|
|
<div class={styles.counter}>
|
|
|
|
<span>12</span>
|
|
|
|
</div>
|
2022-12-01 03:26:44 +00:00
|
|
|
</div>
|
2022-12-01 06:00:51 +00:00
|
|
|
</Show>
|
2022-11-10 15:06:02 +00:00
|
|
|
</div>
|
2022-12-01 03:26:44 +00:00
|
|
|
</Show>
|
2022-11-10 15:06:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DialogCard
|