Merge branch 'prepare-inbox' of github.com:Discours/discoursio-webapp into prepare-inbox
This commit is contained in:
commit
fe4f55ad11
|
@ -46,8 +46,8 @@ export const AuthorCard = (props: AuthorCardProps) => {
|
|||
}
|
||||
// TODO: reimplement AuthorCard
|
||||
const { changeSearchParam } = useRouter()
|
||||
const handleInitChat = () => {
|
||||
openPage(router, 'inbox')
|
||||
const initChat = () => {
|
||||
openPage(router, `inbox`)
|
||||
changeSearchParam('openChat', `${props.author.id}`)
|
||||
}
|
||||
return (
|
||||
|
@ -134,7 +134,7 @@ export const AuthorCard = (props: AuthorCardProps) => {
|
|||
'button--subscribe-topic': props.isAuthorsList,
|
||||
[styles.buttonWrite]: props.liteButtons && props.isAuthorsList
|
||||
}}
|
||||
onClick={handleInitChat}
|
||||
onClick={initChat}
|
||||
>
|
||||
<Icon name="comment" class={styles.icon} />
|
||||
<Show when={!props.liteButtons}>{t('Write')}</Show>
|
||||
|
|
|
@ -59,7 +59,7 @@ export const Editor = () => {
|
|||
const handleSaveButtonClick = () => {
|
||||
const article: ShoutInput = {
|
||||
body: getHtml(editorViewRef.current.state),
|
||||
community: 'discours', // ?
|
||||
// community: 'discours', // ? Type 'string' is not assignable to type 'number'.
|
||||
slug: 'new-' + Math.floor(Math.random() * 1000000)
|
||||
}
|
||||
createArticle({ article })
|
||||
|
|
|
@ -22,9 +22,11 @@ const DialogCard = (props: DialogProps) => {
|
|||
const companions = createMemo(
|
||||
() => props.members && props.members.filter((member) => member.id !== props.ownId)
|
||||
)
|
||||
const names = companions()
|
||||
?.map((companion) => companion.name)
|
||||
.join(', ')
|
||||
const names = createMemo(() =>
|
||||
companions()
|
||||
?.map((companion) => companion.name)
|
||||
.join(', ')
|
||||
)
|
||||
|
||||
return (
|
||||
<Show when={props.members}>
|
||||
|
@ -37,11 +39,15 @@ const DialogCard = (props: DialogProps) => {
|
|||
</Switch>
|
||||
</div>
|
||||
<div class={styles.row}>
|
||||
<div class={styles.name}>{props.title}</div>
|
||||
<div class={styles.name}>
|
||||
<Switch fallback={names()}>
|
||||
<Match when={companions().length > 1}>{props.title}</Match>
|
||||
</Switch>
|
||||
</div>
|
||||
<div class={styles.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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,6 @@ type DialogHeader = {
|
|||
chat: Chat
|
||||
ownId: number
|
||||
}
|
||||
|
||||
const DialogHeader = (props: DialogHeader) => {
|
||||
return (
|
||||
<header class={styles.DialogHeader}>
|
||||
|
|
|
@ -19,7 +19,7 @@ const md = new MarkdownIt({
|
|||
const Message = (props: Props) => {
|
||||
// возвращать ID автора
|
||||
const isOwn = props.ownId === Number(props.content.author)
|
||||
const user = props.members.find((m) => m.id === Number(props.content.author))
|
||||
const user = props.members?.find((m) => m.id === Number(props.content.author))
|
||||
return (
|
||||
<div class={clsx(styles.Message, isOwn && styles.own)}>
|
||||
<Show when={!isOwn}>
|
||||
|
|
|
@ -16,6 +16,8 @@ import { useInbox } from '../../context/inbox'
|
|||
import DialogHeader from '../Inbox/DialogHeader'
|
||||
import { apiClient } from '../../utils/apiClient'
|
||||
import MessagesFallback from '../Inbox/MessagesFallback'
|
||||
import { useRouter } from '../../stores/router'
|
||||
import createChat from '../../graphql/mutation/create-chat'
|
||||
|
||||
const userSearch = (array: Author[], keyword: string) => {
|
||||
const searchTerm = keyword.toLowerCase()
|
||||
|
@ -93,9 +95,26 @@ export const InboxView = () => {
|
|||
const handleChangeMessage = (event) => {
|
||||
setPostMessageText(event.target.value)
|
||||
}
|
||||
createEffect(() => {
|
||||
if (!textareaParent) return
|
||||
textareaParent.dataset.replicatedValue = postMessageText()
|
||||
|
||||
const { actions } = useInbox()
|
||||
const urlParams = new URLSearchParams(window.location.search)
|
||||
const params = Object.fromEntries(urlParams)
|
||||
console.log('!!! params:', params)
|
||||
|
||||
createEffect(async () => {
|
||||
if (textareaParent) {
|
||||
textareaParent.dataset.replicatedValue = postMessageText()
|
||||
}
|
||||
if (params['openChat']) {
|
||||
try {
|
||||
const newChat = await actions.createChat([Number(params['chat'])], '')
|
||||
console.log('!!! newChat:', newChat)
|
||||
await handleOpenChat(newChat.chat)
|
||||
await loadChats()
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const handleOpenInviteModal = () => {
|
||||
|
@ -106,7 +125,6 @@ export const InboxView = () => {
|
|||
const sorted = chats().sort((a, b) => {
|
||||
return a.updatedAt - b.updatedAt
|
||||
})
|
||||
console.log('!!! sorted:', sorted)
|
||||
if (sortByPerToPer()) {
|
||||
return sorted.filter((chat) => chat.title.trim().length === 0)
|
||||
} else if (sortByGroup()) {
|
||||
|
@ -116,10 +134,6 @@ export const InboxView = () => {
|
|||
}
|
||||
}
|
||||
|
||||
createEffect(() => {
|
||||
console.log('!!! currentDialog():', currentDialog())
|
||||
})
|
||||
|
||||
return (
|
||||
<div class="messages container">
|
||||
<Modal variant="narrow" name="inviteToChat">
|
||||
|
@ -171,7 +185,7 @@ export const InboxView = () => {
|
|||
{(chat) => (
|
||||
<DialogCard
|
||||
onClick={() => handleOpenChat(chat)}
|
||||
title={chat.title || chat.members[0].name}
|
||||
title={chat.title}
|
||||
members={chat.members}
|
||||
ownId={currentUserId()}
|
||||
lastUpdate={chat.updatedAt}
|
||||
|
|
|
@ -8,7 +8,7 @@ import newMessages from '../graphql/subs/new-messages'
|
|||
type InboxContextType = {
|
||||
chats: Accessor<Chat[]>
|
||||
actions: {
|
||||
createChat: (members: number[], title: string) => Promise<void>
|
||||
createChat: (members: number[], title: string) => Promise<{ chat: Chat }>
|
||||
loadChats: () => Promise<void>
|
||||
setListener: (listener: (ev) => void) => void
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ const getSession = async (): Promise<AuthResult> => {
|
|||
if (!authResult) {
|
||||
return null
|
||||
}
|
||||
console.log('!!! authResult:', authResult)
|
||||
setToken(authResult.token)
|
||||
return authResult
|
||||
} catch (error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user