Create chat
This commit is contained in:
parent
cc54f055f3
commit
8e88d2a68b
|
@ -18,10 +18,10 @@ const colors = [
|
||||||
'#ca6702',
|
'#ca6702',
|
||||||
'#ae2012',
|
'#ae2012',
|
||||||
'#9b2226',
|
'#9b2226',
|
||||||
'#668CFF',
|
'#668cff',
|
||||||
'#C34CFE',
|
'#c34cfe',
|
||||||
'#E699FF',
|
'#e699ff',
|
||||||
'#6633FF'
|
'#6633ff'
|
||||||
]
|
]
|
||||||
|
|
||||||
const getById = (letter: string) =>
|
const getById = (letter: string) =>
|
||||||
|
|
|
@ -2,6 +2,11 @@ import './DialogCard.module.scss'
|
||||||
import styles from './DialogCard.module.scss'
|
import styles from './DialogCard.module.scss'
|
||||||
import DialogAvatar from './DialogAvatar'
|
import DialogAvatar from './DialogAvatar'
|
||||||
import type { Author } from '../../graphql/types.gen'
|
import type { Author } from '../../graphql/types.gen'
|
||||||
|
import { useAuthStore } from '../../stores/auth'
|
||||||
|
import { createEffect, createSignal } from 'solid-js'
|
||||||
|
import { apiClient } from '../../utils/apiClient'
|
||||||
|
|
||||||
|
const { session } = useAuthStore()
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
online?: boolean
|
online?: boolean
|
||||||
|
@ -9,9 +14,30 @@ type Props = {
|
||||||
counter?: number
|
counter?: number
|
||||||
} & Author
|
} & Author
|
||||||
|
|
||||||
|
const createChat = async ({ title, members }: { title?: string; members?: string[] }): Promise<void> => {
|
||||||
|
await apiClient.createChat({ title, members })
|
||||||
|
}
|
||||||
|
|
||||||
const DialogCard = (props: Props) => {
|
const DialogCard = (props: Props) => {
|
||||||
|
const [currentUser, setCurrentUser] = createSignal(undefined)
|
||||||
|
createEffect(() => {
|
||||||
|
setCurrentUser(session()?.user?.slug)
|
||||||
|
})
|
||||||
|
|
||||||
|
const handleOpenChat = async () => {
|
||||||
|
try {
|
||||||
|
const test = await apiClient.createChat({
|
||||||
|
title: 'test chat',
|
||||||
|
members: [props.slug, currentUser()]
|
||||||
|
})
|
||||||
|
console.log('!!! test:', test)
|
||||||
|
} catch (err) {
|
||||||
|
console.log('!!! errr:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={styles.DialogCard} onClick={handleGoToChat}>
|
<div class={styles.DialogCard} onClick={handleOpenChat}>
|
||||||
<div class={styles.avatar}>
|
<div class={styles.avatar}>
|
||||||
<DialogAvatar name={props.name} url={props.userpic} online={props.online} />
|
<DialogAvatar name={props.name} url={props.userpic} online={props.online} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,17 +6,20 @@ 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 { useAuthorsStore } from '../../stores/zine/authors'
|
import { useAuthorsStore } from '../../stores/zine/authors'
|
||||||
|
// const { session } = useAuthStore()
|
||||||
|
|
||||||
import '../../styles/Inbox.scss'
|
import '../../styles/Inbox.scss'
|
||||||
// Для моков
|
// Для моков
|
||||||
import { createClient } from '@urql/core'
|
import { createClient } from '@urql/core'
|
||||||
import { findAndLoadGraphQLConfig } from '@graphql-codegen/cli'
|
import { findAndLoadGraphQLConfig } from '@graphql-codegen/cli'
|
||||||
|
import { useAuthStore } from '../../stores/auth'
|
||||||
|
|
||||||
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'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// console.log('!!! session:', session)
|
||||||
// interface InboxProps {
|
// interface InboxProps {
|
||||||
// chats?: Chat[]
|
// chats?: Chat[]
|
||||||
// messages?: Message[]
|
// messages?: Message[]
|
||||||
|
@ -58,6 +61,7 @@ export const InboxView = () => {
|
||||||
const [authors, setAuthors] = createSignal<Author[]>([])
|
const [authors, setAuthors] = createSignal<Author[]>([])
|
||||||
const [postMessageText, setPostMessageText] = createSignal('')
|
const [postMessageText, setPostMessageText] = createSignal('')
|
||||||
const [loading, setLoading] = createSignal<boolean>(false)
|
const [loading, setLoading] = createSignal<boolean>(false)
|
||||||
|
|
||||||
const { sortedAuthors } = useAuthorsStore()
|
const { sortedAuthors } = useAuthorsStore()
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
|
|
12
src/graphql/mutation/create-chat.ts
Normal file
12
src/graphql/mutation/create-chat.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { gql } from '@urql/core'
|
||||||
|
|
||||||
|
export default gql`
|
||||||
|
mutation CreateChat($title: String, $members: [String]!) {
|
||||||
|
createChat(title: $title, members: $members) {
|
||||||
|
error
|
||||||
|
chat {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
|
@ -29,6 +29,7 @@ import authorsBySlugs from '../graphql/query/authors-by-slugs'
|
||||||
import incrementView from '../graphql/mutation/increment-view'
|
import incrementView from '../graphql/mutation/increment-view'
|
||||||
import myChats from '../graphql/query/im-chats'
|
import myChats from '../graphql/query/im-chats'
|
||||||
import loadChat from '../graphql/query/im-load-messages'
|
import loadChat from '../graphql/query/im-load-messages'
|
||||||
|
import CreateChat from '../graphql/mutation/create-chat'
|
||||||
|
|
||||||
const FEED_SIZE = 50
|
const FEED_SIZE = 50
|
||||||
|
|
||||||
|
@ -326,6 +327,10 @@ export const apiClient = {
|
||||||
incrementView: async ({ articleSlug }) => {
|
incrementView: async ({ articleSlug }) => {
|
||||||
await privateGraphQLClient.mutation(incrementView, { shout: articleSlug })
|
await privateGraphQLClient.mutation(incrementView, { shout: articleSlug })
|
||||||
},
|
},
|
||||||
|
createChat: async ({ title, members }) => {
|
||||||
|
return await privateGraphQLClient.mutation(CreateChat, { title: title, members: members }).toPromise()
|
||||||
|
},
|
||||||
|
|
||||||
getChats: async (payload = {}) => {
|
getChats: async (payload = {}) => {
|
||||||
const resp = await privateGraphQLClient.query(myChats, payload).toPromise()
|
const resp = await privateGraphQLClient.query(myChats, payload).toPromise()
|
||||||
return resp.data.myChats
|
return resp.data.myChats
|
||||||
|
|
Loading…
Reference in New Issue
Block a user