From 23bb1c193c48cdd8cc13ee7573c364e9d89c585e Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 2 Nov 2022 09:26:07 +0300 Subject: [PATCH 01/55] fixconfig --- astro.config.ts | 2 +- src/utils/config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/astro.config.ts b/astro.config.ts index beb88fe9..cf758735 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -67,7 +67,7 @@ const astroConfig: AstroUserConfig = { } */ }, - external: ['@aws-sdk/clients/s3'] + external: [] } }, css diff --git a/src/utils/config.ts b/src/utils/config.ts index 75f03f39..ab0ab70b 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -1,4 +1,4 @@ export const isDev = import.meta.env.MODE === 'development' export const apiBaseUrl = 'https://newapi.discours.io' -// export const apiBaseUrl = 'http://localhost:8000' +// export const apiBaseUrl = 'http://localhost:8080' From e609eb09fa2c41e6873bfd4363a5e2910198777c Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 2 Nov 2022 13:16:53 +0300 Subject: [PATCH 02/55] sended link status, sign out revoke token --- .../Nav/AuthModal/ForgotPasswordForm.tsx | 10 ++++++++-- src/stores/auth.ts | 14 +++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx index f19a89f4..0dc12583 100644 --- a/src/components/Nav/AuthModal/ForgotPasswordForm.tsx +++ b/src/components/Nav/AuthModal/ForgotPasswordForm.tsx @@ -22,7 +22,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({}) @@ -53,6 +53,7 @@ export const ForgotPasswordForm = () => { try { const result = await signSendLink({ email: email(), lang: locale() }) if (result.error) setSubmitError(result.error) + else setSended(true) } catch (error) { setSubmitError(error.message) } finally { @@ -63,7 +64,12 @@ export const ForgotPasswordForm = () => { return (

{t('Forgot password?')}

