diff --git a/src/components/Inbox/DialogAvatar.tsx b/src/components/Inbox/DialogAvatar.tsx index dbc63282..d0d46e86 100644 --- a/src/components/Inbox/DialogAvatar.tsx +++ b/src/components/Inbox/DialogAvatar.tsx @@ -18,10 +18,10 @@ const colors = [ '#ca6702', '#ae2012', '#9b2226', - '#668CFF', - '#C34CFE', - '#E699FF', - '#6633FF' + '#668cff', + '#c34cfe', + '#e699ff', + '#6633ff' ] const getById = (letter: string) => diff --git a/src/components/Inbox/DialogCard.tsx b/src/components/Inbox/DialogCard.tsx index 74d90673..e31b55d5 100644 --- a/src/components/Inbox/DialogCard.tsx +++ b/src/components/Inbox/DialogCard.tsx @@ -2,17 +2,43 @@ 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' -type Props = { +const { session } = useAuthStore() + +type DialogProps = { online?: boolean message?: string counter?: number author?: Author } -const DialogCard = (props: Props) => { +const createChat = async ({ title, members }: { title?: string; members?: string[] }): Promise => { + await apiClient.createChat({ title, members }) +} + +const DialogCard = (props: DialogProps) => { + const [currentUser, setCurrentUser] = createSignal(undefined) + createEffect(() => { + setCurrentUser(session()?.user?.slug) + }) + + const handleOpenChat = async () => { + try { + const test = await apiClient.createChat({ + title: 'test chat', + members: [props.author.slug, currentUser()] + }) + console.log('!!! test:', test) + } catch (err) { + console.log('!!! errr:', err) + } + } + return ( -
+
diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 0f8bea76..25dae112 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -6,17 +6,20 @@ import { Loading } from '../Loading' import DialogCard from '../Inbox/DialogCard' import Search from '../Inbox/Search' import { useAuthorsStore } from '../../stores/zine/authors' +// const { session } = useAuthStore() import '../../styles/Inbox.scss' // Для моков import { createClient } from '@urql/core' import { findAndLoadGraphQLConfig } from '@graphql-codegen/cli' +// import { useAuthStore } from '../../stores/auth' const OWNER_ID = '501' const client = createClient({ url: 'https://graphqlzero.almansi.me/api' }) +// console.log('!!! session:', session) // interface InboxProps { // chats?: Chat[] // messages?: Message[] @@ -63,6 +66,7 @@ export const InboxView = () => { const [authors, setAuthors] = createSignal([]) const [postMessageText, setPostMessageText] = createSignal('') const [loading, setLoading] = createSignal(false) + const { sortedAuthors } = useAuthorsStore() createEffect(() => { @@ -133,7 +137,7 @@ export const InboxView = () => {
- {(author: Author) => } + {(author) => }
diff --git a/src/graphql/mutation/create-chat.ts b/src/graphql/mutation/create-chat.ts new file mode 100644 index 00000000..b700707b --- /dev/null +++ b/src/graphql/mutation/create-chat.ts @@ -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 + } + } + } +` diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index ef7187e8..b8ebab27 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -24,42 +24,18 @@ export type AuthResult = { export type Author = { bio?: Maybe caption?: Maybe - id: Scalars['Int'] - lastSeen?: Maybe links?: Maybe>> name: Scalars['String'] - roles?: Maybe>> slug: Scalars['String'] - stat?: Maybe userpic?: Maybe } -export type AuthorStat = { - commented?: Maybe - followers?: Maybe - followings?: Maybe - rating?: Maybe -} - -export type AuthorsBy = { - createdAt?: InputMaybe - days?: InputMaybe - lastSeen?: InputMaybe - name?: InputMaybe - order?: InputMaybe - slug?: InputMaybe - stat?: InputMaybe - topic?: InputMaybe -} - export type Chat = { - admins?: Maybe>> createdAt: Scalars['Int'] createdBy: User description?: Maybe - id: Scalars['String'] + id: Scalars['Int'] messages: Array> - private?: Maybe title?: Maybe unread?: Maybe updatedAt: Scalars['Int'] @@ -76,8 +52,8 @@ export type ChatMember = { invitedAt?: Maybe invitedBy?: Maybe name: Scalars['String'] + pic?: Maybe slug: Scalars['String'] - userpic?: Maybe } export type Collab = { @@ -93,7 +69,6 @@ export type Collection = { createdAt: Scalars['DateTime'] createdBy: User desc?: Maybe - id: Scalars['Int'] publishedAt?: Maybe slug: Scalars['String'] title: Scalars['String'] @@ -103,7 +78,6 @@ export type Community = { createdAt: Scalars['DateTime'] createdBy: User desc?: Maybe - id: Scalars['Int'] name: Scalars['String'] pic: Scalars['String'] slug: Scalars['String'] @@ -122,7 +96,7 @@ export type Message = { chatId: Scalars['String'] createdAt: Scalars['Int'] id: Scalars['Int'] - replyTo?: Maybe + replyTo?: Maybe updatedAt?: Maybe } @@ -148,7 +122,8 @@ export type Mutation = { createReaction: Result createShout: Result createTopic: Result - deleteChat: Result + deleteCollection: Result + deleteCommunity: Result deleteMessage: Result deleteReaction: Result deleteShout: Result @@ -184,7 +159,7 @@ export type MutationCreateChatArgs = { export type MutationCreateMessageArgs = { body: Scalars['String'] chatId: Scalars['String'] - replyTo?: InputMaybe + replyTo?: InputMaybe } export type MutationCreateReactionArgs = { @@ -199,8 +174,12 @@ export type MutationCreateTopicArgs = { input: TopicInput } -export type MutationDeleteChatArgs = { - chatId: Scalars['String'] +export type MutationDeleteCollectionArgs = { + slug: Scalars['String'] +} + +export type MutationDeleteCommunityArgs = { + slug: Scalars['String'] } export type MutationDeleteMessageArgs = { @@ -316,34 +295,58 @@ export type ProfileInput = { } export type Query = { - authorsAll: Array> - getAuthor: User + authorsAll: Array> + collectionsAll: Array> getCollabs: Array> - getTopic: Topic + getCommunities: Array> + getCommunity: Community + getShoutBySlug: Shout + getUserCollections: Array> + getUserRoles: Array> + getUsersBySlugs: Array> isEmailUsed: Scalars['Boolean'] - loadAuthorsBy: Array> - loadChats: Result - loadMessagesBy: Result - loadReactionsBy: Array> - loadShoutsBy: Array> + loadChat: Array> markdownBody: Scalars['String'] - searchUsers: Result + myChats: Array> + reactionsByAuthor: Array> + reactionsForShouts: Array> + recentAll: Array> + recentCandidates: Array> + recentCommented: Array> + recentPublished: Array> + recentReacted: Array> + searchQuery?: Maybe>> + shoutsByAuthors: Array> + shoutsByCollection: Array> + shoutsByCommunities: Array> + shoutsByTopics: Array> + shoutsForFeed: Array> signIn: AuthResult signOut: AuthResult topicsAll: Array> topicsByAuthor: Array> topicsByCommunity: Array> topicsRandom: Array> - userFollowedAuthors: Array> + userFollowedAuthors: Array> + userFollowedCommunities: Array> userFollowedTopics: Array> - userFollowers: Array> + userFollowers: Array> + userReactedShouts: Array> } -export type QueryGetAuthorArgs = { +export type QueryGetCommunityArgs = { + slug?: InputMaybe +} + +export type QueryGetShoutBySlugArgs = { slug: Scalars['String'] } -export type QueryGetTopicArgs = { +export type QueryGetUserCollectionsArgs = { + author: Scalars['String'] +} + +export type QueryGetUserRolesArgs = { slug: Scalars['String'] } @@ -351,30 +354,7 @@ export type QueryIsEmailUsedArgs = { email: Scalars['String'] } -export type QueryLoadAuthorsByArgs = { - amount?: InputMaybe - by?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadChatsArgs = { - amount?: InputMaybe - offset?: InputMaybe -} - -export type QueryLoadMessagesByArgs = { - amount?: InputMaybe - by: MessagesBy - offset?: InputMaybe -} - -export type QueryLoadReactionsByArgs = { - amount?: InputMaybe - by: ReactionBy - limit?: InputMaybe -} - -export type QueryLoadShoutsByArgs = { +export type QueryLoadChatArgs = { amount?: InputMaybe by?: InputMaybe offset?: InputMaybe @@ -384,10 +364,76 @@ export type QueryMarkdownBodyArgs = { body: Scalars['String'] } -export type QuerySearchUsersArgs = { - amount?: InputMaybe - offset?: InputMaybe - query: Scalars['String'] +export type QueryReactionsByAuthorArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] + slug: Scalars['String'] +} + +export type QueryReactionsForShoutsArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] + shouts: Array> +} + +export type QueryRecentAllArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] +} + +export type QueryRecentCandidatesArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] +} + +export type QueryRecentCommentedArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] +} + +export type QueryRecentPublishedArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] +} + +export type QueryRecentReactedArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] +} + +export type QuerySearchQueryArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] + q?: InputMaybe +} + +export type QueryShoutsByAuthorsArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] + slugs: Array> +} + +export type QueryShoutsByCollectionArgs = { + collection: Scalars['String'] + limit: Scalars['Int'] + offset: Scalars['Int'] +} + +export type QueryShoutsByCommunitiesArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] + slugs: Array> +} + +export type QueryShoutsByTopicsArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] + slugs: Array> +} + +export type QueryShoutsForFeedArgs = { + limit: Scalars['Int'] + offset: Scalars['Int'] } export type QuerySignInArgs = { @@ -495,8 +541,8 @@ export type Resource = { } export type Result = { - author?: Maybe - authors?: Maybe>> + author?: Maybe + authors?: Maybe>> chat?: Maybe chats?: Maybe>> communities?: Maybe>> @@ -509,10 +555,8 @@ export type Result = { reactions?: Maybe>> shout?: Maybe shouts?: Maybe>> - slugs?: Maybe>> topic?: Maybe topics?: Maybe>> - uids?: Maybe>> } export type Role = { @@ -531,6 +575,7 @@ export type Shout = { createdAt: Scalars['DateTime'] deletedAt?: Maybe deletedBy?: Maybe + draft?: Maybe id: Scalars['Int'] lang?: Maybe layout?: Maybe @@ -545,8 +590,8 @@ export type Shout = { topics?: Maybe>> updatedAt?: Maybe updatedBy?: Maybe - versionOf?: Maybe - visibility?: Maybe + versionOf?: Maybe + visibleFor?: Maybe>> } export type ShoutInput = { diff --git a/src/styles/Inbox.scss b/src/styles/Inbox.scss index fab4cbfb..581f29db 100644 --- a/src/styles/Inbox.scss +++ b/src/styles/Inbox.scss @@ -4,6 +4,10 @@ main { flex-direction: column; position: relative; } +// TODO: добавлять когда открыт чат +body { + overflow: hidden; +} .messages { top: 74px; @@ -17,7 +21,7 @@ main { flex: 1; flex-direction: column; position: fixed; - z-index: 1; + z-index: 9; > .row { flex: 1; diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index a0eb2884..e05dc69c 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -34,6 +34,7 @@ import authorBySlug from '../graphql/query/author-by-slug' import shoutsLoadBy from '../graphql/query/articles-load-by' import reactionsLoadBy from '../graphql/query/reactions-load-by' import authorsLoadBy from '../graphql/query/authors-load-by' +import createChatQuery from '../graphql/mutation/create-chat' const FEED_SIZE = 50 @@ -396,6 +397,12 @@ export const apiClient = { incrementView: async ({ articleSlug }) => { await privateGraphQLClient.mutation(incrementView, { shout: articleSlug }) }, + createChat: async ({ title, members }) => { + return await privateGraphQLClient + .mutation(createChatQuery, { title: title, members: members }) + .toPromise() + }, + getChats: async (payload = {}) => { const resp = await privateGraphQLClient.query(myChats, payload).toPromise() return resp.data.myChats diff --git a/src/utils/config.ts b/src/utils/config.ts index ecb7be64..8501f5bd 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -1,6 +1,6 @@ -export const isDev = import.meta.env.VERCEL_ENV !== 'production' -export const apiBaseUrl = - import.meta.env.PUBLIC_API_URL || - import.meta.env.API_URL || - import.meta.env.VITE_API_URL || - 'http://localhost:8080' +export const isDev = import.meta.env.MODE === 'development' + +export const apiBaseUrl = 'https://testapi.discours.io' +// export const apiBaseUrl = 'https://newapi.discours.io' +// testapi.discours.io +// export const apiBaseUrl = 'http://localhost:8080'