diff --git a/src/components/Inbox/DialogCard.tsx b/src/components/Inbox/DialogCard.tsx index 9d43a4e8..62958081 100644 --- a/src/components/Inbox/DialogCard.tsx +++ b/src/components/Inbox/DialogCard.tsx @@ -2,7 +2,7 @@ import styles from './DialogCard.module.scss' import DialogAvatar from './DialogAvatar' import type { Author, AuthResult } from '../../graphql/types.gen' import { useSession } from '../../context/session' -import { createMemo, InitializedResource } from 'solid-js' +import { createMemo } from 'solid-js' import { apiClient } from '../../utils/apiClient' type DialogProps = { @@ -22,11 +22,11 @@ const DialogCard = (props: DialogProps) => { const handleOpenChat = async () => { try { - const test = await apiClient.createChat({ + const initChat = await apiClient.createChat({ title: 'test chat', members: [props.author.slug, currentSession().user.slug] }) - console.log('!!! test:', test) + // console.log('!!! test:', test) } catch (error) { console.log('!!! errr:', error) } diff --git a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx index bfe024ae..6a92582b 100644 --- a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx +++ b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx @@ -23,7 +23,7 @@ export const ForgotPasswordForm = () => { setValidationErrors(({ email: _notNeeded, ...rest }) => rest) setEmail(newEmail) } - const [sended, setSended] = createSignal(false) + const [submitError, setSubmitError] = createSignal('') const [isSubmitting, setIsSubmitting] = createSignal(false) const [validationErrors, setValidationErrors] = createSignal({}) @@ -69,12 +69,7 @@ export const ForgotPasswordForm = () => { return (

{t('Forgot password?')}

- {t('Link sent, check your email')}} - > -
{t('Everything is ok, please give us your email address')}
-
+
{t('Everything is ok, please give us your email address')}
    diff --git a/src/components/Nav/HeaderAuth.tsx b/src/components/Nav/HeaderAuth.tsx index 9f838fec..aa54e6fa 100644 --- a/src/components/Nav/HeaderAuth.tsx +++ b/src/components/Nav/HeaderAuth.tsx @@ -3,7 +3,7 @@ import { clsx } from 'clsx' import { handleClientRouteLinkClick, useRouter } from '../../stores/router' import { t } from '../../utils/intl' import { Icon } from '../_shared/Icon' -import { createSignal, onMount, Show } from 'solid-js' +import { createSignal, Show } from 'solid-js' import Notifications from './Notifications' import { ProfilePopup } from './ProfilePopup' import Userpic from '../Author/Userpic' diff --git a/src/components/Nav/ProfileModal.tsx b/src/components/Nav/ProfileModal.tsx index d67cda93..ddfabe87 100644 --- a/src/components/Nav/ProfileModal.tsx +++ b/src/components/Nav/ProfileModal.tsx @@ -18,6 +18,7 @@ export const ProfileModal = () => { const author = createMemo(() => { const a: Author = { + id: null, name: 'anonymous', userpic: '', slug: '' diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 25dae112..7f59dfb3 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -13,6 +13,7 @@ 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({ @@ -66,11 +67,15 @@ export const InboxView = () => { const [authors, setAuthors] = createSignal([]) const [postMessageText, setPostMessageText] = createSignal('') const [loading, setLoading] = createSignal(false) + const [currentSlug, setCurrentSlug] = createSignal() + const { session } = useSession() const { sortedAuthors } = useAuthorsStore() createEffect(() => { setAuthors(sortedAuthors()) + console.log('!!! session():', session()) + setCurrentSlug(session()?.user?.slug) }) // Поиск по диалогам @@ -97,30 +102,31 @@ export const InboxView = () => { let chatWindow onMount(async () => { setLoading(true) - await fetchMessages(messageQuery) - .then(() => { - setLoading(false) - chatWindow.scrollTop = chatWindow.scrollHeight - }) - .catch(() => setLoading(false)) + try { + await fetchMessages(messageQuery) + } catch (error) { + setLoading(false) + console.error([fetchMessages], error) + } finally { + setLoading(false) + chatWindow.scrollTop = chatWindow.scrollHeight + } }) const handleSubmit = async () => { - postMessage(postMessageText()) - .then((result) => { - setMessages((prev) => [...prev, result]) - }) - .then(() => { - setPostMessageText('') - chatWindow.scrollTop = chatWindow.scrollHeight - }) - .catch(console.error) + try { + const post = await postMessage(postMessageText()) + setMessages((prev) => [...prev, post]) + setPostMessageText('') + chatWindow.scrollTop = chatWindow.scrollHeight + } catch (error) { + console.error('[post message error]:', error) + } } const handleChangeMessage = (event) => { setPostMessageText(event.target.value) } - // TODO: get user session return (
    diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 708b4194..10789e47 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -24,18 +24,42 @@ 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['Int'] + id: Scalars['String'] messages: Array> + private?: Maybe title?: Maybe unread?: Maybe updatedAt: Scalars['Int'] @@ -52,8 +76,8 @@ export type ChatMember = { invitedAt?: Maybe invitedBy?: Maybe name: Scalars['String'] - pic?: Maybe slug: Scalars['String'] + userpic?: Maybe } export type Collab = { @@ -69,6 +93,7 @@ export type Collection = { createdAt: Scalars['DateTime'] createdBy: User desc?: Maybe + id: Scalars['Int'] publishedAt?: Maybe slug: Scalars['String'] title: Scalars['String'] @@ -78,6 +103,7 @@ export type Community = { createdAt: Scalars['DateTime'] createdBy: User desc?: Maybe + id: Scalars['Int'] name: Scalars['String'] pic: Scalars['String'] slug: Scalars['String'] @@ -96,7 +122,7 @@ export type Message = { chatId: Scalars['String'] createdAt: Scalars['Int'] id: Scalars['Int'] - replyTo?: Maybe + replyTo?: Maybe updatedAt?: Maybe } @@ -122,8 +148,7 @@ export type Mutation = { createReaction: Result createShout: Result createTopic: Result - deleteCollection: Result - deleteCommunity: Result + deleteChat: Result deleteMessage: Result deleteReaction: Result deleteShout: Result @@ -159,7 +184,7 @@ export type MutationCreateChatArgs = { export type MutationCreateMessageArgs = { body: Scalars['String'] chatId: Scalars['String'] - replyTo?: InputMaybe + replyTo?: InputMaybe } export type MutationCreateReactionArgs = { @@ -174,12 +199,8 @@ export type MutationCreateTopicArgs = { input: TopicInput } -export type MutationDeleteCollectionArgs = { - slug: Scalars['String'] -} - -export type MutationDeleteCommunityArgs = { - slug: Scalars['String'] +export type MutationDeleteChatArgs = { + chatId: Scalars['String'] } export type MutationDeleteMessageArgs = { @@ -295,58 +316,34 @@ export type ProfileInput = { } export type Query = { - authorsAll: Array> - collectionsAll: Array> + authorsAll: Array> + getAuthor: User getCollabs: Array> - getCommunities: Array> - getCommunity: Community - getShoutBySlug: Shout - getUserCollections: Array> - getUserRoles: Array> - getUsersBySlugs: Array> + getTopic: Topic isEmailUsed: Scalars['Boolean'] - loadChat: Array> + loadAuthorsBy: Array> + loadChats: Result + loadMessagesBy: Result + loadReactionsBy: Array> + loadShoutsBy: Array> markdownBody: Scalars['String'] - 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> + searchUsers: Result signIn: AuthResult signOut: AuthResult topicsAll: Array> topicsByAuthor: Array> topicsByCommunity: Array> topicsRandom: Array> - userFollowedAuthors: Array> - userFollowedCommunities: Array> + userFollowedAuthors: Array> userFollowedTopics: Array> - userFollowers: Array> - userReactedShouts: Array> + userFollowers: Array> } -export type QueryGetCommunityArgs = { - slug?: InputMaybe -} - -export type QueryGetShoutBySlugArgs = { +export type QueryGetAuthorArgs = { slug: Scalars['String'] } -export type QueryGetUserCollectionsArgs = { - author: Scalars['String'] -} - -export type QueryGetUserRolesArgs = { +export type QueryGetTopicArgs = { slug: Scalars['String'] } @@ -354,7 +351,30 @@ export type QueryIsEmailUsedArgs = { email: Scalars['String'] } -export type QueryLoadChatArgs = { +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 = { amount?: InputMaybe by?: InputMaybe offset?: InputMaybe @@ -364,76 +384,10 @@ export type QueryMarkdownBodyArgs = { body: 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 QuerySearchUsersArgs = { + amount?: InputMaybe + offset?: InputMaybe + query: Scalars['String'] } export type QuerySignInArgs = { @@ -494,7 +448,6 @@ export type ReactionBy = { days?: InputMaybe order?: InputMaybe shout?: InputMaybe - shouts?: InputMaybe>> stat?: InputMaybe topic?: InputMaybe } @@ -542,8 +495,8 @@ export type Resource = { } export type Result = { - author?: Maybe - authors?: Maybe>> + author?: Maybe + authors?: Maybe>> chat?: Maybe chats?: Maybe>> communities?: Maybe>> @@ -556,8 +509,10 @@ export type Result = { reactions?: Maybe>> shout?: Maybe shouts?: Maybe>> + slugs?: Maybe>> topic?: Maybe topics?: Maybe>> + uids?: Maybe>> } export type Role = { @@ -576,7 +531,6 @@ export type Shout = { createdAt: Scalars['DateTime'] deletedAt?: Maybe deletedBy?: Maybe - draft?: Maybe id: Scalars['Int'] lang?: Maybe layout?: Maybe @@ -591,8 +545,8 @@ export type Shout = { topics?: Maybe>> updatedAt?: Maybe updatedBy?: Maybe - versionOf?: Maybe - visibleFor?: Maybe>> + versionOf?: Maybe + visibility?: Maybe } export type ShoutInput = { @@ -614,12 +568,10 @@ export type ShoutsBy = { days?: InputMaybe layout?: InputMaybe order?: InputMaybe - published?: InputMaybe slug?: InputMaybe stat?: InputMaybe title?: InputMaybe topic?: InputMaybe - topics?: InputMaybe>> visibility?: InputMaybe } diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 3d860197..851cda44 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -1,12 +1,4 @@ -import type { - Reaction, - Shout, - FollowingEntity, - AuthResult, - ShoutInput, - Topic, - Author -} from '../graphql/types.gen' +import type { FollowingEntity, AuthResult, ShoutInput, Topic, Author } from '../graphql/types.gen' import { publicGraphQLClient } from '../graphql/publicGraphQLClient' import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient' import topicsAll from '../graphql/query/topics-all' @@ -26,14 +18,14 @@ import reactionDestroy from '../graphql/mutation/reaction-destroy' import reactionUpdate from '../graphql/mutation/reaction-update' import createArticle from '../graphql/mutation/article-create' import myChats from '../graphql/query/chats-load' -import loadChat from '../graphql/query/chat-messages-load-by' -import topicBySlug from '../graphql/query/topic-by-slug' +import chatMessagesLoadBy from '../graphql/query/chat-messages-load-by' 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 topicBySlug from '../graphql/query/topic-by-slug' import createChatQuery from '../graphql/mutation/create-chat' +import reactionsLoadBy from '../graphql/query/reactions-load-by' import { REACTIONS_AMOUNT_PER_PAGE } from '../stores/zine/reactions' +import authorsLoadBy from '../graphql/query/authors-load-by' +import shoutsLoadBy from '../graphql/query/articles-load-by' const FEED_SIZE = 50 @@ -262,7 +254,7 @@ export const apiClient = { const by = { chat } - const resp = await privateGraphQLClient.query(loadChat, { by, offset, amount }).toPromise() + const resp = await privateGraphQLClient.query(chatMessagesLoadBy, { by, offset, amount }).toPromise() return resp.data.loadChat } }