From faab073e06e24cc2e35c978fcfe232046f38e922 Mon Sep 17 00:00:00 2001 From: Teodorus Nathaniel <53143942+teodorus-nathaniel@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:34:08 +0700 Subject: [PATCH] Fix link preview not showing (#461) * Fix link preview not showing * Only render link preview if link metadata is filled * Fix create chat issue --- .../ChatItem/variants/DefaultChatItem.tsx | 2 +- src/pages/[hubId]/[slug]/index.tsx | 3 +- .../subsocial/datahub/generated-query.ts | 56 ------------------- src/services/subsocial/datahub/posts/query.ts | 11 ---- src/services/subsocial/posts/mutation.ts | 2 +- 5 files changed, 4 insertions(+), 70 deletions(-) diff --git a/src/components/chats/ChatItem/variants/DefaultChatItem.tsx b/src/components/chats/ChatItem/variants/DefaultChatItem.tsx index 6ed1917d7..76b165539 100644 --- a/src/components/chats/ChatItem/variants/DefaultChatItem.tsx +++ b/src/components/chats/ChatItem/variants/DefaultChatItem.tsx @@ -80,7 +80,7 @@ export default function DefaultChatItem({ {body}

- {link && ( + {link && linkMetadata?.title && ( | null - }> }> } } @@ -825,12 +771,10 @@ export const GetCommentIdsInPostId = gql` id persistentId optimisticId - ...DatahubPostFragment } total } } - ${DatahubPostFragment} ` export const GetPostMetadata = gql` query GetPostMetadata($where: PostMetadataInput!) { diff --git a/src/services/subsocial/datahub/posts/query.ts b/src/services/subsocial/datahub/posts/query.ts index b9651ea9d..671834776 100644 --- a/src/services/subsocial/datahub/posts/query.ts +++ b/src/services/subsocial/datahub/posts/query.ts @@ -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 { @@ -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 } @@ -41,7 +36,6 @@ export type PaginatedPostsData = { page: number hasMore: boolean totalData: number - messages: PostData[] } async function getPaginatedPostsByRootPostId({ page, @@ -68,14 +62,10 @@ async function getPaginatedPostsByRootPostId({ }, }) const optimisticIds = new Set() - 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 @@ -100,7 +90,6 @@ async function getPaginatedPostsByRootPostId({ page, hasMore, totalData, - messages, } } const COMMENT_IDS_QUERY_KEY = 'comments' diff --git a/src/services/subsocial/posts/mutation.ts b/src/services/subsocial/posts/mutation.ts index f50958743..f6dbdcac1 100644 --- a/src/services/subsocial/posts/mutation.ts +++ b/src/services/subsocial/posts/mutation.ts @@ -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')