fix Reply view
This commit is contained in:
parent
1badb74f6f
commit
4d57d63d11
|
@ -12,6 +12,7 @@ $actionsWidth: 32px * 2;
|
||||||
|
|
||||||
.text {
|
.text {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
flex-direction: column;
|
||||||
max-width: 60%;
|
max-width: 60%;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
background: #f6f6f6;
|
background: #f6f6f6;
|
||||||
|
|
|
@ -55,7 +55,7 @@ const Message = (props: Props) => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Show when={props.replyBody}>
|
<Show when={props.replyBody}>
|
||||||
<QuotedMessage body={props.replyBody} variant="inline" />
|
<QuotedMessage body={props.replyBody} variant="inline" isOwn={isOwn} />
|
||||||
</Show>
|
</Show>
|
||||||
<div innerHTML={md.render(props.content.body)} />
|
<div innerHTML={md.render(props.content.body)} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,18 +2,33 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-top: 2px solid #ccc;
|
|
||||||
padding: 12px 0;
|
|
||||||
gap: 12px;
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
|
||||||
.icon {
|
&.inline {
|
||||||
width: 40px;
|
color: #696969;
|
||||||
height: 40px;
|
border-left: 2px solid #404040;
|
||||||
flex-basis: 40px;
|
padding-left: 12px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
|
||||||
&.cancel {
|
&.own {
|
||||||
cursor: pointer;
|
color: #9fa1a7;
|
||||||
|
border-color: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&.reply {
|
||||||
|
border-top: 2px solid #ccc;
|
||||||
|
padding: 12px 0;
|
||||||
|
gap: 12px;
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
flex-basis: 40px;
|
||||||
|
|
||||||
|
&.cancel {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,21 +8,30 @@ type QuotedMessage = {
|
||||||
cancel?: () => void
|
cancel?: () => void
|
||||||
author?: string
|
author?: string
|
||||||
variant: 'inline' | 'reply'
|
variant: 'inline' | 'reply'
|
||||||
|
isOwn?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const QuotedMessage = (props: QuotedMessage) => {
|
const QuotedMessage = (props: QuotedMessage) => {
|
||||||
return (
|
return (
|
||||||
<div class={styles.QuotedMessage}>
|
<div
|
||||||
<div class={styles.icon}>
|
class={clsx(styles.QuotedMessage, {
|
||||||
<Icon name="chat-reply" />
|
[styles.reply]: props.variant === 'reply',
|
||||||
</div>
|
[styles.inline]: props.variant === 'inline',
|
||||||
|
[styles.own]: props.isOwn
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Show when={props.variant === 'reply'}>
|
||||||
|
<div class={styles.icon}>
|
||||||
|
<Icon name="chat-reply" />
|
||||||
|
</div>
|
||||||
|
</Show>
|
||||||
<div class={styles.body}>
|
<div class={styles.body}>
|
||||||
<Show when={props.author}>
|
<Show when={props.author}>
|
||||||
<div class={styles.author}>{props.author}</div>
|
<div class={styles.author}>{props.author}</div>
|
||||||
</Show>
|
</Show>
|
||||||
<div class={styles.quote}>{props.body}</div>
|
<div class={styles.quote}>{props.body}</div>
|
||||||
</div>
|
</div>
|
||||||
<Show when={props.cancel && props.variant !== 'inline'}>
|
<Show when={props.cancel && props.variant === 'reply'}>
|
||||||
<div class={clsx(styles.cancel, styles.icon)} onClick={props.cancel}>
|
<div class={clsx(styles.cancel, styles.icon)} onClick={props.cancel}>
|
||||||
<Icon name="close-gray" />
|
<Icon name="close-gray" />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,9 +29,11 @@ const { changeSearchParam } = useRouter()
|
||||||
export const InboxView = () => {
|
export const InboxView = () => {
|
||||||
const {
|
const {
|
||||||
chats,
|
chats,
|
||||||
actions: { loadChats } // setListener
|
messages,
|
||||||
|
actions: { loadChats, getMessages } // setListener
|
||||||
} = useInbox()
|
} = useInbox()
|
||||||
const [messages, setMessages] = createSignal<MessageType[]>([])
|
|
||||||
|
// const [messages, setMessages] = createSignal<MessageType[]>([])
|
||||||
const [recipients, setRecipients] = createSignal<Author[]>([])
|
const [recipients, setRecipients] = createSignal<Author[]>([])
|
||||||
const [postMessageText, setPostMessageText] = createSignal('')
|
const [postMessageText, setPostMessageText] = createSignal('')
|
||||||
const [sortByGroup, setSortByGroup] = createSignal<boolean>(false)
|
const [sortByGroup, setSortByGroup] = createSignal<boolean>(false)
|
||||||
|
@ -56,15 +58,26 @@ export const InboxView = () => {
|
||||||
setCurrentDialog(chat)
|
setCurrentDialog(chat)
|
||||||
changeSearchParam('chat', `${chat.id}`)
|
changeSearchParam('chat', `${chat.id}`)
|
||||||
try {
|
try {
|
||||||
const response = await loadMessages({ chat: chat.id })
|
await getMessages(chat.id)
|
||||||
setMessages(response as unknown as MessageType[])
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[loadMessages]', error)
|
console.error('[getMessages]', error)
|
||||||
} finally {
|
} finally {
|
||||||
chatWindow.scrollTop = chatWindow.scrollHeight
|
chatWindow.scrollTop = chatWindow.scrollHeight
|
||||||
}
|
}
|
||||||
|
// try {
|
||||||
|
// const response = await loadMessages({ chat: chat.id })
|
||||||
|
// setMessages(response as unknown as MessageType[])
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('[loadMessages]', error)
|
||||||
|
// } finally {
|
||||||
|
// chatWindow.scrollTop = chatWindow.scrollHeight
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createEffect(() => {
|
||||||
|
console.log('!!! messages:', messages())
|
||||||
|
})
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await loadRecipients({ days: 365 })
|
const response = await loadRecipients({ days: 365 })
|
||||||
|
@ -77,12 +90,13 @@ export const InboxView = () => {
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
|
console.log('!!! post:')
|
||||||
const post = await apiClient.createMessage({
|
const post = await apiClient.createMessage({
|
||||||
body: postMessageText().toString(),
|
body: postMessageText().toString(),
|
||||||
chat: currentDialog().id.toString(),
|
chat: currentDialog().id.toString(),
|
||||||
replyTo: messageToReply()?.id
|
replyTo: messageToReply()?.id
|
||||||
})
|
})
|
||||||
setMessages((prev) => [...prev, post.message])
|
// setMessages((prev) => [...prev, post.message])
|
||||||
setPostMessageText('')
|
setPostMessageText('')
|
||||||
setMessageToReply(null)
|
setMessageToReply(null)
|
||||||
chatWindow.scrollTop = chatWindow.scrollHeight
|
chatWindow.scrollTop = chatWindow.scrollHeight
|
||||||
|
|
|
@ -6,12 +6,15 @@ import { apiClient } from '../utils/apiClient'
|
||||||
import newMessage from '../graphql/subs/new-message'
|
import newMessage from '../graphql/subs/new-message'
|
||||||
import type { Client } from '@urql/core'
|
import type { Client } from '@urql/core'
|
||||||
import { pipe, subscribe } from 'wonka'
|
import { pipe, subscribe } from 'wonka'
|
||||||
|
import { loadMessages } from '../stores/inbox'
|
||||||
|
|
||||||
type InboxContextType = {
|
type InboxContextType = {
|
||||||
chats: Accessor<Chat[]>
|
chats: Accessor<Chat[]>
|
||||||
|
messages?: Accessor<Message[]>
|
||||||
actions: {
|
actions: {
|
||||||
createChat: (members: number[], title: string) => Promise<{ chat: Chat }>
|
createChat: (members: number[], title: string) => Promise<{ chat: Chat }>
|
||||||
loadChats: () => Promise<void>
|
loadChats: () => Promise<void>
|
||||||
|
getMessages?: (chatId: string) => Promise<void>
|
||||||
unsubscribe: () => void
|
unsubscribe: () => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +27,7 @@ export function useInbox() {
|
||||||
|
|
||||||
export const InboxProvider = (props: { children: JSX.Element }) => {
|
export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
const [chats, setChats] = createSignal<Chat[]>([])
|
const [chats, setChats] = createSignal<Chat[]>([])
|
||||||
|
const [messages, setMessages] = createSignal<Message[]>([])
|
||||||
const subclient = createMemo<Client>(() => createChatClient())
|
const subclient = createMemo<Client>(() => createChatClient())
|
||||||
const loadChats = async () => {
|
const loadChats = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -38,6 +42,15 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getMessages = async (chatId: string) => {
|
||||||
|
try {
|
||||||
|
const response = await loadMessages({ chat: chatId })
|
||||||
|
setMessages(response as unknown as Message[])
|
||||||
|
} catch (error) {
|
||||||
|
console.log('[loadMessages]', error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createChat = async (members: number[], title: string) => {
|
const createChat = async (members: number[], title: string) => {
|
||||||
const chat = await apiClient.createChat({ members, title })
|
const chat = await apiClient.createChat({ members, title })
|
||||||
setChats((prevChats) => {
|
setChats((prevChats) => {
|
||||||
|
@ -57,9 +70,10 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
const actions = {
|
const actions = {
|
||||||
createChat,
|
createChat,
|
||||||
loadChats,
|
loadChats,
|
||||||
|
getMessages,
|
||||||
unsubscribe // TODO: call unsubscribe some time!
|
unsubscribe // TODO: call unsubscribe some time!
|
||||||
}
|
}
|
||||||
|
|
||||||
const value: InboxContextType = { chats, actions }
|
const value: InboxContextType = { chats, messages, actions }
|
||||||
return <InboxContext.Provider value={value}>{props.children}</InboxContext.Provider>
|
return <InboxContext.Provider value={value}>{props.children}</InboxContext.Provider>
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,9 +55,9 @@ export type AuthorsBy = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Chat = {
|
export type Chat = {
|
||||||
admins?: Maybe<Array<Maybe<Scalars['String']>>>
|
admins?: Maybe<Array<Maybe<Scalars['Int']>>>
|
||||||
createdAt: Scalars['Int']
|
createdAt: Scalars['Int']
|
||||||
createdBy: Scalars['String']
|
createdBy: Scalars['Int']
|
||||||
description?: Maybe<Scalars['String']>
|
description?: Maybe<Scalars['String']>
|
||||||
id: Scalars['String']
|
id: Scalars['String']
|
||||||
members?: Maybe<Array<Maybe<ChatMember>>>
|
members?: Maybe<Array<Maybe<ChatMember>>>
|
||||||
|
@ -66,7 +66,7 @@ export type Chat = {
|
||||||
title?: Maybe<Scalars['String']>
|
title?: Maybe<Scalars['String']>
|
||||||
unread?: Maybe<Scalars['Int']>
|
unread?: Maybe<Scalars['Int']>
|
||||||
updatedAt: Scalars['Int']
|
updatedAt: Scalars['Int']
|
||||||
users?: Maybe<Array<Maybe<Scalars['String']>>>
|
users?: Maybe<Array<Maybe<Scalars['Int']>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChatInput = {
|
export type ChatInput = {
|
||||||
|
@ -79,6 +79,7 @@ export type ChatMember = {
|
||||||
id: Scalars['Int']
|
id: Scalars['Int']
|
||||||
lastSeen?: Maybe<Scalars['DateTime']>
|
lastSeen?: Maybe<Scalars['DateTime']>
|
||||||
name: Scalars['String']
|
name: Scalars['String']
|
||||||
|
online?: Maybe<Scalars['Boolean']>
|
||||||
slug: Scalars['String']
|
slug: Scalars['String']
|
||||||
userpic?: Maybe<Scalars['String']>
|
userpic?: Maybe<Scalars['String']>
|
||||||
}
|
}
|
||||||
|
@ -140,12 +141,13 @@ export type LoadShoutsOptions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Message = {
|
export type Message = {
|
||||||
author: Scalars['String']
|
author: Scalars['Int']
|
||||||
body: Scalars['String']
|
body: Scalars['String']
|
||||||
chatId: Scalars['String']
|
chatId: Scalars['String']
|
||||||
createdAt: Scalars['Int']
|
createdAt: Scalars['Int']
|
||||||
id: Scalars['Int']
|
id: Scalars['Int']
|
||||||
replyTo?: Maybe<Scalars['String']>
|
replyTo?: Maybe<Scalars['Int']>
|
||||||
|
seen?: Maybe<Scalars['Boolean']>
|
||||||
updatedAt?: Maybe<Scalars['Int']>
|
updatedAt?: Maybe<Scalars['Int']>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,6 +356,7 @@ export type Query = {
|
||||||
loadShout?: Maybe<Shout>
|
loadShout?: Maybe<Shout>
|
||||||
loadShouts: Array<Maybe<Shout>>
|
loadShouts: Array<Maybe<Shout>>
|
||||||
markdownBody: Scalars['String']
|
markdownBody: Scalars['String']
|
||||||
|
searchMessages: Result
|
||||||
searchRecipients: Result
|
searchRecipients: Result
|
||||||
signIn: AuthResult
|
signIn: AuthResult
|
||||||
signOut: AuthResult
|
signOut: AuthResult
|
||||||
|
@ -418,6 +421,12 @@ export type QueryMarkdownBodyArgs = {
|
||||||
body: Scalars['String']
|
body: Scalars['String']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type QuerySearchMessagesArgs = {
|
||||||
|
by: MessagesBy
|
||||||
|
limit?: InputMaybe<Scalars['Int']>
|
||||||
|
offset?: InputMaybe<Scalars['Int']>
|
||||||
|
}
|
||||||
|
|
||||||
export type QuerySearchRecipientsArgs = {
|
export type QuerySearchRecipientsArgs = {
|
||||||
limit?: InputMaybe<Scalars['Int']>
|
limit?: InputMaybe<Scalars['Int']>
|
||||||
offset?: InputMaybe<Scalars['Int']>
|
offset?: InputMaybe<Scalars['Int']>
|
||||||
|
@ -621,19 +630,12 @@ export type Stat = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Subscription = {
|
export type Subscription = {
|
||||||
newMessage: Message
|
collabUpdate?: Maybe<Reaction>
|
||||||
onlineUpdated: Array<User>
|
newMessage?: Maybe<Message>
|
||||||
reactionUpdated: ReactionUpdating
|
|
||||||
shoutUpdated: Shout
|
|
||||||
userUpdated: User
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SubscriptionNewMessageArgs = {
|
export type SubscriptionCollabUpdateArgs = {
|
||||||
chats?: InputMaybe<Array<Scalars['Int']>>
|
collab: Scalars['Int']
|
||||||
}
|
|
||||||
|
|
||||||
export type SubscriptionReactionUpdatedArgs = {
|
|
||||||
shout: Scalars['String']
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Token = {
|
export type Token = {
|
||||||
|
@ -670,6 +672,7 @@ export type TopicStat = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
|
about?: Maybe<Scalars['String']>
|
||||||
bio?: Maybe<Scalars['String']>
|
bio?: Maybe<Scalars['String']>
|
||||||
communities?: Maybe<Array<Maybe<Scalars['Int']>>>
|
communities?: Maybe<Array<Maybe<Scalars['Int']>>>
|
||||||
createdAt: Scalars['DateTime']
|
createdAt: Scalars['DateTime']
|
||||||
|
|
Loading…
Reference in New Issue
Block a user