Skip to content

Commit

Permalink
Merge pull request #412 from dappforce/fix/profile-chat-getting
Browse files Browse the repository at this point in the history
Fix getting profile chat after changing space fetching
  • Loading branch information
olehmell authored Apr 22, 2024
2 parents b614f57 + 1673b88 commit e850e82
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/components/activity/AccountActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useIsMySpace } from '../spaces/helpers'
import { CreatePostButton } from '../spaces/helpers/CreatePostButton'
import { FollowerCanPostAlert } from '../spaces/permissions/FollowerCanPostAlert'
import { useSubsocialApi } from '../substrate'
import { Loading } from '../utils'
import { getCreatorChatIdFromProfile, Loading } from '../utils'
import { createLoadMorePosts, FeedActivities } from './FeedActivities'
import { OnchainAccountActivity } from './OnchainAccountActivity'
import { SpaceActivities } from './SpaceActivities'
Expand Down Expand Up @@ -147,7 +147,7 @@ const OffchainAccountActivity = ({

const space = useSelectSpace(spaceId)

const chatId = (space?.content?.chats as any[])?.[0]?.id as string | undefined
const chatId = getCreatorChatIdFromProfile(space)

useFetchPosts(chatId ? [chatId] : [])

Expand Down
17 changes: 8 additions & 9 deletions src/components/chat/ChatButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEmptyArray } from '@subsocial/utils'
import { useFetchPosts, useSelectPost, useSelectSpace } from 'src/rtk/app/hooks'
import { getCreatorChatIdFromProfile } from '../utils'
import CreateChatModalButton from './CreateChatModal'
import UnhideChatButton from './UnhideChatButton'

Expand All @@ -12,20 +12,19 @@ const ChatButton = ({ spaceId }: ChatButtonProps) => {

const spaceContent = space?.content

const chats = spaceContent?.chats
const chat = chats?.[0]
const chatId = getCreatorChatIdFromProfile(space)

useFetchPosts(chat ? [chat?.id] : [])
useFetchPosts(chatId ? [chatId] : [])

const post = useSelectPost(chat?.id)
const chat = useSelectPost(chatId)

const isPostHidden = !!post?.post.struct.hidden
const isRemovedPost = !post?.post.struct.spaceId
const isPostHidden = !!chat?.post.struct.hidden
const isRemovedPost = !chat?.post.struct.spaceId

if (chat && post && spaceContent && !isEmptyArray(chats) && !isPostHidden) return null
if (chatId && chat && spaceContent && !isPostHidden) return null

return isPostHidden && !isRemovedPost ? (
<UnhideChatButton post={post?.post?.struct} />
<UnhideChatButton post={chat?.post?.struct} />
) : (
<CreateChatModalButton spaceId={spaceId} />
)
Expand Down
7 changes: 4 additions & 3 deletions src/components/profiles/address-views/ProfilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, Col, Row } from 'antd'
import clsx from 'clsx'
import dynamic from 'next/dynamic'
import React, { FC } from 'react'
import { getCreatorChatIdFromProfile } from 'src/components/utils'
import { Pluralize } from 'src/components/utils/Plularize'
import { LARGE_AVATAR_SIZE } from 'src/config/Size.config'
import {
Expand Down Expand Up @@ -91,11 +92,11 @@ export const ProfilePreviewPopup: FC<ProfilePreviewProps> = props => {
const sendEvent = useSendEvent()
const profile = useSelectProfile(address.toString())

const chat = profile?.content?.chats?.[0]
const chatId = getCreatorChatIdFromProfile(profile)

useFetchPosts(chat ? [chat.id] : [])
useFetchPosts(chatId ? [chatId] : [])

const post = useSelectPost(chat?.id)
const post = useSelectPost(chatId)

const onOpenChatClick = () => {
if (!post) return
Expand Down

0 comments on commit e850e82

Please sign in to comment.