diff --git a/codegen.yml b/codegen.yml index 44d1e541..da015e44 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,5 +1,6 @@ overwrite: true -schema: 'http://localhost:8080' +#schema: 'http://localhost:8080' +schema: 'https://v2.discours.io' generates: src/graphql/introspec.gen.ts: plugins: diff --git a/src/components/Inbox/CreateModalContent.tsx b/src/components/Inbox/CreateModalContent.tsx index 6f8146fe..3e0b3054 100644 --- a/src/components/Inbox/CreateModalContent.tsx +++ b/src/components/Inbox/CreateModalContent.tsx @@ -14,28 +14,27 @@ type Props = { const CreateModalContent = (props: Props) => { const inviteUsers: inviteUser[] = props.users.map((user) => ({ ...user, selected: false })) const [theme, setTheme] = createSignal(' ') - const [slugs, setSlugs] = createSignal([]) + const [usersId, setUsersId] = createSignal([]) const [collectionToInvite, setCollectionToInvite] = createSignal(inviteUsers) let textInput: HTMLInputElement const reset = () => { setTheme('') - setSlugs([]) + setUsersId([]) hideModal() } createEffect(() => { - setSlugs(() => { + setUsersId(() => { return collectionToInvite() .filter((user) => { return user.selected === true }) .map((user) => { - return user['slug'] + return user['id'] }) }) - - if (slugs().length > 1 && theme().length === 1) { + if (usersId().length > 1 && theme().length === 1) { setTheme(t('group_chat')) } }) @@ -47,7 +46,7 @@ const CreateModalContent = (props: Props) => { const handleClick = (user) => { setCollectionToInvite((userCollection) => { return userCollection.map((clickedUser) => - user.slug === clickedUser.slug ? { ...clickedUser, selected: !clickedUser.selected } : clickedUser + user.id === clickedUser.id ? { ...clickedUser, selected: !clickedUser.selected } : clickedUser ) }) } @@ -56,7 +55,7 @@ const CreateModalContent = (props: Props) => { const handleCreate = async () => { try { - const initChat = await actions.createChat(slugs(), theme()) + const initChat = await actions.createChat(usersId(), theme()) console.debug('[initChat]', initChat) hideModal() await actions.loadChats() @@ -68,7 +67,7 @@ const CreateModalContent = (props: Props) => { return (

{t('create_chat')}

