Skip to content

Commit

Permalink
Add fix for profile posts list modal
Browse files Browse the repository at this point in the history
  • Loading branch information
samchuk-vlad committed Jul 10, 2024
1 parent 947e668 commit 2f2e2a0
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 229 deletions.
34 changes: 14 additions & 20 deletions src/components/ProfilePreviewModalWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useProfilePostsModal } from '@/stores/profile-posts-modal'
import { cx } from '@/utils/class-names'
import { useState } from 'react'
import Name, { NameProps } from './Name'
import ProfilePreview from './ProfilePreview'
import ProfilePostsListModalWrapper from './chats/ChatItem/profilePosts/ProfileProstsListModal'
import Modal from './modals/Modal'

export type ProfilePreviewModalWrapperProps = {
Expand Down Expand Up @@ -49,26 +49,20 @@ export function ProfilePreviewModalName({
hubId: string
enableProfileModal?: boolean
}) {
const { openModal } = useProfilePostsModal()

return (
<ProfilePostsListModalWrapper
<Name
{...props}
onClick={(e) => {
if (enableProfileModal) {
e.preventDefault()
openModal({ messageId, chatId, hubId, address: props.address })
props.onClick?.(e)
}
}}
className={cx('cursor-pointer', props.className)}
address={props.address}
messageId={messageId}
chatId={chatId}
hubId={hubId}
>
{(onClick) => (
<Name
{...props}
onClick={(e) => {
if (enableProfileModal) {
onClick(e)
props.onClick?.(e)
}
}}
className={cx('cursor-pointer', props.className)}
address={props.address}
/>
)}
</ProfilePostsListModalWrapper>
/>
)
}
27 changes: 12 additions & 15 deletions src/components/chats/ChatItem/ChatItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import AddressAvatar from '@/components/AddressAvatar'
import { useProfilePostsModal } from '@/stores/profile-posts-modal'
import { cx } from '@/utils/class-names'
import { PostData } from '@subsocial/api/types'
import { ComponentProps } from 'react'
import { ScrollToMessage } from '../ChatList/hooks/useScrollToMessage'
import ChatItemMenus from './ChatItemMenus'
import ChatItemWithExtension from './ChatItemWithExtension'
import Embed, { useCanRenderEmbed } from './Embed'
import ProfilePostsListModalWrapper from './profilePosts/ProfileProstsListModal'
import DefaultChatItem from './variants/DefaultChatItem'
import EmojiChatItem, {
shouldRenderEmojiChatItem,
Expand Down Expand Up @@ -40,6 +40,7 @@ export default function ChatItem({
}: ChatItemProps) {
const { ownerId, id: messageId } = message.struct
const { body, extensions, link } = message.content || {}
const { openModal } = useProfilePostsModal()

const canRenderEmbed = useCanRenderEmbed(link ?? '')

Expand All @@ -61,20 +62,17 @@ export default function ChatItem({
)}
>
{!isMyMessage && (
<ProfilePostsListModalWrapper
<AddressAvatar
onClick={(e) => {
e.preventDefault()

if (enableProfileModal) {
openModal({ chatId, hubId, messageId, address: ownerId })
}
}}
address={ownerId}
chatId={chatId}
hubId={hubId}
messageId={messageId}
>
{(onClick) => (
<AddressAvatar
onClick={enableProfileModal ? onClick : undefined}
address={ownerId}
className='flex-shrink-0 cursor-pointer'
/>
)}
</ProfilePostsListModalWrapper>
className='flex-shrink-0 cursor-pointer'
/>
)}
<ChatItemMenus
chatId={chatId}
Expand All @@ -92,7 +90,6 @@ export default function ChatItem({
e.preventDefault()
toggleDisplay?.(e)
}}
// onDoubleClick={() => setMessageAsReply()}
{...referenceProps}
id={messageBubbleId}
>
Expand Down
99 changes: 2 additions & 97 deletions src/components/chats/ChatItem/ChatItemMenus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export default function ChatItemMenus({
hubId,
enableChatMenu = true,
}: ChatItemMenusProps) {
// const canSendMessage = useCanSendMessage(hubId, chatId)
const myAddress = useMyMainAddress()

const isOpen = useChatMenu((state) => state.openedChatId === messageId)
Expand All @@ -71,26 +70,14 @@ export default function ChatItemMenus({

const { data: post } = getPostQuery.useQuery(messageId)
const ownerId = post?.struct.ownerId ?? ''
const { ref, inView } = useInView({ triggerOnce: true })
// const { evmAddress } = useLinkedEvmAddress(ownerId, { enabled: inView })
// const refSearchParam = useReferralSearchParam()
const { ref } = useInView({ triggerOnce: true })

// const router = useRouter()

// const address = useMyMainAddress()
const { data: message } = getPostQuery.useQuery(messageId)
const [modalState, setModalState] = useState<ModalState>(null)

const { mutate: moderate } = useModerateWithSuccessToast(messageId, chatId)

const sendEvent = useSendEvent()
// const openDonateExtension = useOpenDonateExtension(
// message?.id,
// message?.struct.ownerId ?? ''
// )

// const setReplyTo = useMessageData((state) => state.setReplyTo)
// const setMessageToEdit = useMessageData((state) => state.setMessageToEdit)

const { isAuthorized } = useAuthorizedForModeration(chatId)
const { data: reasons } = getModerationReasonsQuery.useQuery(null)
Expand All @@ -102,40 +89,7 @@ export default function ChatItemMenus({

const pinUnpinMenu = usePinUnpinMenuItem(chatId, messageId)
const getChatMenus = (): FloatingMenusProps['menus'] => {
const menus: FloatingMenusProps['menus'] = [
// {
// text: 'Copy Text',
// icon: MdContentCopy,
// onClick: () => {
// copyToClipboard(message?.content?.body ?? '')
// toast.custom((t) => (
// <Toast t={t} title='Message copied to clipboard!' />
// ))
// },
// },
// {
// text: 'Copy Message Link',
// icon: FiLink,
// onClick: () => {
// const messageLink = urlJoin(
// getCurrentUrlOrigin(),
// env.NEXT_PUBLIC_BASE_PATH,
// '/message',
// `/${messageId}`,
// refSearchParam
// )
// copyToClipboard(messageLink)
// toast.custom((t) => (
// <Toast t={t} title='Message link copied to clipboard!' />
// ))
// },
// },
// {
// text: 'Show Metadata',
// icon: RiDatabase2Line,
// onClick: () => setModalState('metadata'),
// },
]
const menus: FloatingMenusProps['menus'] = []

const hideMenu: FloatingMenusProps['menus'][number] = {
text: 'Hide',
Expand Down Expand Up @@ -191,56 +145,7 @@ export default function ChatItemMenus({

if (isOptimisticMessage) return menus

// const donateMenuItem: FloatingMenusProps['menus'][number] = {
// text: 'Donate',
// icon: RiCopperCoinLine,
// onClick: () => {
// sendEventWithRef(myAddress ?? '', (refId) => {
// sendEvent('click_donate', { postId: messageId }, { ref: refId })
// })
// if (!address) {
// useLoginModal.getState().setIsOpen(true)
// return
// }

// sendEvent('open_donate_action_modal', { hubId, chatId })
// openDonateExtension()
// },
// }
// const replyItem: FloatingMenusProps['menus'][number] = {
// text: 'Reply',
// icon: LuReply,
// onClick: () => {
// sendEventWithRef(myAddress ?? '', (refId) => {
// sendEvent(
// 'click_reply',
// {
// eventSource: 'message_menu',
// postId: messageId,
// },
// { ref: refId }
// )
// })
// setReplyTo(messageId)
// },
// }
// const editItem: FloatingMenusProps['menus'][number] = {
// text: 'Edit',
// icon: LuPencil,
// onClick: () => setMessageToEdit(messageId),
// }
// const showDonateMenuItem = canSendMessage && !isMessageOwner && evmAddress

// if (showDonateMenuItem) menus.unshift(donateMenuItem)
if (pinUnpinMenu) menus.unshift(pinUnpinMenu)
// if (canSendMessage && isMessageOwner) menus.unshift(editItem)
// if (message)
// menus.unshift({
// text: 'Share',
// icon: GrShareOption,
// submenus: getShareMessageMenus(message),
// })
// if (canSendMessage) menus.unshift(replyItem)

return menus
}
Expand Down
Loading

0 comments on commit 2f2e2a0

Please sign in to comment.