Skip to content

Commit

Permalink
Fix link preview not showing (#461)
Browse files Browse the repository at this point in the history
* Fix link preview not showing

* Only render link preview if link metadata is filled

* Fix create chat issue
  • Loading branch information
teodorus-nathaniel authored Nov 8, 2023
1 parent e8881c6 commit faab073
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 70 deletions.
2 changes: 1 addition & 1 deletion src/components/chats/ChatItem/variants/DefaultChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function DefaultChatItem({
{body}
</Linkify>
</p>
{link && (
{link && linkMetadata?.title && (
<LinkPreview
renderNullIfLinkEmbedable
className={cx('my-1')}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/[hubId]/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ async function getMessageIdsFromDatahub(client: QueryClient, chatId: string) {
chatId
)
getPaginatedPostsByPostIdFromDatahubQuery.invalidateFirstQuery(client, chatId)
const messages = await getPostsServer(res.data)

return { messageIds: res.data, messages: res.messages }
return { messageIds: res.data, messages }
}
async function getMessageIdsFromChain(client: QueryClient, chatId: string) {
const messageIds = await getCommentIdsByPostIdFromChainQuery.fetchQuery(
Expand Down
56 changes: 0 additions & 56 deletions src/services/subsocial/datahub/generated-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,60 +618,6 @@ export type GetCommentIdsInPostIdQuery = {
id: string
persistentId?: string | null
optimisticId?: string | null
dataType: DataType
content?: string | null
createdAtBlock?: number | null
createdAtTime?: any | null
title?: string | null
body?: string | null
summary?: string | null
isShowMore: boolean
image?: string | null
link?: string | null
hidden: boolean
blockchainSyncFailed: boolean
isComment: boolean
kind: PostKind
updatedAtTime?: any | null
canonical?: string | null
tagsOriginal?: string | null
followersCount?: number | null
inReplyToKind?: InReplyToKind | null
createdByAccount: { __typename?: 'Account'; id: string }
ownedByAccount: { __typename?: 'Account'; id: string }
space?: { __typename?: 'Space'; persistentId?: string | null } | null
rootPost?: {
__typename?: 'Post'
persistentId?: string | null
space?: { __typename?: 'Space'; persistentId?: string | null } | null
} | null
inReplyToPost?: {
__typename?: 'Post'
persistentId?: string | null
} | null
extensions: Array<{
__typename?: 'ContentExtension'
image?: string | null
amount?: string | null
chain?: string | null
collectionId?: string | null
decimals?: number | null
extensionSchemaId: ContentExtensionSchemaId
id: string
nftId?: string | null
token?: string | null
txHash?: string | null
message?: string | null
nonce?: string | null
url?: string | null
recipient?: { __typename?: 'Account'; id: string } | null
fromEvm?: { __typename?: 'EvmAccount'; id: string } | null
toEvm?: { __typename?: 'EvmAccount'; id: string } | null
pinnedResources?: Array<{
__typename?: 'ExtensionPinnedResource'
post?: { __typename?: 'Post'; id: string } | null
}> | null
}>
}>
}
}
Expand Down Expand Up @@ -825,12 +771,10 @@ export const GetCommentIdsInPostId = gql`
id
persistentId
optimisticId
...DatahubPostFragment
}
total
}
}
${DatahubPostFragment}
`
export const GetPostMetadata = gql`
query GetPostMetadata($where: PostMetadataInput!) {
Expand Down
11 changes: 0 additions & 11 deletions src/services/subsocial/datahub/posts/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CHAT_PER_PAGE } from '@/constants/chat'
import { getPostQuery } from '@/services/api/query'
import { queryClient } from '@/services/provider'
import { createQuery, poolQuery, QueryConfig } from '@/subsocial-query'
import { PostData } from '@subsocial/api/types'
import { QueryClient, useInfiniteQuery } from '@tanstack/react-query'
import { gql } from 'graphql-request'
import {
Expand All @@ -18,19 +17,15 @@ import {
GetUnreadCountQueryVariables,
QueryOrder,
} from '../generated-query'
import { mapDatahubPostFragment } from '../mappers'
import { datahubQueryRequest } from '../utils'
import { DATAHUB_POST_FRAGMENT } from './fetcher'

const GET_COMMENT_IDS_IN_POST_ID = gql`
${DATAHUB_POST_FRAGMENT}
query GetCommentIdsInPostId($where: FindPostsArgs!) {
findPosts(where: $where) {
data {
id
persistentId
optimisticId
...DatahubPostFragment
}
total
}
Expand All @@ -41,7 +36,6 @@ export type PaginatedPostsData = {
page: number
hasMore: boolean
totalData: number
messages: PostData[]
}
async function getPaginatedPostsByRootPostId({
page,
Expand All @@ -68,14 +62,10 @@ async function getPaginatedPostsByRootPostId({
},
})
const optimisticIds = new Set<string>()
const messages: PostData[] = []
const ids = res.findPosts.data.map((post) => {
optimisticIds.add(post.optimisticId ?? '')
const message = mapDatahubPostFragment(post)
messages.push(message)

const id = post.persistentId || post.id
getPostQuery.setQueryData(client, id, message)
return id
})
const totalData = res.findPosts.total ?? 0
Expand All @@ -100,7 +90,6 @@ async function getPaginatedPostsByRootPostId({
page,
hasMore,
totalData,
messages,
}
}
const COMMENT_IDS_QUERY_KEY = 'comments'
Expand Down
2 changes: 1 addition & 1 deletion src/services/subsocial/posts/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async function generateMessageContent(
) {
const { image, title, body } = params

if ('postId' in params) {
if ('postId' in params && params.postId) {
const post = await getPostQuery.fetchQuery(client, params.postId)
if (!post) throw new Error('Post not found')

Expand Down

0 comments on commit faab073

Please sign in to comment.