- {slugs().length > 1 && ( + {usersId().length > 1 && ( { type="button" class="btn btn-lg fs-3 btn-outline-primary" onClick={handleCreate} - disabled={slugs().length === 0} + disabled={usersId().length === 0} > - {slugs().length > 1 ? t('create_group') : t('create_chat')} + {usersId().length > 1 ? t('create_group') : t('create_chat')}
diff --git a/src/components/Inbox/DialogCard.tsx b/src/components/Inbox/DialogCard.tsx index 2a94cd45..41394545 100644 --- a/src/components/Inbox/DialogCard.tsx +++ b/src/components/Inbox/DialogCard.tsx @@ -10,7 +10,7 @@ type DialogProps = { message?: string counter?: number title?: string - ownSlug: string + ownId: number members: ChatMember[] onClick?: () => void isChatHeader?: boolean @@ -18,13 +18,12 @@ type DialogProps = { const DialogCard = (props: DialogProps) => { const companions = createMemo( - () => props.members && props.members.filter((member) => member.slug !== props.ownSlug) - ) - const names = createMemo(() => - companions() - .map((companion) => companion.name) - .join(', ') + () => props.members && props.members.filter((member) => member.id !== props.ownId) ) + const names = companions() + ?.map((companion) => companion.name) + .join(', ') + return (
@@ -37,7 +36,7 @@ const DialogCard = (props: DialogProps) => {
{companions()[0].name}
}> - 1}> + 2}>
{props.title}
diff --git a/src/components/Inbox/DialogHeader.tsx b/src/components/Inbox/DialogHeader.tsx index 7d98d259..7c2ecf17 100644 --- a/src/components/Inbox/DialogHeader.tsx +++ b/src/components/Inbox/DialogHeader.tsx @@ -4,7 +4,7 @@ import DialogCard from './DialogCard' type DialogHeader = { chat: Chat - currentSlug: string + ownId: number } const DialogHeader = (props: DialogHeader) => { @@ -14,7 +14,7 @@ const DialogHeader = (props: DialogHeader) => { isChatHeader={true} title={props.chat.title} members={props.chat.members} - ownSlug={props.currentSlug} + ownId={props.ownId} /> ) diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index b39e7255..b8985a7e 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -73,16 +73,16 @@ export const InboxView = () => { const [sortByPerToPer, setSortByPerToPer] = createSignal(false) const [selectedChat, setSelectedChat] = createSignal() const { session } = useSession() - const currentSlug = createMemo(() => session()?.user?.slug) + const currentUserId = createMemo(() => session()?.user?.id) // Поиск по диалогам const getQuery = (query) => { - if (query().length >= 2) { - const match = userSearch(recipients(), query()) - setRecipients(match) - } else { - setRecipients(cashedRecipients()) - } + // if (query().length >= 2) { + // const match = userSearch(recipients(), query()) + // setRecipients(match) + // } else { + // setRecipients(cashedRecipients()) + // } } let chatWindow @@ -109,7 +109,6 @@ export const InboxView = () => { console.log(error) } await loadChats() - console.log('!!! chats:', chats()) }) const handleSubmit = async () => { @@ -136,6 +135,10 @@ export const InboxView = () => { showModal('inviteToChat') } + createEffect(() => { + console.log('!!! chats():', chats()) + }) + const chatsToShow = () => { if (sortByPerToPer()) { return chats().filter((chat) => chat.title.trim().length === 0) @@ -199,7 +202,7 @@ export const InboxView = () => { onClick={() => handleOpenChat(chat)} title={chat.title} members={chat.members} - ownSlug={currentSlug()} + ownId={currentUserId()} /> )} @@ -209,7 +212,7 @@ export const InboxView = () => {
- +
diff --git a/src/context/inbox.tsx b/src/context/inbox.tsx index f502e24d..d9c445bb 100644 --- a/src/context/inbox.tsx +++ b/src/context/inbox.tsx @@ -2,12 +2,11 @@ import type { Accessor, JSX } from 'solid-js' import { createContext, createSignal, useContext } from 'solid-js' import type { Chat } from '../graphql/types.gen' import { apiClient } from '../utils/apiClient' -import { createStore } from 'solid-js/store' type InboxContextType = { chats: Accessor actions: { - createChat: (members: string[], title: string) => Promise + createChat: (members: number[], title: string) => Promise loadChats: () => Promise } } @@ -33,7 +32,7 @@ export const InboxProvider = (props: { children: JSX.Element }) => { } } - const createChat = async (members: string[], title: string) => { + const createChat = async (members: number[], title: string) => { const chat = await apiClient.createChat({ members, title }) setChats((prevChats) => { return [chat, ...prevChats] diff --git a/src/graphql/mutation/create-chat.ts b/src/graphql/mutation/create-chat.ts index b700707b..46993794 100644 --- a/src/graphql/mutation/create-chat.ts +++ b/src/graphql/mutation/create-chat.ts @@ -1,7 +1,7 @@ import { gql } from '@urql/core' export default gql` - mutation CreateChat($title: String, $members: [String]!) { + mutation CreateChat($title: String, $members: [Int]!) { createChat(title: $title, members: $members) { error chat { diff --git a/src/graphql/query/chat-recipients.ts b/src/graphql/query/chat-recipients.ts index 7acf3588..2feb0081 100644 --- a/src/graphql/query/chat-recipients.ts +++ b/src/graphql/query/chat-recipients.ts @@ -5,6 +5,7 @@ export default gql` loadRecipients(limit: $limit, offset: $offset) { members { name + id slug userpic } diff --git a/src/graphql/query/chats-load.ts b/src/graphql/query/chats-load.ts index 2e2ac02a..b7c4cc48 100644 --- a/src/graphql/query/chats-load.ts +++ b/src/graphql/query/chats-load.ts @@ -9,6 +9,7 @@ export default gql` title admins members { + id slug name userpic diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 39afa866..5dd514cf 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -84,10 +84,10 @@ export type ChatMember = { export type Collab = { authors: Array> - body?: Maybe - createdAt: Scalars['DateTime'] + chat?: Maybe + createdAt: Scalars['Int'] invites?: Maybe>> - title?: Maybe + shout?: Maybe } export type Collection = { @@ -164,6 +164,7 @@ export type MessagesBy = { } export type Mutation = { + acceptCoauthor: Result confirmEmail: AuthResult createChat: Result createMessage: Result @@ -177,11 +178,11 @@ export type Mutation = { destroyTopic: Result follow: Result getSession: AuthResult - inviteAuthor: Result + inviteCoauthor: Result markAsRead: Result rateUser: Result registerUser: AuthResult - removeAuthor: Result + removeCoauthor: Result sendLink: Result unfollow: Result updateChat: Result @@ -193,19 +194,23 @@ export type Mutation = { updateTopic: Result } +export type MutationAcceptCoauthorArgs = { + shout: Scalars['Int'] +} + export type MutationConfirmEmailArgs = { token: Scalars['String'] } export type MutationCreateChatArgs = { - members: Array> + members: Array> title?: InputMaybe } export type MutationCreateMessageArgs = { body: Scalars['String'] chat: Scalars['String'] - replyTo?: InputMaybe + replyTo?: InputMaybe } export type MutationCreateReactionArgs = { @@ -213,7 +218,7 @@ export type MutationCreateReactionArgs = { } export type MutationCreateShoutArgs = { - input: ShoutInput + inp: ShoutInput } export type MutationCreateTopicArgs = { @@ -246,9 +251,9 @@ export type MutationFollowArgs = { what: FollowingEntity } -export type MutationInviteAuthorArgs = { +export type MutationInviteCoauthorArgs = { author: Scalars['String'] - shout: Scalars['String'] + shout: Scalars['Int'] } export type MutationMarkAsReadArgs = { @@ -267,14 +272,15 @@ export type MutationRegisterUserArgs = { password?: InputMaybe } -export type MutationRemoveAuthorArgs = { +export type MutationRemoveCoauthorArgs = { author: Scalars['String'] - shout: Scalars['String'] + shout: Scalars['Int'] } export type MutationSendLinkArgs = { email: Scalars['String'] lang?: InputMaybe + template?: InputMaybe } export type MutationUnfollowArgs = { @@ -301,7 +307,7 @@ export type MutationUpdateReactionArgs = { } export type MutationUpdateShoutArgs = { - input: ShoutInput + inp: ShoutInput } export type MutationUpdateTopicArgs = { @@ -320,14 +326,16 @@ export type Operation = { } export type Permission = { - operation_id: Scalars['Int'] - resource_id: Scalars['Int'] + operation: Scalars['Int'] + resource: Scalars['Int'] } export type ProfileInput = { + about?: InputMaybe bio?: InputMaybe links?: InputMaybe>> name?: InputMaybe + slug?: InputMaybe userpic?: InputMaybe } @@ -461,7 +469,7 @@ export type Reaction = { old_id?: Maybe old_thread?: Maybe range?: Maybe - replyTo?: Maybe + replyTo?: Maybe shout: Shout stat?: Maybe updatedAt?: Maybe @@ -576,13 +584,14 @@ export type Shout = { } export type ShoutInput = { + authors?: InputMaybe>> body: Scalars['String'] - community: Scalars['String'] + community?: InputMaybe mainTopic?: InputMaybe - slug: Scalars['String'] + slug?: InputMaybe subtitle?: InputMaybe title?: InputMaybe - topic_slugs?: InputMaybe>> + topics?: InputMaybe>> versionOf?: InputMaybe visibleForRoles?: InputMaybe>> visibleForUsers?: InputMaybe>> diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index eee44d50..562feed5 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -289,7 +289,7 @@ export const apiClient = { getChatMessages: async (options: QueryLoadMessagesByArgs) => { const resp = await privateGraphQLClient.query(chatMessagesLoadBy, options).toPromise() console.log('!!! resp:', resp) - // return resp.data.loadChat + return resp.data.loadChat }, getRecipients: async (options: QueryLoadRecipientsArgs) => {