import { createSignal, For, createEffect } from 'solid-js' import styles from './CreateModalContent.module.scss' import InviteUser from './InviteUser' import type { Author } from '../../graphql/types.gen' import { hideModal } from '../../stores/ui' import { useInbox } from '../../context/inbox' import { useLocalize } from '../../context/localize' type inviteUser = Author & { selected: boolean } type Props = { users: Author[] } const CreateModalContent = (props: Props) => { const { t } = useLocalize() const inviteUsers: inviteUser[] = props.users.map((user) => ({ ...user, selected: false })) const [theme, setTheme] = createSignal(' ') const [usersId, setUsersId] = createSignal([]) const [collectionToInvite, setCollectionToInvite] = createSignal(inviteUsers) let textInput: HTMLInputElement const reset = () => { setTheme('') setUsersId([]) hideModal() } createEffect(() => { setUsersId(() => { return collectionToInvite() .filter((user) => { return user.selected === true }) .map((user) => { return user['id'] }) }) if (usersId().length > 1 && theme().length === 1) { setTheme(t('Group Chat')) } }) const handleSetTheme = () => { setTheme(textInput.value.length > 0 && textInput.value) } const handleClick = (user) => { setCollectionToInvite((userCollection) => { return userCollection.map((clickedUser) => user.id === clickedUser.id ? { ...clickedUser, selected: !clickedUser.selected } : clickedUser ) }) } const { actions } = useInbox() const handleCreate = async () => { try { const initChat = await actions.createChat(usersId(), theme()) console.debug('[initChat]', initChat) hideModal() await actions.loadChats() } catch (error) { console.error(error) } } return (

{t('Create Chat')}

{usersId().length > 1 && ( )}
{(author) => ( handleClick(author)} author={author} selected={author.selected} /> )}
) } export default CreateModalContent