Merge branch 'prepare-inbox' of github.com:Discours/discoursio-webapp into prepare-inbox

This commit is contained in:
tonyrewin 2022-12-06 11:58:48 +03:00
commit 5caa7bbb3a
6 changed files with 46 additions and 21 deletions

View File

@ -2,6 +2,7 @@ import { Show, Switch, Match, createMemo, For } from 'solid-js'
import DialogAvatar from './DialogAvatar' import DialogAvatar from './DialogAvatar'
import type { ChatMember } from '../../graphql/types.gen' import type { ChatMember } from '../../graphql/types.gen'
import GroupDialogAvatar from './GroupDialogAvatar' import GroupDialogAvatar from './GroupDialogAvatar'
import formattedTime from '../../utils/formatDateTime'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import styles from './DialogCard.module.scss' import styles from './DialogCard.module.scss'
@ -14,6 +15,7 @@ type DialogProps = {
members: ChatMember[] members: ChatMember[]
onClick?: () => void onClick?: () => void
isChatHeader?: boolean isChatHeader?: boolean
lastUpdate?: number
} }
const DialogCard = (props: DialogProps) => { const DialogCard = (props: DialogProps) => {
@ -37,17 +39,22 @@ const DialogCard = (props: DialogProps) => {
<div class={styles.row}> <div class={styles.row}>
<div class={styles.name}>{props.title}</div> <div class={styles.name}>{props.title}</div>
<div class={styles.message}> <div class={styles.message}>
<Switch fallback={'Chat last message'}> <Switch>
<Match when={props.message && !props.isChatHeader}>{props.message}</Match>
<Match when={props.isChatHeader && companions().length > 1}>{names}</Match> <Match when={props.isChatHeader && companions().length > 1}>{names}</Match>
</Switch> </Switch>
</div> </div>
</div> </div>
<Show when={!props.isChatHeader}> <Show when={!props.isChatHeader}>
<div class={styles.activity}> <div class={styles.activity}>
<div class={styles.time}>22:22</div> <Show when={props.lastUpdate}>
<div class={styles.counter}> <div class={styles.time}>{formattedTime(props.lastUpdate)}</div>
<span>12</span> </Show>
</div> <Show when={props.counter > 0}>
<div class={styles.counter}>
<span>{props.counter}</span>
</div>
</Show>
</div> </div>
</Show> </Show>
</div> </div>

View File

@ -11,10 +11,12 @@
padding: 12px 16px; padding: 12px 16px;
position: relative; position: relative;
display: flex; display: flex;
margin-right: auto;
p { p {
margin: 0; margin: 0;
} }
a { a {
color: inherit; color: inherit;
text-decoration: underline; text-decoration: underline;
@ -48,6 +50,7 @@
.body { .body {
justify-content: flex-end; justify-content: flex-end;
margin-left: auto; margin-left: auto;
margin-right: unset;
background: #000; background: #000;
color: #fff; color: #fff;
} }

View File

@ -1,10 +1,10 @@
import { createMemo, Show } from 'solid-js' import { Show } from 'solid-js'
import MarkdownIt from 'markdown-it' import MarkdownIt from 'markdown-it'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import styles from './Message.module.scss' import styles from './Message.module.scss'
import DialogAvatar from './DialogAvatar' import DialogAvatar from './DialogAvatar'
import { locale } from '../../stores/ui'
import type { Message, ChatMember } from '../../graphql/types.gen' import type { Message, ChatMember } from '../../graphql/types.gen'
import formattedTime from '../../utils/formatDateTime'
type Props = { type Props = {
content: Message content: Message
@ -17,28 +17,21 @@ const md = new MarkdownIt({
}) })
const Message = (props: Props) => { const Message = (props: Props) => {
const formattedTime = createMemo<string>(() => {
return new Date(props.content.createdAt * 1000).toLocaleTimeString(locale(), {
hour: 'numeric',
minute: 'numeric'
})
})
// возвращать ID автора // возвращать ID автора
const isOwn = props.ownId === Number(props.content.author) const isOwn = props.ownId === Number(props.content.author)
const user = props.members.find((m) => m.id === Number(props.content.author))
return ( return (
<div class={clsx(styles.Message, isOwn && styles.own)}> <div class={clsx(styles.Message, isOwn && styles.own)}>
<Show when={!isOwn}> <Show when={!isOwn}>
<div class={styles.author}> <div class={styles.author}>
<DialogAvatar size="small" name={'Message Author'} /> <DialogAvatar size="small" name={user.name} url={user.userpic} />
<div class={styles.name}>Message Author</div> <div class={styles.name}>{user.name}</div>
</div> </div>
</Show> </Show>
<div class={styles.body}> <div class={styles.body}>
<div innerHTML={md.render(props.content.body)} /> <div innerHTML={md.render(props.content.body)} />
</div> </div>
<div class={styles.time}>{formattedTime()}</div> <div class={styles.time}>{formattedTime(props.content.createdAt)}</div>
</div> </div>
) )
} }

View File

@ -106,12 +106,16 @@ export const InboxView = () => {
} }
const chatsToShow = () => { const chatsToShow = () => {
const sorted = chats().sort((a, b) => {
return a.updatedAt - b.updatedAt
})
console.log('!!! sorted:', sorted)
if (sortByPerToPer()) { if (sortByPerToPer()) {
return chats().filter((chat) => chat.title.trim().length === 0) return sorted.filter((chat) => chat.title.trim().length === 0)
} else if (sortByGroup()) { } else if (sortByGroup()) {
return chats().filter((chat) => chat.title.trim().length > 0) return sorted.filter((chat) => chat.title.trim().length > 0)
} else { } else {
return chats() return sorted
} }
} }
@ -173,6 +177,9 @@ export const InboxView = () => {
title={chat.title || chat.members[0].name} title={chat.title || chat.members[0].name}
members={chat.members} members={chat.members}
ownId={currentUserId()} ownId={currentUserId()}
lastUpdate={chat.updatedAt}
counter={chat.unread}
message={chat.messages.pop()?.body}
/> />
)} )}
</For> </For>

View File

@ -8,6 +8,7 @@ export default gql`
id id
title title
admins admins
users
members { members {
id id
slug slug
@ -17,6 +18,7 @@ export default gql`
unread unread
description description
updatedAt updatedAt
private
messages { messages {
id id
body body

View File

@ -0,0 +1,13 @@
import { createMemo } from 'solid-js'
import { locale } from '../stores/ui'
// unix timestamp in seconds
const formattedTime = (time: number) =>
createMemo<string>(() => {
return new Date(time * 1000).toLocaleTimeString(locale(), {
hour: 'numeric',
minute: 'numeric'
})
})
export default formattedTime