Refactoring after backend update
This commit is contained in:
parent
bbabb69555
commit
c124cfc971
|
@ -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:
|
||||
|
|
|
@ -14,28 +14,27 @@ type Props = {
|
|||
const CreateModalContent = (props: Props) => {
|
||||
const inviteUsers: inviteUser[] = props.users.map((user) => ({ ...user, selected: false }))
|
||||
const [theme, setTheme] = createSignal<string>(' ')
|
||||
const [slugs, setSlugs] = createSignal<string[]>([])
|
||||
const [usersId, setUsersId] = createSignal<number[]>([])
|
||||
const [collectionToInvite, setCollectionToInvite] = createSignal<inviteUser[]>(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 (
|
||||
<div class={styles.CreateModalContent}>
|
||||
<h4>{t('create_chat')}</h4>
|
||||
{slugs().length > 1 && (
|
||||
{usersId().length > 1 && (
|
||||
<input
|
||||
ref={textInput}
|
||||
onInput={handleSetTheme}
|
||||
|
@ -95,9 +94,9 @@ const CreateModalContent = (props: Props) => {
|
|||
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')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 (
|
||||
<Show when={props.members}>
|
||||
<div class={clsx(styles.DialogCard, { [styles.header]: props.isChatHeader })} onClick={props.onClick}>
|
||||
|
@ -37,7 +36,7 @@ const DialogCard = (props: DialogProps) => {
|
|||
</div>
|
||||
<div class={styles.row}>
|
||||
<Switch fallback={<div class={styles.name}>{companions()[0].name}</div>}>
|
||||
<Match when={companions().length > 1}>
|
||||
<Match when={companions().length > 2}>
|
||||
<div class={styles.name}>{props.title}</div>
|
||||
</Match>
|
||||
</Switch>
|
||||
|
|
|
@ -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}
|
||||
/>
|
||||
</header>
|
||||
)
|
||||
|
|
|
@ -73,16 +73,16 @@ export const InboxView = () => {
|
|||
const [sortByPerToPer, setSortByPerToPer] = createSignal<boolean>(false)
|
||||
const [selectedChat, setSelectedChat] = createSignal<Chat>()
|
||||
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()}
|
||||
/>
|
||||
)}
|
||||
</For>
|
||||
|
@ -209,7 +212,7 @@ export const InboxView = () => {
|
|||
|
||||
<div class="col-md-8 conversation">
|
||||
<Show when={selectedChat()}>
|
||||
<DialogHeader currentSlug={currentSlug()} chat={selectedChat()} />
|
||||
<DialogHeader ownId={currentUserId()} chat={selectedChat()} />
|
||||
</Show>
|
||||
|
||||
<div class="conversation__messages">
|
||||
|
|
|
@ -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<Chat[]>
|
||||
actions: {
|
||||
createChat: (members: string[], title: string) => Promise<void>
|
||||
createChat: (members: number[], title: string) => Promise<void>
|
||||
loadChats: () => Promise<void>
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -5,6 +5,7 @@ export default gql`
|
|||
loadRecipients(limit: $limit, offset: $offset) {
|
||||
members {
|
||||
name
|
||||
id
|
||||
slug
|
||||
userpic
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ export default gql`
|
|||
title
|
||||
admins
|
||||
members {
|
||||
id
|
||||
slug
|
||||
name
|
||||
userpic
|
||||
|
|
|
@ -84,10 +84,10 @@ export type ChatMember = {
|
|||
|
||||
export type Collab = {
|
||||
authors: Array<Maybe<Scalars['String']>>
|
||||
body?: Maybe<Scalars['String']>
|
||||
createdAt: Scalars['DateTime']
|
||||
chat?: Maybe<Chat>
|
||||
createdAt: Scalars['Int']
|
||||
invites?: Maybe<Array<Maybe<Scalars['String']>>>
|
||||
title?: Maybe<Scalars['String']>
|
||||
shout?: Maybe<Shout>
|
||||
}
|
||||
|
||||
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<InputMaybe<Scalars['String']>>
|
||||
members: Array<InputMaybe<Scalars['Int']>>
|
||||
title?: InputMaybe<Scalars['String']>
|
||||
}
|
||||
|
||||
export type MutationCreateMessageArgs = {
|
||||
body: Scalars['String']
|
||||
chat: Scalars['String']
|
||||
replyTo?: InputMaybe<Scalars['String']>
|
||||
replyTo?: InputMaybe<Scalars['Int']>
|
||||
}
|
||||
|
||||
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<Scalars['String']>
|
||||
}
|
||||
|
||||
export type MutationRemoveAuthorArgs = {
|
||||
export type MutationRemoveCoauthorArgs = {
|
||||
author: Scalars['String']
|
||||
shout: Scalars['String']
|
||||
shout: Scalars['Int']
|
||||
}
|
||||
|
||||
export type MutationSendLinkArgs = {
|
||||
email: Scalars['String']
|
||||
lang?: InputMaybe<Scalars['String']>
|
||||
template?: InputMaybe<Scalars['String']>
|
||||
}
|
||||
|
||||
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<Scalars['String']>
|
||||
bio?: InputMaybe<Scalars['String']>
|
||||
links?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
||||
name?: InputMaybe<Scalars['String']>
|
||||
slug?: InputMaybe<Scalars['String']>
|
||||
userpic?: InputMaybe<Scalars['String']>
|
||||
}
|
||||
|
||||
|
@ -461,7 +469,7 @@ export type Reaction = {
|
|||
old_id?: Maybe<Scalars['String']>
|
||||
old_thread?: Maybe<Scalars['String']>
|
||||
range?: Maybe<Scalars['String']>
|
||||
replyTo?: Maybe<Reaction>
|
||||
replyTo?: Maybe<Scalars['Int']>
|
||||
shout: Shout
|
||||
stat?: Maybe<Stat>
|
||||
updatedAt?: Maybe<Scalars['DateTime']>
|
||||
|
@ -576,13 +584,14 @@ export type Shout = {
|
|||
}
|
||||
|
||||
export type ShoutInput = {
|
||||
authors?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
||||
body: Scalars['String']
|
||||
community: Scalars['String']
|
||||
community?: InputMaybe<Scalars['Int']>
|
||||
mainTopic?: InputMaybe<Scalars['String']>
|
||||
slug: Scalars['String']
|
||||
slug?: InputMaybe<Scalars['String']>
|
||||
subtitle?: InputMaybe<Scalars['String']>
|
||||
title?: InputMaybe<Scalars['String']>
|
||||
topic_slugs?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
||||
topics?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
||||
versionOf?: InputMaybe<Scalars['String']>
|
||||
visibleForRoles?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
||||
visibleForUsers?: InputMaybe<Array<InputMaybe<Scalars['String']>>>
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user