import clsx from 'clsx' import { User } from 'common/user' import { useState } from 'react' import { useUser } from 'web/hooks/use-user' import { withTracking } from 'web/lib/service/analytics' import { Row } from 'web/components/layout/row' import { useMemberGroups, useMemberIds } from 'web/hooks/use-group' import { TextButton } from 'web/components/text-button' import { Group } from 'common/group' import { Modal } from 'web/components/layout/modal' import { Col } from 'web/components/layout/col' import { joinGroup, leaveGroup } from 'web/lib/firebase/groups' import { firebaseLogin } from 'web/lib/firebase/users' import { GroupLinkItem } from 'web/pages/groups' import toast from 'react-hot-toast' import { Button } from '../button' export function GroupsButton(props: { user: User; className?: string }) { const { user, className } = props const [isOpen, setIsOpen] = useState(false) const groups = useMemberGroups(user.id) return ( <> setIsOpen(true)} className={className}> {groups?.length ?? ''} Groups ) } function GroupsDialog(props: { user: User groups: Group[] isOpen: boolean setIsOpen: (isOpen: boolean) => void }) { const { user, groups, isOpen, setIsOpen } = props return (
{user.name}
@{user.username}
) } function GroupsList(props: { groups: Group[] }) { const { groups } = props return ( {groups.length === 0 && (
No groups yet...
)} {groups .sort((group1, group2) => group2.createdTime - group1.createdTime) .map((group) => ( ))} ) } function GroupItem(props: { group: Group; className?: string }) { const { group, className } = props const user = useUser() const memberIds = useMemberIds(group.id) return ( ) } export function JoinOrLeaveGroupButton(props: { group: Group isMember: boolean user: User | undefined | null className?: string }) { const { group, className, isMember, user } = props if (!user) { if (!group.anyoneCanJoin) return
Closed
return ( ) } const onJoinGroup = () => { joinGroup(group, user.id).catch(() => { toast.error('Failed to join group') }) } const onLeaveGroup = () => { leaveGroup(group, user.id).catch(() => { toast.error('Failed to leave group') }) } if (isMember) { return ( ) } if (!group.anyoneCanJoin) return
Closed
return ( ) }