2023-12-19 09:34:24 +00:00
|
|
|
import type { ChatMember } from '../../graphql/schema/chat.gen'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2022-12-17 03:27:00 +00:00
|
|
|
import { clsx } from 'clsx'
|
2024-02-04 11:25:21 +00:00
|
|
|
import { Match, Show, Switch, createMemo } from 'solid-js'
|
2023-11-14 15:10:00 +00:00
|
|
|
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
2023-12-19 09:34:24 +00:00
|
|
|
import { Author } from '../../graphql/schema/core.gen'
|
2023-11-01 08:34:59 +00:00
|
|
|
import { AuthorBadge } from '../Author/AuthorBadge'
|
2022-11-10 15:06:02 +00:00
|
|
|
|
2023-11-14 15:10:00 +00:00
|
|
|
import DialogAvatar from './DialogAvatar'
|
|
|
|
import GroupDialogAvatar from './GroupDialogAvatar'
|
|
|
|
|
|
|
|
import styles from './DialogCard.module.scss'
|
|
|
|
|
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-12-17 03:27:00 +00:00
|
|
|
ownId: number
|
2022-11-27 18:36:45 +00:00
|
|
|
members: ChatMember[]
|
2022-12-17 03:27:00 +00:00
|
|
|
onClick?: () => void
|
|
|
|
isChatHeader?: boolean
|
|
|
|
lastUpdate?: number
|
|
|
|
isOpened?: boolean
|
2022-11-15 09:45:55 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 12:15:07 +00:00
|
|
|
const DialogCard = (props: DialogProps) => {
|
2023-10-18 10:56:41 +00:00
|
|
|
const { t, formatTime } = useLocalize()
|
2024-02-04 09:03:15 +00:00
|
|
|
const companions = createMemo(() =>
|
|
|
|
props.members?.filter((member: ChatMember) => member.id !== props.ownId),
|
2022-12-17 03:27:00 +00:00
|
|
|
)
|
2023-01-26 06:59:43 +00:00
|
|
|
|
2024-01-18 12:52:02 +00:00
|
|
|
const names = createMemo<string>(() => (companions() || []).map((companion) => companion.name).join(', '))
|
2022-12-17 03:27:00 +00:00
|
|
|
|
2022-11-10 15:06:02 +00:00
|
|
|
return (
|
2024-01-25 09:57:57 +00:00
|
|
|
<Show when={props.members.length > 0} fallback={<div>'No chat members'</div>}>
|
2022-12-17 03:27:00 +00:00
|
|
|
<div
|
|
|
|
class={clsx(styles.DialogCard, {
|
|
|
|
[styles.opened]: props.isOpened,
|
2023-11-14 15:10:00 +00:00
|
|
|
[styles.hovered]: !props.isChatHeader,
|
2022-12-17 03:27:00 +00:00
|
|
|
})}
|
|
|
|
onClick={props.onClick}
|
|
|
|
>
|
2023-11-01 08:34:59 +00:00
|
|
|
<Switch
|
|
|
|
fallback={
|
|
|
|
<Show
|
|
|
|
when={props.isChatHeader}
|
|
|
|
fallback={
|
|
|
|
<div class={styles.avatar}>
|
2024-01-25 09:57:57 +00:00
|
|
|
<DialogAvatar name={props.members[0]?.slug} url={props.members[0]?.pic} />
|
2023-11-01 08:34:59 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
2023-12-19 09:34:24 +00:00
|
|
|
<AuthorBadge nameOnly={true} author={props.members[0] as Author} />
|
2023-11-01 08:34:59 +00:00
|
|
|
</Show>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Match when={props.members.length >= 3}>
|
|
|
|
<div class={styles.avatar}>
|
2022-12-17 03:27:00 +00:00
|
|
|
<GroupDialogAvatar users={props.members} />
|
2023-11-01 08:34:59 +00:00
|
|
|
</div>
|
|
|
|
</Match>
|
|
|
|
</Switch>
|
|
|
|
|
2022-12-17 03:27:00 +00:00
|
|
|
<Show when={!props.isChatHeader}>
|
2023-11-01 08:34:59 +00:00
|
|
|
<div class={styles.row}>
|
|
|
|
<div class={styles.name}>
|
|
|
|
{companions()?.length > 1 ? t('Group Chat') : companions()[0]?.name}
|
|
|
|
</div>
|
|
|
|
<div class={styles.message}>
|
|
|
|
<Switch>
|
|
|
|
<Match when={props.message}>
|
|
|
|
<div innerHTML={props.message} />
|
|
|
|
</Match>
|
|
|
|
<Match when={props.isChatHeader && companions().length > 1}>{names()}</Match>
|
|
|
|
</Switch>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-17 03:27:00 +00:00
|
|
|
<div class={styles.activity}>
|
|
|
|
<Show when={props.lastUpdate}>
|
2023-10-18 10:56:41 +00:00
|
|
|
<div class={styles.time}>{formatTime(new Date(props.lastUpdate * 1000))}</div>
|
2022-12-17 03:27:00 +00:00
|
|
|
</Show>
|
|
|
|
<Show when={props.counter > 0}>
|
|
|
|
<div class={styles.counter}>
|
|
|
|
<span>{props.counter}</span>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
</div>
|
|
|
|
</Show>
|
2022-11-10 15:06:02 +00:00
|
|
|
</div>
|
2022-12-02 11:11:45 +00:00
|
|
|
</Show>
|
2022-11-10 15:06:02 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DialogCard
|