inbox-hitfixes

This commit is contained in:
tonyrewin 2022-12-02 14:11:45 +03:00
parent cc87a21b46
commit 8be277c602
8 changed files with 51 additions and 43 deletions

View File

@ -6,7 +6,10 @@ import type { Author } from '../../graphql/types.gen'
import { hideModal } from '../../stores/ui' import { hideModal } from '../../stores/ui'
import { useInbox } from '../../context/inbox' import { useInbox } from '../../context/inbox'
type inviteUser = Author & { selected: boolean } type InvitingUser = Author & {
selected: boolean
}
type query = type query =
| { | {
theme: string theme: string
@ -18,40 +21,41 @@ type Props = {
} }
const CreateModalContent = (props: Props) => { const CreateModalContent = (props: Props) => {
const inviteUsers: inviteUser[] = props.users.map((user) => ({ ...user, selected: false })) const inviteUsers: InvitingUser[] = props.users.map((user) => ({ ...user, selected: false }))
const [theme, setTheme] = createSignal<string>('') const [title, setTitle] = createSignal<string>('')
const [slugs, setSlugs] = createSignal<string[]>([]) const [uids, setUids] = createSignal<number[]>([])
const [collectionToInvite, setCollectionToInvite] = createSignal<inviteUser[]>(inviteUsers) const [collectionToInvite, setCollectionToInvite] = createSignal<InvitingUser[]>(inviteUsers)
let textInput: HTMLInputElement let textInput: HTMLInputElement
const reset = () => { const reset = () => {
setTheme('') setTitle('')
setSlugs([]) setUids([])
hideModal() hideModal()
} }
createEffect(() => { createEffect(() => {
setSlugs(() => { console.log(collectionToInvite())
setUids(() => {
return collectionToInvite() return collectionToInvite()
.filter((user) => { .filter((user: InvitingUser) => {
return user.selected === true return user.selected === true
}) })
.map((user) => { .map((user: InvitingUser) => {
return user['slug'] return user.id
}) })
}) })
if (slugs().length > 2 && theme().length === 0) { if (uids().length > 1 && title().length === 0) {
setTheme(t('group_chat')) setTitle(t('group_chat'))
} }
}) })
const handleSetTheme = () => { const handleSetTheme = () => {
setTheme(textInput.value.length > 0 && textInput.value) setTitle(textInput.value.length > 0 && textInput.value)
} }
const handleClick = (user) => { const handleClick = (user) => {
setCollectionToInvite((userCollection) => { setCollectionToInvite((userCollection: InvitingUser[]) => {
return userCollection.map((clickedUser) => return userCollection.map((clickedUser: InvitingUser) =>
user.slug === clickedUser.slug ? { ...clickedUser, selected: !clickedUser.selected } : clickedUser user.slug === clickedUser.slug ? { ...clickedUser, selected: !clickedUser.selected } : clickedUser
) )
}) })
@ -63,7 +67,7 @@ const CreateModalContent = (props: Props) => {
const handleCreate = async () => { const handleCreate = async () => {
try { try {
const initChat = await actions.createChat(slugs(), theme()) const initChat = await actions.createChat(uids(), title())
console.debug('[initChat]', initChat) console.debug('[initChat]', initChat)
} catch (error) { } catch (error) {
console.error(error) console.error(error)
@ -73,7 +77,7 @@ const CreateModalContent = (props: Props) => {
return ( return (
<div class={styles.CreateModalContent}> <div class={styles.CreateModalContent}>
<h4>{t('create_chat')}</h4> <h4>{t('create_chat')}</h4>
{slugs().length > 2 && ( {uids().length > 1 && (
<input <input
ref={textInput} ref={textInput}
onInput={handleSetTheme} onInput={handleSetTheme}
@ -86,7 +90,7 @@ const CreateModalContent = (props: Props) => {
<div class="invite-recipients" style={{ height: '400px', overflow: 'auto' }}> <div class="invite-recipients" style={{ height: '400px', overflow: 'auto' }}>
<For each={collectionToInvite()}> <For each={collectionToInvite()}>
{(author) => ( {(author: InvitingUser) => (
<InviteUser onClick={() => handleClick(author)} author={author} selected={author.selected} /> <InviteUser onClick={() => handleClick(author)} author={author} selected={author.selected} />
)} )}
</For> </For>
@ -100,9 +104,9 @@ const CreateModalContent = (props: Props) => {
type="button" type="button"
class="btn btn-lg fs-3 btn-outline-primary" class="btn btn-lg fs-3 btn-outline-primary"
onClick={handleCreate} onClick={handleCreate}
disabled={slugs().length === 0} disabled={uids().length === 0}
> >
{slugs().length > 2 ? t('create_group') : t('create_chat')} {uids().length > 1 ? t('create_group') : t('create_chat')}
</button> </button>
</div> </div>
</div> </div>

View File

@ -2,29 +2,30 @@ import styles from './DialogCard.module.scss'
import DialogAvatar from './DialogAvatar' import DialogAvatar from './DialogAvatar'
import type { Author, ChatMember, User } from '../../graphql/types.gen' import type { Author, ChatMember, User } from '../../graphql/types.gen'
import { t } from '../../utils/intl' import { t } from '../../utils/intl'
import { Show } from 'solid-js'
import { useSession } from '../../context/session'
type DialogProps = { type DialogProps = {
online?: boolean online?: boolean
message?: string message?: string
counter?: number counter?: number
members: ChatMember[] members: ChatMember[]
ownSlug: User['slug']
} }
const DialogCard = (props: DialogProps) => { const DialogCard = (props: DialogProps) => {
const participants = props.members.filter((m) => m.slug !== props.ownSlug) const { session } = useSession()
const participants = props.members?.filter((m) => m?.id !== session().user.id) || []
console.log('!!! participants:', participants) console.log('!!! participants:', participants)
return ( return (
//DialogCardView - подумать //DialogCardView - подумать
<Show when={participants?.length > 0}>
<div class={styles.DialogCard}> <div class={styles.DialogCard}>
<div class={styles.avatar}> <div class={styles.avatar}>
<DialogAvatar name={participants[0].name} online={props.online} /> <DialogAvatar name={participants[0].name} online={props.online} />
</div> </div>
<div class={styles.row}> <div class={styles.row}>
<div class={styles.name}>{participants[0].name}</div> <div class={styles.name}>{participants[0].name}</div>
<div class={styles.message}> <div class={styles.message}>{t('You can announce your languages in profile')}</div>
Указать предпочтительные языки для результатов поиска можно в разделе
</div>
</div> </div>
<div class={styles.activity}> <div class={styles.activity}>
<div class={styles.time}>22:22</div> <div class={styles.time}>22:22</div>
@ -33,6 +34,7 @@ const DialogCard = (props: DialogProps) => {
</div> </div>
</div> </div>
</div> </div>
</Show>
) )
} }

View File

@ -7,7 +7,7 @@ import { createStore } from 'solid-js/store'
type InboxContextType = { type InboxContextType = {
chatEntities: { [chatId: string]: Message[] } chatEntities: { [chatId: string]: Message[] }
actions: { actions: {
createChat: (members: string[], title: string) => Promise<void> createChat: (members: number[], title: string) => Promise<void>
} }
} }
@ -20,7 +20,7 @@ export function useInbox() {
export const InboxProvider = (props: { children: JSX.Element }) => { export const InboxProvider = (props: { children: JSX.Element }) => {
const [chatEntities, setChatEntities] = createStore({}) const [chatEntities, setChatEntities] = createStore({})
const createChat = async (members: string[], title: string) => { const createChat = async (members: number[], title: string) => {
const chat = await apiClient.createChat({ members, title }) const chat = await apiClient.createChat({ members, title })
setChatEntities((s) => { setChatEntities((s) => {
s[chat.id] = chat s[chat.id] = chat

View File

@ -35,6 +35,7 @@ const useProfileForm = () => {
await loadAuthor({ slug: currentSlug() }) await loadAuthor({ slug: currentSlug() })
setForm({ setForm({
name: currentAuthor()?.name, name: currentAuthor()?.name,
slug: currentAuthor()?.name,
bio: currentAuthor()?.bio, bio: currentAuthor()?.bio,
about: currentAuthor()?.about, about: currentAuthor()?.about,
userpic: currentAuthor()?.userpic, userpic: currentAuthor()?.userpic,

View File

@ -1,7 +1,7 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
mutation CreateChat($title: String, $members: [String]!) { mutation CreateChat($title: String, $members: [Int]!) {
createChat(title: $title, members: $members) { createChat(title: $title, members: $members) {
error error
chat { chat {

View File

@ -32,7 +32,7 @@ const options: ClientOptions = {
// меняем через setToken, например при получении значения с сервера // меняем через setToken, например при получении значения с сервера
// скорее всего придумаем что-нибудь получше со временем // скорее всего придумаем что-нибудь получше со временем
const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY) const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY)
if (token === null) alert('token is null') if (token === null) console.error('[ERROR] token is null')
const headers = { Authorization: token } const headers = { Authorization: token }
return { headers } return { headers }
}, },

View File

@ -4,6 +4,7 @@ export default gql`
query GetChatsQuery($limit: Int, $offset: Int) { query GetChatsQuery($limit: Int, $offset: Int) {
loadRecipients(limit: $limit, offset: $offset) { loadRecipients(limit: $limit, offset: $offset) {
members { members {
id
name name
slug slug
userpic userpic

View File

@ -199,7 +199,7 @@ export type MutationConfirmEmailArgs = {
} }
export type MutationCreateChatArgs = { export type MutationCreateChatArgs = {
members: Array<InputMaybe<Scalars['String']>> members: Array<InputMaybe<Scalars['Int']>>
title?: InputMaybe<Scalars['String']> title?: InputMaybe<Scalars['String']>
} }