Resolve Conversation

This commit is contained in:
ilya-bkv 2022-11-24 09:52:31 +03:00
parent 271e67f305
commit 6a94474732
12 changed files with 55 additions and 70 deletions

View File

@ -18,7 +18,7 @@
border-radius: 50%; border-radius: 50%;
border: 3px solid #fff; border: 3px solid #fff;
} }
> .imageHolder { .imageHolder {
background-size: cover; background-size: cover;
width: 100%; width: 100%;
height: 100%; height: 100%;
@ -26,12 +26,12 @@
border-radius: 100%; border-radius: 100%;
} }
> .letter { .letter {
display: block; display: block;
border-radius: 100%; border-radius: 100%;
} }
> .letter { .letter {
margin-bottom: -2px; margin-bottom: -2px;
font-weight: 500; font-weight: 500;
font-size: 18px; font-size: 18px;
@ -43,7 +43,7 @@
width: 24px; width: 24px;
height: 24px; height: 24px;
> .letter { .letter {
font-size: 14px; font-size: 14px;
} }
} }

View File

@ -36,7 +36,10 @@ const DialogAvatar = (props: Props) => {
return ( return (
<div <div
class={clsx(styles.DialogAvatar, props.online && styles.online, `${styles[props.size]}`)} class={clsx(styles.DialogAvatar, {
[styles.online]: props.online,
[styles.small]: props.size === 'small'
})}
style={{ 'background-color': `${randomBg()}` }} style={{ 'background-color': `${randomBg()}` }}
> >
<Show when={props.url} fallback={() => <div class={styles.letter}>{nameFirstLetter}</div>}> <Show when={props.url} fallback={() => <div class={styles.letter}>{nameFirstLetter}</div>}>

View File

@ -62,7 +62,7 @@
height: 22px; height: 22px;
line-height: 6px; line-height: 6px;
> span { span {
margin-bottom: -2px; margin-bottom: -2px;
} }
} }

View File

@ -129,7 +129,7 @@ export const Header = (props: Props) => {
containerCssClass={styles.control} containerCssClass={styles.control}
trigger={<Icon name="share-outline" class={styles.icon} />} trigger={<Icon name="share-outline" class={styles.icon} />}
/> />
<a href={'/inbox'} class={styles.control}> <a href={getPagePath(router, 'inbox')} class={styles.control}>
<Icon name="comments-outline" class={styles.icon} /> <Icon name="comments-outline" class={styles.icon} />
</a> </a>
<a href="#" class={styles.control} onClick={(event) => event.preventDefault()}> <a href="#" class={styles.control} onClick={(event) => event.preventDefault()}>

View File

@ -1,8 +1,7 @@
import { PageWrap } from '../_shared/PageWrap' import { PageWrap } from '../_shared/PageWrap'
import { InboxView } from '../Views/Inbox' import { InboxView } from '../Views/Inbox'
import type { PageProps } from '../types'
export const InboxPage = (props: PageProps) => { export const InboxPage = () => {
return ( return (
<PageWrap hideFooter={true}> <PageWrap hideFooter={true}>
<InboxView /> <InboxView />

View File

@ -1,24 +1,19 @@
import { For, createSignal, Show, onMount, createEffect } from 'solid-js' import { For, createSignal, Show, onMount, createEffect } from 'solid-js'
import { PageWrap } from '../_shared/PageWrap' import type { Author } from '../../graphql/types.gen'
import type { Author, Chat } from '../../graphql/types.gen'
import { AuthorCard } from '../Author/Card' import { AuthorCard } from '../Author/Card'
import { Icon } from '../_shared/Icon' import { Icon } from '../_shared/Icon'
import { Loading } from '../Loading' import { Loading } from '../Loading'
import DialogCard from '../Inbox/DialogCard' import DialogCard from '../Inbox/DialogCard'
import Search from '../Inbox/Search' import Search from '../Inbox/Search'
import { loadAllAuthors, useAuthorsStore } from '../../stores/zine/authors'
import MarkdownIt from 'markdown-it'
import { useSession } from '../../context/session' import { useSession } from '../../context/session'
import '../../styles/Inbox.scss' import '../../styles/Inbox.scss'
// Для моков // Для моков
import { createClient } from '@urql/core' import { createClient } from '@urql/core'
import Message from '../Inbox/Message' import Message from '../Inbox/Message'
import { loadAuthorsBy, loadChats, chats, setChats } from '../../stores/inbox' import { loadAuthorsBy, loadChats } from '../../stores/inbox'
import { t } from '../../utils/intl'
const md = new MarkdownIt({
linkify: true
})
const OWNER_ID = '501' const OWNER_ID = '501'
const client = createClient({ const client = createClient({
url: 'https://graphqlzero.almansi.me/api' url: 'https://graphqlzero.almansi.me/api'
@ -63,7 +58,7 @@ const postMessage = async (msg: string) => {
const handleGetChats = async () => { const handleGetChats = async () => {
try { try {
const response = await loadChats() const response = await loadChats()
setChats(response as unknown as Chat[]) console.log('!!! response:', response)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
} }
@ -79,9 +74,7 @@ export const InboxView = () => {
const { session } = useSession() const { session } = useSession()
createEffect(() => { createEffect(() => {
console.log('!!! session():', session())
setCurrentSlug(session()?.user?.slug) setCurrentSlug(session()?.user?.slug)
console.log('!!! chats:', chats())
}) })
// Поиск по диалогам // Поиск по диалогам
@ -90,7 +83,7 @@ export const InboxView = () => {
const match = userSearch(authors(), query()) const match = userSearch(authors(), query())
setAuthors(match) setAuthors(match)
} else { } else {
setAuthors(cashedAuthors) setAuthors(cashedAuthors())
} }
} }
@ -153,10 +146,10 @@ export const InboxView = () => {
<div class="chat-list__types"> <div class="chat-list__types">
<ul> <ul>
<li> <li>
<strong>Все</strong> <strong>{t('All')}</strong>
</li> </li>
<li onClick={handleGetChats}>Переписки</li> <li onClick={handleGetChats}>{t('Conversations')}</li>
<li>Группы</li> <li>{t('Groups')}</li>
</ul> </ul>
</div> </div>
<div class="holder"> <div class="holder">

View File

@ -5,21 +5,23 @@ export default gql`
loadChats(limit: $limit, offset: $offset) { loadChats(limit: $limit, offset: $offset) {
error error
chats { chats {
title id
description
updatedAt
messages { messages {
id id
author
body body
replyTo author
createdAt }
admins {
slug
name
} }
users { users {
slug slug
name name
userpic
} }
unread
description
updatedAt
} }
} }
} }

View File

@ -180,5 +180,8 @@
"view": "просмотр", "view": "просмотр",
"zine": "журнал", "zine": "журнал",
"shout": "пост", "shout": "пост",
"discussion": "дискурс" "discussion": "дискурс",
"Conversations": "Переписки",
"Groups": "Группы",
"All": "Все"
} }

View File

@ -1,9 +1,5 @@
import { createSignal } from 'solid-js'
import type { Chat } from '../graphql/types.gen'
import { apiClient } from '../utils/apiClient' import { apiClient } from '../utils/apiClient'
export const [chats, setChats] = createSignal<Chat[]>([])
export const loadAuthorsBy = async (by?: any): Promise<void> => { export const loadAuthorsBy = async (by?: any): Promise<void> => {
return await apiClient.getAuthorsBy({ by }) return await apiClient.getAuthorsBy({ by })
} }

View File

@ -5,11 +5,6 @@ main {
position: relative; position: relative;
} }
// TODO: добавлять когда открыт чат
body {
//overflow: hidden;
}
.messages { .messages {
top: 74px; top: 74px;
height: calc(100% - 74px); height: calc(100% - 74px);
@ -24,7 +19,7 @@ body {
position: fixed; position: fixed;
z-index: 9; z-index: 9;
> .row { .row {
flex: 1; flex: 1;
} }
@ -171,7 +166,7 @@ body {
background: #fff; background: #fff;
padding: 2px 0 12px 0; padding: 2px 0 12px 0;
> .wrapper { .wrapper {
border: 2px solid #cccccc; border: 2px solid #cccccc;
border-radius: 16px; border-radius: 16px;
padding: 4px; padding: 4px;
@ -179,7 +174,7 @@ body {
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
> .grow-wrap { .grow-wrap {
display: grid; display: grid;
width: 100%; width: 100%;
@ -190,7 +185,7 @@ body {
transition: height 1.3s ease-in-out; transition: height 1.3s ease-in-out;
} }
& > textarea { & textarea {
margin-bottom: 0; margin-bottom: 0;
font-family: inherit; font-family: inherit;
border: none; border: none;
@ -207,7 +202,7 @@ body {
} }
&::after, &::after,
& > textarea { & textarea {
/* Identical styling required!! */ /* Identical styling required!! */
font-weight: 400; font-weight: 400;
font-size: 14px; font-size: 14px;
@ -218,7 +213,7 @@ body {
} }
} }
> button { button {
border: none; border: none;
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
@ -232,7 +227,7 @@ body {
} }
} }
> .icon { .icon {
width: 100%; width: 100%;
height: 100%; height: 100%;
opacity: 0.2; opacity: 0.2;

View File

@ -4,7 +4,10 @@ import type {
ShoutInput, ShoutInput,
Topic, Topic,
Author, Author,
LoadShoutsOptions LoadShoutsOptions,
QueryLoadChatsArgs,
QueryLoadAuthorsByArgs,
QueryLoadMessagesByArgs
} from '../graphql/types.gen' } from '../graphql/types.gen'
import { publicGraphQLClient } from '../graphql/publicGraphQLClient' import { publicGraphQLClient } from '../graphql/publicGraphQLClient'
import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient' import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient'
@ -29,7 +32,6 @@ import chatMessagesLoadBy from '../graphql/query/chat-messages-load-by'
import authorBySlug from '../graphql/query/author-by-slug' import authorBySlug from '../graphql/query/author-by-slug'
import topicBySlug from '../graphql/query/topic-by-slug' import topicBySlug from '../graphql/query/topic-by-slug'
import createChat from '../graphql/mutation/create-chat' import createChat from '../graphql/mutation/create-chat'
import createMessage from '../graphql/mutation/create-chat-message'
import reactionsLoadBy from '../graphql/query/reactions-load-by' import reactionsLoadBy from '../graphql/query/reactions-load-by'
import { REACTIONS_AMOUNT_PER_PAGE } from '../stores/zine/reactions' import { REACTIONS_AMOUNT_PER_PAGE } from '../stores/zine/reactions'
import authorsLoadBy from '../graphql/query/authors-load-by' import authorsLoadBy from '../graphql/query/authors-load-by'
@ -239,8 +241,8 @@ export const apiClient = {
return response.data.deleteReaction return response.data.deleteReaction
}, },
getAuthorsBy: async ({ by, limit = 50, offset = 0 }) => { getAuthorsBy: async (options: QueryLoadAuthorsByArgs) => {
const resp = await publicGraphQLClient.query(authorsLoadBy, { by, limit, offset }).toPromise() const resp = await publicGraphQLClient.query(authorsLoadBy, options).toPromise()
return resp.data.loadAuthorsBy return resp.data.loadAuthorsBy
}, },
getShout: async (slug: string) => { getShout: async (slug: string) => {
@ -262,30 +264,22 @@ export const apiClient = {
}, },
getReactionsBy: async ({ by, limit = REACTIONS_AMOUNT_PER_PAGE, offset = 0 }) => { getReactionsBy: async ({ by, limit = REACTIONS_AMOUNT_PER_PAGE, offset = 0 }) => {
const resp = await publicGraphQLClient.query(reactionsLoadBy, { by, limit, offset }).toPromise() const resp = await publicGraphQLClient.query(reactionsLoadBy, { by, limit, offset }).toPromise()
resp.error ?? console.error(resp.error) if (resp.error) {
console.error(resp.error)
return
}
return resp.data.loadReactionsBy return resp.data.loadReactionsBy
}, },
// inbox // inbox
getChats: async ({ limit, offset }) => { getChats: async (options: QueryLoadChatsArgs) => {
const resp = await privateGraphQLClient.query(myChats, { limit, offset }).toPromise() const resp = await privateGraphQLClient.query(myChats, options).toPromise()
console.log('!!! resp.data.myChats:', resp) console.debug('[getChats]', resp)
return resp.data.myChats return resp.data.myChats
}, },
getChatMessages: async ({ getChatMessages: async (options: QueryLoadMessagesByArgs) => {
chat, const resp = await privateGraphQLClient.query(chatMessagesLoadBy, options).toPromise()
limit = 50,
offset = 0
}: {
chat: string
limit?: number
offset?: number
}) => {
const by = {
chat
}
const resp = await privateGraphQLClient.query(chatMessagesLoadBy, { by, offset, limit }).toPromise()
return resp.data.loadChat return resp.data.loadChat
} }
} }

View File

@ -1,4 +1,4 @@
export const isDev = import.meta.env.MODE === 'development' export const isDev = import.meta.env.MODE === 'development'
const defaultApiUrl = 'https://v2.discours.io' const defaultApiUrl = 'https://testapi.discours.io'
export const apiBaseUrl = import.meta.env.PUBLIC_API_URL || defaultApiUrl export const apiBaseUrl = import.meta.env.PUBLIC_API_URL || defaultApiUrl