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