-
{t('Everything is ok, please give us your email address')}
+ {t('Link sent, check your email')}} + > +
{t('Everything is ok, please give us your email address')}
+
    diff --git a/src/stores/auth.ts b/src/stores/auth.ts index 9662ebe8..5b07ad25 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -11,11 +11,15 @@ export const signIn = async (params) => { setToken(authResult.token) console.debug('signed in') } -export const signOut = () => { - // TODO: call backend to revoke token - setSession(null) - resetToken() - console.debug('signed out') +export const signOut = async () => { + const result = await apiClient.authSignOut() + if (result.error) { + console.error('[auth] sign out error', result.error) + } else { + setSession(null) + resetToken() + console.debug('signed out') + } } export const [emailChecks, setEmailChecks] = createSignal<{ [email: string]: boolean }>({}) From 92e5ec0b5337a32bfc1b25524c4c46055107aa1f Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 2 Nov 2022 13:28:29 +0300 Subject: [PATCH 03/55] update-schema --- src/graphql/types.gen.ts | 61 +++++++++++++++------------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 5b233587..a8191d36 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -35,25 +35,19 @@ export type Chat = { createdBy: User description?: Maybe id: Scalars['Int'] - messages?: Maybe>> + messages: Array> title?: Maybe + unread?: Maybe updatedAt: Scalars['DateTime'] users: Array> } -export type ChatResult = { - createdAt: Scalars['DateTime'] - createdBy?: Maybe - error?: Maybe - members: Array> - messages?: Maybe>> - title?: Maybe -} - -export type ChatUpdatedResult = { - error?: Maybe - message?: Maybe - status?: Maybe +export type ChatMember = { + invitedAt?: Maybe + invitedBy?: Maybe + name: Scalars['String'] + pic?: Maybe + slug: Scalars['String'] } export type Collab = { @@ -95,17 +89,6 @@ export type CommunityInput = { title: Scalars['String'] } -export type CreateChatResult = { - chatId?: Maybe - error?: Maybe -} - -export type EnterChatResult = { - chat?: Maybe - error?: Maybe - messages?: Maybe>> -} - export enum FollowingEntity { Author = 'AUTHOR', Community = 'COMMUNITY', @@ -116,17 +99,12 @@ export enum FollowingEntity { export type Message = { author: Scalars['String'] body: Scalars['String'] - chatRoom: Scalars['Int'] + chatId: Scalars['Int'] createdAt: Scalars['DateTime'] id: Scalars['Int'] replyTo?: Maybe updatedAt: Scalars['DateTime'] - visibleForUsers: Array> -} - -export type MessageResult = { - error?: Maybe - message?: Maybe + visibleForUsers?: Maybe>> } export enum MessageStatus { @@ -137,10 +115,10 @@ export enum MessageStatus { export type Mutation = { confirmEmail: AuthResult - createChat: CreateChatResult + createChat: Chat createCollection: Result createCommunity: Result - createMessage: MessageResult + createMessage: Result createReaction: Result createShout: Result createTopic: Result @@ -163,7 +141,7 @@ export type Mutation = { unfollow: Result updateCollection: Result updateCommunity: Result - updateMessage: MessageResult + updateMessage: Result updateProfile: Result updateReaction: Result updateShout: Result @@ -171,7 +149,7 @@ export type Mutation = { } export type MutationConfirmEmailArgs = { - code: Scalars['String'] + token: Scalars['String'] } export type MutationCreateChatArgs = { @@ -335,7 +313,7 @@ export type ProfileInput = { export type Query = { authorsAll: Array> collectionsAll: Array> - enterChat: ChatResult + enterChat: Chat getCollabs: Array> getCommunities: Array> getCommunity: Community @@ -346,7 +324,7 @@ export type Query = { isEmailUsed: Scalars['Boolean'] loadChat: Array> markdownBody: Scalars['String'] - myChats: Array> + myChats: Array> reactionsByAuthor: Array> reactionsForShouts: Array> recentAll: Array> @@ -619,9 +597,14 @@ export type Resource = { export type Result = { author?: Maybe authors?: Maybe>> + chat?: Maybe + chats?: Maybe>> communities?: Maybe>> community?: Maybe error?: Maybe + members?: Maybe>> + message?: Maybe + messages?: Maybe>> reaction?: Maybe reactions?: Maybe>> shout?: Maybe @@ -686,7 +669,7 @@ export type Stat = { } export type Subscription = { - chatUpdated: ChatUpdatedResult + chatUpdated: Result onlineUpdated: Array reactionUpdated: ReactionUpdating shoutUpdated: Shout From 6b53746c5f80317e850e2c90b32f8282ce4476c6 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 2 Nov 2022 16:44:00 +0300 Subject: [PATCH 04/55] fixed-api --- .../query/{my-chats.ts => im-chats.ts} | 1 - src/graphql/query/im-load-messages.ts | 13 +++++ src/graphql/types.gen.ts | 49 ++++++++++++------- src/pages/inbox.astro | 2 +- src/utils/apiClient.ts | 17 ++++++- 5 files changed, 59 insertions(+), 23 deletions(-) rename src/graphql/query/{my-chats.ts => im-chats.ts} (95%) create mode 100644 src/graphql/query/im-load-messages.ts diff --git a/src/graphql/query/my-chats.ts b/src/graphql/query/im-chats.ts similarity index 95% rename from src/graphql/query/my-chats.ts rename to src/graphql/query/im-chats.ts index 043eab0b..993da387 100644 --- a/src/graphql/query/my-chats.ts +++ b/src/graphql/query/im-chats.ts @@ -4,7 +4,6 @@ export default gql` query GetChatsQuery { myChats { messages { - chatId id author body diff --git a/src/graphql/query/im-load-messages.ts b/src/graphql/query/im-load-messages.ts new file mode 100644 index 00000000..0e2be8f7 --- /dev/null +++ b/src/graphql/query/im-load-messages.ts @@ -0,0 +1,13 @@ +import { gql } from '@urql/core' + +export default gql` + query LoadMessagesQuery($chatId: String!, $offset: Int, $amount: Int) { + loadChat(chatId: $chatId, offset: $offset, amount: $amount) { + id + title + desc + slug + amount + } + } +` diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index a8191d36..7f93f85e 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -31,17 +31,23 @@ export type Author = { } export type Chat = { - createdAt: Scalars['DateTime'] + createdAt: Scalars['Int'] createdBy: User description?: Maybe id: Scalars['Int'] messages: Array> title?: Maybe unread?: Maybe - updatedAt: Scalars['DateTime'] + updatedAt: Scalars['Int'] users: Array> } +export type ChatInput = { + description?: InputMaybe + id: Scalars['String'] + title?: InputMaybe +} + export type ChatMember = { invitedAt?: Maybe invitedBy?: Maybe @@ -99,12 +105,11 @@ export enum FollowingEntity { export type Message = { author: Scalars['String'] body: Scalars['String'] - chatId: Scalars['Int'] - createdAt: Scalars['DateTime'] + chatId: Scalars['String'] + createdAt: Scalars['Int'] id: Scalars['Int'] replyTo?: Maybe - updatedAt: Scalars['DateTime'] - visibleForUsers?: Maybe>> + updatedAt?: Maybe } export enum MessageStatus { @@ -115,7 +120,7 @@ export enum MessageStatus { export type Mutation = { confirmEmail: AuthResult - createChat: Chat + createChat: Result createCollection: Result createCommunity: Result createMessage: Result @@ -128,6 +133,7 @@ export type Mutation = { deleteReaction: Result deleteShout: Result destroyTopic: Result + enterChat: Result follow: Result incrementView: Result inviteAuthor: Result @@ -139,6 +145,7 @@ export type Mutation = { removeAuthor: Result sendLink: Result unfollow: Result + updateChat: Result updateCollection: Result updateCommunity: Result updateMessage: Result @@ -153,7 +160,8 @@ export type MutationConfirmEmailArgs = { } export type MutationCreateChatArgs = { - description?: InputMaybe + members: Array> + title?: InputMaybe } export type MutationCreateCollectionArgs = { @@ -207,6 +215,10 @@ export type MutationDestroyTopicArgs = { slug: Scalars['String'] } +export type MutationEnterChatArgs = { + chatId: Scalars['String'] +} + export type MutationFollowArgs = { slug: Scalars['String'] what: FollowingEntity @@ -257,6 +269,10 @@ export type MutationUnfollowArgs = { what: FollowingEntity } +export type MutationUpdateChatArgs = { + chat: ChatInput +} + export type MutationUpdateCollectionArgs = { collection: CollectionInput } @@ -313,7 +329,6 @@ export type ProfileInput = { export type Query = { authorsAll: Array> collectionsAll: Array> - enterChat: Chat getCollabs: Array> getCommunities: Array> getCommunity: Community @@ -356,10 +371,6 @@ export type Query = { userReactedShouts: Array> } -export type QueryEnterChatArgs = { - chatId: Scalars['String'] -} - export type QueryGetCommunityArgs = { slug?: InputMaybe } @@ -385,9 +396,9 @@ export type QueryIsEmailUsedArgs = { } export type QueryLoadChatArgs = { + amount?: InputMaybe chatId: Scalars['String'] - page: Scalars['Int'] - size: Scalars['Int'] + offset?: InputMaybe } export type QueryMarkdownBodyArgs = { @@ -657,7 +668,7 @@ export type ShoutInput = { topic_slugs?: InputMaybe>> versionOf?: InputMaybe visibleForRoles?: InputMaybe>> - visibleForUsers?: InputMaybe>> + visibleForUsers?: InputMaybe>> } export type Stat = { @@ -669,15 +680,15 @@ export type Stat = { } export type Subscription = { - chatUpdated: Result + newMessage: Message onlineUpdated: Array reactionUpdated: ReactionUpdating shoutUpdated: Shout userUpdated: User } -export type SubscriptionChatUpdatedArgs = { - chatId: Scalars['String'] +export type SubscriptionNewMessageArgs = { + chats?: InputMaybe> } export type SubscriptionReactionUpdatedArgs = { diff --git a/src/pages/inbox.astro b/src/pages/inbox.astro index 8e7abf67..74db702d 100644 --- a/src/pages/inbox.astro +++ b/src/pages/inbox.astro @@ -4,7 +4,7 @@ import { Root } from '../components/Root' import { apiClient } from '../utils/apiClient' import { initRouter } from '../stores/router' -const chatrooms = await apiClient.getInboxes() +const chatrooms = await apiClient.getChats() const { pathname, search } = Astro.url initRouter(pathname, search) diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 670d7b8d..9a52d77f 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -27,7 +27,8 @@ import reactionDestroy from '../graphql/mutation/reaction-destroy' import reactionUpdate from '../graphql/mutation/reaction-update' import authorsBySlugs from '../graphql/query/authors-by-slugs' import incrementView from '../graphql/mutation/increment-view' -import myChats from '../graphql/query/my-chats' +import myChats from '../graphql/query/im-chats' +import loadChat from '../graphql/query/im-load-messages' const FEED_SIZE = 50 @@ -325,8 +326,20 @@ export const apiClient = { incrementView: async ({ articleSlug }) => { await privateGraphQLClient.mutation(incrementView, { shout: articleSlug }) }, - getInboxes: async (payload = {}) => { + 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 } } From b8ff05f70afd12f47eea3d09275568b6292961ad Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 2 Nov 2022 16:51:57 +0300 Subject: [PATCH 05/55] fix-query --- src/graphql/query/im-chats.ts | 2 +- src/graphql/query/im-load-messages.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/graphql/query/im-chats.ts b/src/graphql/query/im-chats.ts index 993da387..a87f7b34 100644 --- a/src/graphql/query/im-chats.ts +++ b/src/graphql/query/im-chats.ts @@ -13,7 +13,7 @@ export default gql` users { slug name - pic + userpic } title createdAt diff --git a/src/graphql/query/im-load-messages.ts b/src/graphql/query/im-load-messages.ts index 0e2be8f7..d9ae1404 100644 --- a/src/graphql/query/im-load-messages.ts +++ b/src/graphql/query/im-load-messages.ts @@ -3,11 +3,11 @@ import { gql } from '@urql/core' export default gql` query LoadMessagesQuery($chatId: String!, $offset: Int, $amount: Int) { loadChat(chatId: $chatId, offset: $offset, amount: $amount) { - id - title - desc - slug - amount + author + body + createdAt + updatedAt + seen } } ` From 2142837d34f366f6159689a1ecbbd1a5afca8370 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Thu, 3 Nov 2022 09:07:57 +0300 Subject: [PATCH 06/55] fix-queries --- src/graphql/query/im-chats.ts | 30 +++++++++++++++------------ src/graphql/query/im-load-messages.ts | 13 +++++++----- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/graphql/query/im-chats.ts b/src/graphql/query/im-chats.ts index a87f7b34..1fb48553 100644 --- a/src/graphql/query/im-chats.ts +++ b/src/graphql/query/im-chats.ts @@ -3,20 +3,24 @@ import { gql } from '@urql/core' export default gql` query GetChatsQuery { myChats { - messages { - id - author - body - replyTo - createdAt + error + chats { + title + description + updatedAt + messages { + id + author + body + replyTo + createdAt + } + users { + slug + name + userpic + } } - users { - slug - name - userpic - } - title - createdAt } } ` diff --git a/src/graphql/query/im-load-messages.ts b/src/graphql/query/im-load-messages.ts index d9ae1404..ec3b83bf 100644 --- a/src/graphql/query/im-load-messages.ts +++ b/src/graphql/query/im-load-messages.ts @@ -3,11 +3,14 @@ import { gql } from '@urql/core' export default gql` query LoadMessagesQuery($chatId: String!, $offset: Int, $amount: Int) { loadChat(chatId: $chatId, offset: $offset, amount: $amount) { - author - body - createdAt - updatedAt - seen + error + messages { + author + body + createdAt + updatedAt + seen + } } } ` From cd6b0b8b74f2073734b8dd750e9be19ccbd84e78 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Wed, 9 Nov 2022 15:20:13 +0300 Subject: [PATCH 07/55] init chat logic --- src/components/Pages/HomePage.tsx | 3 +- src/components/Views/Inbox.tsx | 169 ++++++++++++++++++++---------- src/styles/Inbox.scss | 24 +++-- 3 files changed, 136 insertions(+), 60 deletions(-) diff --git a/src/components/Pages/HomePage.tsx b/src/components/Pages/HomePage.tsx index 392280bb..77896108 100644 --- a/src/components/Pages/HomePage.tsx +++ b/src/components/Pages/HomePage.tsx @@ -5,7 +5,7 @@ import { createSignal, onCleanup, onMount, Show } from 'solid-js' import { loadPublishedArticles, resetSortedArticles } from '../../stores/zine/articles' import { loadRandomTopics } from '../../stores/zine/topics' import { Loading } from '../Loading' - +import { InboxView } from '../Views/Inbox' export const HomePage = (props: PageProps) => { const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeArticles) && Boolean(props.randomTopics)) @@ -25,6 +25,7 @@ export const HomePage = (props: PageProps) => { return ( }> + diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 47b67d91..f970c3e1 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -1,14 +1,93 @@ +import { For, createSignal, Show, onMount } from 'solid-js' import type { Author } from '../../graphql/types.gen' import { AuthorCard } from '../Author/Card' import { Icon } from '../Nav/Icon' +import { Loading } from '../Loading' import '../../styles/Inbox.scss' +// Для моков +import { createClient } from '@urql/core' + +const OWNER_ID = '501' +const client = createClient({ + url: 'https://graphqlzero.almansi.me/api' +}) // interface InboxProps { // chats?: Chat[] // messages?: Message[] // } +const [messages, setMessages] = createSignal([]) +const [postMessageText, setPostMessageText] = createSignal('') +const [loading, setLoading] = createSignal(false) + +const messageQuery = ` +query Comments ($options: PageQueryOptions) { + comments(options: $options) { + data { + id + body + email + } + } +} +` + +const newMessageQuery = ` +mutation postComment($messageBody: String!) { + createComment( + input: { body: $messageBody, email: "test@test.com", name: "User" } + ) { + id + body + name + email + } +} +` +const fetchMessages = async (query) => { + const response = await client + .query(query, { + options: { slice: { start: 0, end: 3 } } + }) + .toPromise() + if (response.error) console.debug('getMessages', response.error) + setMessages(response.data.comments.data) +} + +const postMessage = async (msg: string) => { + const response = await client.mutation(newMessageQuery, { messageBody: msg }).toPromise() + return response.data.createComment +} + +let chatWindow +onMount(() => { + setLoading(true) + fetchMessages(messageQuery) + .then(() => { + setLoading(false) + chatWindow.scrollTop = chatWindow.scrollHeight + }) + .catch(() => setLoading(false)) +}) export const InboxView = () => { + const handleSubmit = async () => { + postMessage(postMessageText()) + .then((result) => { + setMessages((prev) => [...prev, result]) + }) + .then(() => { + setPostMessageText('') + chatWindow.scrollTop = chatWindow.scrollHeight + console.log('!!! msg:', messages()) + }) + } + + const handleChangeMessage = (event) => { + setPostMessageText(event.target.value) + console.log('!!! asd:', postMessageText().trim().length) + } + // TODO: get user session return (
    @@ -37,13 +116,6 @@ export const InboxView = () => {
      -
    • - -
      12:15
      -
      - Lorem ipsum dolor sit amet, consectetur adipisicing elit. -
      -
    • 19:48
      @@ -64,59 +136,50 @@ export const InboxView = () => {
    -
    -
    -
    - Круто, беру в оборот! -
    - +
    + + + + + {(comment: { body: string; id: string; email: string }) => ( +
    +
    + {comment.body} +
    + + {comment.email} id: {comment.id} +
    + +
    - -
    -
    + )} + -
    -
    - Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut beatae earum iste itaque - libero perspiciatis possimus quod! Accusamus, aliquam amet consequuntur debitis dolorum - esse laudantium magni omnis rerum voluptatem voluptates! -
    - - Отредактировано -
    - -
    -
    - -
    - -
    - -
    -
    - Нужна грамотная инфраструктура для сообщений, если ожидается нагрузка - надо опираться на - это. Но в целом это несложно сделать. -
    - -
    - -
    -
    + {/*
    */} + {/* */} + {/*
    */}
    - - -