Chats is working!

This commit is contained in:
ilya-bkv 2022-12-05 13:45:53 +03:00
parent c1413bbf5d
commit 9602925a31
8 changed files with 13 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import { locale } from '../../stores/ui'
import { follow, unfollow } from '../../stores/zine/common' import { follow, unfollow } from '../../stores/zine/common'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { useSession } from '../../context/session' import { useSession } from '../../context/session'
import { FollowingEntity } from '../../graphql/types.gen'
interface AuthorCardProps { interface AuthorCardProps {
caption?: string caption?: string
@ -84,7 +85,8 @@ export const AuthorCard = (props: AuthorCardProps) => {
when={subscribed()} when={subscribed()}
fallback={ fallback={
<button <button
onClick={() => follow} // TODO: change button view reactivity
onclick={() => follow({ what: FollowingEntity.Author, slug: props.author.slug })}
class={clsx('button', styles.button)} class={clsx('button', styles.button)}
classList={{ classList={{
[styles.buttonSubscribe]: !props.isAuthorsList, [styles.buttonSubscribe]: !props.isAuthorsList,
@ -101,7 +103,7 @@ export const AuthorCard = (props: AuthorCardProps) => {
} }
> >
<button <button
onClick={() => unfollow} onclick={() => follow({ what: FollowingEntity.Author, slug: props.author.slug })}
classList={{ classList={{
[styles.buttonSubscribe]: !props.isAuthorsList, [styles.buttonSubscribe]: !props.isAuthorsList,
'button--subscribe': !props.isAuthorsList, 'button--subscribe': !props.isAuthorsList,

View File

@ -37,7 +37,7 @@ export const InboxView = () => {
const [sortByPerToPer, setSortByPerToPer] = createSignal<boolean>(false) const [sortByPerToPer, setSortByPerToPer] = createSignal<boolean>(false)
const [currentDialog, setCurrentDialog] = createSignal<Chat>() const [currentDialog, setCurrentDialog] = createSignal<Chat>()
const { session } = useSession() const { session } = useSession()
const currentUserId = createMemo(() => session()?.user?.id) const currentUserId = createMemo(() => session()?.user.id)
// Поиск по диалогам // Поиск по диалогам
const getQuery = (query) => { const getQuery = (query) => {

View File

@ -23,6 +23,7 @@ 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) {

View File

@ -7,6 +7,7 @@ export default gql`
token token
user { user {
_id: slug _id: slug
id
name name
slug slug
bio bio

View File

@ -78,7 +78,6 @@ 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,7 +139,7 @@ export type LoadShoutsOptions = {
} }
export type Message = { export type Message = {
author: Scalars['Int'] author: Scalars['String']
body: Scalars['String'] body: Scalars['String']
chatId: Scalars['String'] chatId: Scalars['String']
createdAt: Scalars['Int'] createdAt: Scalars['Int']

View File

@ -2,6 +2,7 @@ import type { FollowingEntity } from '../../graphql/types.gen'
import { apiClient } from '../../utils/apiClient' import { apiClient } from '../../utils/apiClient'
export const follow = async ({ what, slug }: { what: FollowingEntity; slug: string }) => { export const follow = async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
console.log('!!! follow:')
await apiClient.follow({ what, slug }) await apiClient.follow({ what, slug })
// refresh session // refresh session
// TODO: _store update code // TODO: _store update code

View File

@ -16,7 +16,7 @@ main {
display: flex; display: flex;
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
position: fixed; position: absolute;
.row { .row {
flex: 1; flex: 1;

View File

@ -167,11 +167,12 @@ export const apiClient = {
// subscribe // subscribe
follow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => { follow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
const response = await privateGraphQLClient.query(followMutation, { what, slug }).toPromise() const response = await privateGraphQLClient.mutation(followMutation, { what, slug }).toPromise()
console.debug('!!! [follow]:', response)
return response.data.follow return response.data.follow
}, },
unfollow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => { unfollow: async ({ what, slug }: { what: FollowingEntity; slug: string }) => {
const response = await privateGraphQLClient.query(unfollowMutation, { what, slug }).toPromise() const response = await privateGraphQLClient.mutation(unfollowMutation, { what, slug }).toPromise()
return response.data.unfollow return response.data.unfollow
}, },