Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Streamline Post fragments and it's types #5540

Merged
merged 7 commits into from
Mar 2, 2025
4 changes: 2 additions & 2 deletions apps/og/src/app/posts/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import getAccount from "@hey/helpers/getAccount";
import getPostData from "@hey/helpers/getPostData";
import logger from "@hey/helpers/logger";
import { isRepost } from "@hey/helpers/postHelpers";
import { type AnyPost, PostDocument } from "@hey/indexer";
import { type AnyPostFragment, PostDocument } from "@hey/indexer";
import apolloClient from "@hey/indexer/apollo/client";
import type { Metadata } from "next";
import defaultMetadata from "src/defaultMetadata";
Expand All @@ -27,7 +27,7 @@ export const generateMetadata = async ({
return defaultMetadata;
}

const post = data.post as AnyPost;
const post = data.post as AnyPostFragment;
const targetPost = isRepost(post) ? post.repostOf : post;
const { author, metadata } = targetPost;
const filteredContent = getPostData(metadata)?.content || "";
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Account/AccountFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { AccountFeedType } from "@hey/data/enums";
import {
MainContentFocus,
PageSize,
type Post,
PostType,
type PostsRequest,
usePostsQuery
Expand Down Expand Up @@ -145,7 +144,7 @@ const AccountFeed: FC<AccountFeedProps> = ({
<SinglePost
isFirst={index === 0}
isLast={index === (posts?.length || 0) - 1}
post={post as Post}
post={post}
showThread={
type !== AccountFeedType.Media &&
type !== AccountFeedType.Collects
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Bookmarks/BookmarksFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BookmarkIcon } from "@heroicons/react/24/outline";
import {
type MainContentFocus,
PageSize,
type Post,
type PostBookmarksRequest,
usePostBookmarksQuery
} from "@hey/indexer";
Expand Down Expand Up @@ -80,7 +79,7 @@ const BookmarksFeed: FC<BookmarksFeedProps> = ({ focus }) => {
<SinglePost
isFirst={index === 0}
isLast={index === (posts?.length || 0) - 1}
post={post as Post}
post={post}
/>
)}
ref={virtuoso}
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Comment/CommentFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PostsShimmer from "@components/Shared/Shimmer/PostsShimmer";
import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline";
import {
PageSize,
type Post,
PostReferenceType,
type PostReferencesRequest,
PostVisibilityFilter,
Expand Down Expand Up @@ -83,7 +82,7 @@ const CommentFeed: FC<CommentFeedProps> = ({ postId }) => {
<SinglePost
isFirst={isFirst}
isLast={isLast}
post={comment as Post}
post={comment}
showType={false}
/>
);
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Comment/NoneRelevantFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline";
import getAvatar from "@hey/helpers/getAvatar";
import {
PageSize,
type Post,
PostReferenceType,
type PostReferencesRequest,
PostVisibilityFilter,
Expand Down Expand Up @@ -89,7 +88,7 @@ const NoneRelevantFeed: FC<NoneRelevantFeedProps> = ({ postId }) => {
<SinglePost
isFirst={isFirst}
isLast={isLast}
post={comment as Post}
post={comment}
showType={false}
/>
);
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/components/Composer/NewPublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Events } from "@hey/data/events";
import collectActionParams from "@hey/helpers/collectActionParams";
import getAccount from "@hey/helpers/getAccount";
import getMentions from "@hey/helpers/getMentions";
import type { Post } from "@hey/indexer";
import type { PostFragment } from "@hey/indexer";
import type { IGif } from "@hey/types/giphy";
import type { NewAttachment } from "@hey/types/misc";
import { Button, Card, H6 } from "@hey/ui";
Expand Down Expand Up @@ -48,7 +48,7 @@ import LinkPreviews from "./LinkPreviews";

interface NewPublicationProps {
className?: string;
post?: Post;
post?: PostFragment;
feed?: string;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ const NewPublication: FC<NewPublicationProps> = ({ className, post, feed }) => {
setShowLiveVideoEditor(false);
resetLiveVideoConfig();
setAttachments([]);
setQuotedPost(null);
setQuotedPost();
setVideoThumbnail(DEFAULT_VIDEO_THUMBNAIL);
setAudioPost(DEFAULT_AUDIO_POST);
setLicense(null);
Expand Down Expand Up @@ -263,7 +263,7 @@ const NewPublication: FC<NewPublicationProps> = ({ className, post, feed }) => {
<NewAttachments attachments={attachments} />
{quotedPost ? (
<Wrapper className="m-5" zeroPadding>
<QuotedPost isNew post={quotedPost as Post} />
<QuotedPost isNew post={quotedPost} />
</Wrapper>
) : null}
<div className="divider mx-5" />
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Explore/ExploreFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ChatBubbleBottomCenterIcon } from "@heroicons/react/24/outline";
import {
type MlexplorePostsRequest,
PageSize,
type Post,
useMlPostsExploreQuery
} from "@hey/indexer";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
Expand Down Expand Up @@ -83,7 +82,7 @@ const ExploreFeed: FC<ExploreFeedProps> = ({ feedType = "", focus }) => {
<SinglePost
isFirst={index === 0}
isLast={index === (posts?.length || 0) - 1}
post={post as Post}
post={post}
/>
)}
ref={virtuoso}
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Explore/ImageFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import SingleImagePost from "@components/Post/SingleImagePost";
import ImagePostsShimmer from "@components/Shared/Shimmer/ImagePostsShimmer";
import { ChatBubbleBottomCenterIcon } from "@heroicons/react/24/outline";
import {
type AnyPost,
type MlexplorePostsRequest,
PageSize,
useMlPostsExploreQuery
Expand Down Expand Up @@ -51,7 +50,7 @@ const ImageFeed: FC<ImageFeedProps> = ({ feedType = "" }) => {
return (
<div className="grid grid-cols-3 gap-4">
{posts?.map((post) => (
<SingleImagePost key={post.id} post={post as AnyPost} />
<SingleImagePost key={post.id} post={post} />
))}
</div>
);
Expand Down
9 changes: 2 additions & 7 deletions apps/web/src/components/Group/GroupFeed.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import SinglePost from "@components/Post/SinglePost";
import PostsShimmer from "@components/Shared/Shimmer/PostsShimmer";
import { ChatBubbleBottomCenterIcon } from "@heroicons/react/24/outline";
import {
PageSize,
type Post,
type PostsRequest,
usePostsQuery
} from "@hey/indexer";
import { PageSize, type PostsRequest, usePostsQuery } from "@hey/indexer";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
import type { FC } from "react";
import { useEffect, useRef } from "react";
Expand Down Expand Up @@ -84,7 +79,7 @@ const GroupFeed: FC<GroupFeedProps> = ({ feed }) => {
<SinglePost
isFirst={index === 0}
isLast={index === (posts?.length || 0) - 1}
post={post as Post}
post={post}
/>
)}
ref={virtuoso}
Expand Down
3 changes: 1 addition & 2 deletions apps/web/src/components/Home/ForYou.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LightBulbIcon } from "@heroicons/react/24/outline";
import {
type MlpostsForYouRequest,
PageSize,
type Post,
useMlPostsForYouQuery
} from "@hey/indexer";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
Expand Down Expand Up @@ -64,7 +63,7 @@ const ForYou: FC = () => {
<SinglePost
isFirst={index === 0}
isLast={index === (posts?.length || 0) - 1}
post={item.post as Post}
post={item.post}
/>
)}
useWindowScroll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Accounts from "@components/Shared/Accounts";
import { SparklesIcon } from "@heroicons/react/24/outline";
import type { TimelineItem } from "@hey/indexer";
import type { TimelineItemFragment } from "@hey/indexer";
import type { FC } from "react";
import { Fragment } from "react";

interface CombinedProps {
timelineItem: TimelineItem;
timelineItem: TimelineItemFragment;
}

const Combined: FC<CombinedProps> = ({ timelineItem }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Accounts from "@components/Shared/Accounts";
import { ArrowsRightLeftIcon } from "@heroicons/react/24/outline";
import type { Repost } from "@hey/indexer";
import type { RepostFragment } from "@hey/indexer";
import type { FC } from "react";

interface RepostedProps {
reposts: Repost[];
reposts: RepostFragment[];
}

const Reposted: FC<RepostedProps> = ({ reposts }) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Home/Timeline/EventType/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import type { TimelineItem } from "@hey/indexer";
import type { TimelineItemFragment } from "@hey/indexer";
import type { FC } from "react";
import Combined from "./Combined";
import Reposted from "./Reposted";
Expand All @@ -10,7 +10,7 @@ const getCanCombined = (aggregations: number[]) => {
};

interface ActionTypeProps {
timelineItem: TimelineItem;
timelineItem: TimelineItemFragment;
}

const ActionType: FC<ActionTypeProps> = ({ timelineItem }) => {
Expand Down
11 changes: 3 additions & 8 deletions apps/web/src/components/Home/Timeline/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import SinglePost from "@components/Post/SinglePost";
import PostsShimmer from "@components/Shared/Shimmer/PostsShimmer";
import { UserGroupIcon } from "@heroicons/react/24/outline";
import {
type Post,
type TimelineItem,
type TimelineRequest,
useTimelineQuery
} from "@hey/indexer";
import { type TimelineRequest, useTimelineQuery } from "@hey/indexer";
import { Card, EmptyState, ErrorMessage } from "@hey/ui";
import type { FC } from "react";
import { memo, useRef } from "react";
Expand Down Expand Up @@ -75,10 +70,10 @@ const Timeline: FC = () => {
isScrolling={onScrolling}
itemContent={(index, timelineItem) => (
<SinglePost
timelineItem={timelineItem as TimelineItem}
timelineItem={timelineItem}
isFirst={index === 0}
isLast={index === (feed?.length || 0) - 1}
post={timelineItem.primary as Post}
post={timelineItem.primary}
/>
)}
ref={virtuoso}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ChatBubbleLeftIcon } from "@heroicons/react/24/outline";
import humanize from "@hey/helpers/humanize";
import nFormatter from "@hey/helpers/nFormatter";
import type { Post } from "@hey/indexer";
import type { PostFragment } from "@hey/indexer";
import { Tooltip } from "@hey/ui";
import { useRouter } from "next/router";
import type { FC } from "react";

interface CommentProps {
post: Post;
post: PostFragment;
showCount: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Like.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Events } from "@hey/data/events";
import nFormatter from "@hey/helpers/nFormatter";
import {
type LoggedInPostOperationsFragment,
type Post,
type PostFragment,
PostReactionType,
useAddReactionMutation,
useUndoReactionMutation
Expand All @@ -22,7 +22,7 @@ import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useAccountStore } from "src/store/persisted/useAccountStore";

interface LikeProps {
post: Post;
post: PostFragment;
showCount: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Menu/Bookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BookmarkIcon as BookmarkIconSolid } from "@heroicons/react/24/solid";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import {
type LoggedInPostOperationsFragment,
type Post,
type PostFragment,
useBookmarkPostMutation,
useUndoBookmarkPostMutation
} from "@hey/indexer";
Expand All @@ -16,7 +16,7 @@ import type { FC } from "react";
import { toast } from "react-hot-toast";

interface BookmarkProps {
post: Post;
post: PostFragment;
}

const Bookmark: FC<BookmarkProps> = ({ post }) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Menu/CopyPostText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { MenuItem } from "@headlessui/react";
import { ClipboardDocumentIcon } from "@heroicons/react/24/outline";
import getPostData from "@hey/helpers/getPostData";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import type { Post } from "@hey/indexer";
import type { PostFragment } from "@hey/indexer";
import cn from "@hey/ui/cn";
import type { FC } from "react";
import toast from "react-hot-toast";

interface CopyPostTextProps {
post: Post;
post: PostFragment;
}

const CopyPostText: FC<CopyPostTextProps> = ({ post }) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Menu/Delete.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { MenuItem } from "@headlessui/react";
import { TrashIcon } from "@heroicons/react/24/outline";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import type { Post } from "@hey/indexer";
import type { PostFragment } from "@hey/indexer";
import cn from "@hey/ui/cn";
import type { FC } from "react";
import { useDeletePostAlertStore } from "src/store/non-persisted/alert/useDeletePostAlertStore";

interface DeleteProps {
post: Post;
post: PostFragment;
}

const Delete: FC<DeleteProps> = ({ post }) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Menu/HideComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import errorToast from "@helpers/errorToast";
import { CheckCircleIcon, NoSymbolIcon } from "@heroicons/react/24/outline";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import {
type Post,
type PostFragment,
useHideReplyMutation,
useUnhideReplyMutation
} from "@hey/indexer";
Expand All @@ -15,7 +15,7 @@ import { toast } from "react-hot-toast";
import { useAccountStore } from "src/store/persisted/useAccountStore";

interface HideCommentProps {
post: Post;
post: PostFragment;
}

const HideComment: FC<HideCommentProps> = ({ post }) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/Post/Actions/Menu/NotInterested.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EyeIcon, EyeSlashIcon } from "@heroicons/react/24/outline";
import stopEventPropagation from "@hey/helpers/stopEventPropagation";
import {
type LoggedInPostOperationsFragment,
type Post,
type PostFragment,
type PostNotInterestedRequest,
useAddPostNotInterestedMutation,
useUndoPostNotInterestedMutation
Expand All @@ -15,7 +15,7 @@ import type { FC } from "react";
import { toast } from "react-hot-toast";

interface NotInterestedProps {
post: Post;
post: PostFragment;
}

const NotInterested: FC<NotInterestedProps> = ({ post }) => {
Expand Down
Loading