diff --git a/src/components/Inbox/DialogAvatar.tsx b/src/components/Inbox/DialogAvatar.tsx index 569292dd..d0d46e86 100644 --- a/src/components/Inbox/DialogAvatar.tsx +++ b/src/components/Inbox/DialogAvatar.tsx @@ -25,10 +25,10 @@ const colors = [ ] const getById = (letter: string) => - colors[Math.abs(Number(BigInt(letter.toLowerCase().charCodeAt(0) - 97) % BigInt(colors.length)))] + colors[Math.abs(Number(BigInt(letter.toLowerCase().codePointAt(0) - 97) % BigInt(colors.length)))] const DialogAvatar = (props: Props) => { - const nameFirstLetter = props.name.substring(0, 1) + const nameFirstLetter = props.name.slice(0, 1) const randomBg = createMemo(() => { return getById(nameFirstLetter) }) diff --git a/src/components/Inbox/DialogCard.tsx b/src/components/Inbox/DialogCard.tsx index 880c80d3..d0bf9ac8 100644 --- a/src/components/Inbox/DialogCard.tsx +++ b/src/components/Inbox/DialogCard.tsx @@ -2,35 +2,23 @@ import './DialogCard.module.scss' import styles from './DialogCard.module.scss' import DialogAvatar from './DialogAvatar' 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 = { online?: boolean message?: string counter?: number + ownerSlug: Author['slug'] } & Author -const createChat = async ({ title, members }: { title?: string; members?: string[] }): Promise => { - await apiClient.createChat({ title, members }) -} - 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()] + members: [props.slug, props.ownerSlug] }) - console.log('!!! test:', test) + console.log('!!! test:', test.data) } catch (err) { console.log('!!! errr:', err) } diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 5fc0d008..2a9fc2be 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -11,8 +11,7 @@ import { useAuthorsStore } from '../../stores/zine/authors' import '../../styles/Inbox.scss' // Для моков import { createClient } from '@urql/core' -import { findAndLoadGraphQLConfig } from '@graphql-codegen/cli' -import { useAuthStore } from '../../stores/auth' +import { useSession } from '../../context/session' const OWNER_ID = '501' const client = createClient({ @@ -61,11 +60,15 @@ export const InboxView = () => { const [authors, setAuthors] = createSignal([]) const [postMessageText, setPostMessageText] = createSignal('') const [loading, setLoading] = createSignal(false) + const [currentSlug, setCurrentSlug] = createSignal(undefined) + const { session } = useSession() const { sortedAuthors } = useAuthorsStore() createEffect(() => { setAuthors(sortedAuthors()) + console.log('!!! session():', session()) + setCurrentSlug(session()?.user?.slug) }) // Поиск по диалогам @@ -118,7 +121,6 @@ export const InboxView = () => { setPostMessageText(event.target.value) } - // TODO: get user session return (
@@ -137,7 +139,13 @@ export const InboxView = () => {
{(author) => ( - + )}
diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 8f2e7454..81c1ac59 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -35,7 +35,6 @@ export type Author = { } export type AuthorStat = { - commented?: Maybe followers?: Maybe followings?: Maybe rating?: Maybe @@ -367,7 +366,6 @@ export type Query = { recentAll: Array> recentCandidates: Array> recentCommented: Array> - recentLayoutShouts: Array> recentPublished: Array> recentReacted: Array> searchChats: Result @@ -384,9 +382,7 @@ export type Query = { signOut: AuthResult topAuthors: Array> topCommented: Array> - topLayoutShouts: Array> topMonth: Array> - topMonthLayoutShouts: Array> topOverall: Array> topPublished: Array> topicsAll: Array> @@ -474,12 +470,6 @@ export type QueryRecentCommentedArgs = { offset: Scalars['Int'] } -export type QueryRecentLayoutShoutsArgs = { - amount?: InputMaybe - layout: Scalars['String'] - offset?: InputMaybe -} - export type QueryRecentPublishedArgs = { limit: Scalars['Int'] offset: Scalars['Int'] @@ -565,23 +555,11 @@ export type QueryTopCommentedArgs = { offset: Scalars['Int'] } -export type QueryTopLayoutShoutsArgs = { - amount?: InputMaybe - layout: Scalars['String'] - offset?: InputMaybe -} - export type QueryTopMonthArgs = { limit: Scalars['Int'] offset: Scalars['Int'] } -export type QueryTopMonthLayoutShoutsArgs = { - amount?: InputMaybe - layout: Scalars['String'] - offset?: InputMaybe -} - export type QueryTopOverallArgs = { limit: Scalars['Int'] offset: Scalars['Int'] @@ -730,7 +708,6 @@ export type Shout = { lang?: Maybe layout?: Maybe mainTopic?: Maybe - media?: Maybe publishedAt?: Maybe publishedBy?: Maybe slug: Scalars['String'] diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 7a5b436e..00dcd20a 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -35,7 +35,8 @@ import reactionDestroy from '../graphql/mutation/reaction-destroy' import reactionUpdate from '../graphql/mutation/reaction-update' import incrementView from '../graphql/mutation/increment-view' import createArticle from '../graphql/mutation/article-create' -import myChats from '../graphql/query/my-chats' +import CreateChat from '../graphql/mutation/create-chat' +// import myChats from '../graphql/query/my-chats' import authorBySlug from '../graphql/query/author-by-slug' import topicBySlug from '../graphql/query/topic-by-slug' @@ -372,22 +373,22 @@ export const apiClient = { }, createChat: async ({ title, members }) => { return await privateGraphQLClient.mutation(CreateChat, { title: title, members: members }).toPromise() - }, - - getChats: async (payload = {}) => { - const resp = await privateGraphQLClient.query(myChats, payload).toPromise() - return resp.data.myChats - }, - getChatMessages: async ({ - chatId, - offset = 0, - amount = 50 - }: { - chatId: string - offset?: number - amount?: number - }) => { - const resp = await privateGraphQLClient.query(loadChat, { chatId, offset, amount }).toPromise() - return resp.data.loadChat } + + // getChats: async (payload = {}) => { + // const resp = await privateGraphQLClient.query(myChats, payload).toPromise() + // return resp.data.myChats + // }, + // getChatMessages: async ({ + // chatId, + // offset = 0, + // amount = 50 + // }: { + // chatId: string + // offset?: number + // amount?: number + // }) => { + // const resp = await privateGraphQLClient.query(loadChat, { chatId, offset, amount }).toPromise() + // return resp.data.loadChat + // } }