Skip to content

Commit

Permalink
chore: redo structure for cards (#3596)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelchris authored Oct 1, 2024
1 parent 4c805f3 commit 3987298
Show file tree
Hide file tree
Showing 108 changed files with 491 additions and 477 deletions.
29 changes: 22 additions & 7 deletions packages/shared/src/components/Feed.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,28 @@ import { acquisitionKey } from './cards/AcquisitionForm/common/common';
const showLogin = jest.fn();
let nextCallback: (value: PostsEngaged) => unknown = null;

jest.mock('../hooks/useBookmarkProvider', () => ({
__esModule: true,
default: jest
.fn()
.mockImplementation((): { highlightBookmarkedPost: boolean } => ({
jest.mock('../hooks', () => {
const originalModule = jest.requireActual('../hooks');
return {
__esModule: true,
...originalModule,
useBookmarkProvider: (): { highlightBookmarkedPost: boolean } => ({
highlightBookmarkedPost: false,
})),
}));
}),
useSubscription: {
default: jest
.fn()
.mockImplementation(
(
request: () => OperationOptions,
{ next }: SubscriptionCallbacks<PostsEngaged>,
): void => {
nextCallback = next;
},
),
},
};
});

jest.mock('../hooks/useSubscription', () => ({
__esModule: true,
Expand All @@ -108,6 +122,7 @@ beforeEach(() => {
jest.restoreAllMocks();
jest.clearAllMocks();
nock.cleanAll();
jest.clearAllMocks();
variables = defaultVariables;
});

Expand Down
43 changes: 23 additions & 20 deletions packages/shared/src/components/FeedItemComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
import React, { FunctionComponent, ReactElement } from 'react';
import dynamic from 'next/dynamic';
import { FeedItem } from '../hooks/useFeed';
import { ArticlePostCard } from './cards/ArticlePostCard';
import { ArticlePostList } from './cards/list/ArticlePostList';
import { PlaceholderCard } from './cards/PlaceholderCard';
import { PlaceholderList } from './cards/list/PlaceholderList';
import { PlaceholderGrid } from './cards/placeholder/PlaceholderGrid';
import { PlaceholderList } from './cards/placeholder/PlaceholderList';
import { Ad, Post, PostItem, PostType } from '../graphql/posts';
import { LoggedUser } from '../lib/user';
import { CommentOnData } from '../graphql/comments';
import useLogImpression from '../hooks/feed/useLogImpression';
import { FeedPostClick } from '../hooks/feed/useFeedOnPostClick';
import { SharePostCard } from './cards/SharePostCard';
import { SharePostList } from './cards/list/SharePostList';
import { Origin } from '../lib/log';
import { useFeedLayout, UseVotePost } from '../hooks';
import { CollectionCard } from './cards/CollectionCard';
import { CollectionList } from './cards/list/CollectionList';
import { CollectionList } from './cards/collection/CollectionList';
import { MarketingCtaCard } from './marketingCta';
import { MarketingCtaList } from './marketingCta/MarketingCtaList';
import { FeedItemType } from './cards/common';
import { FeedItemType } from './cards/common/common';
import { AdGrid } from './cards/ad/AdGrid';
import { AdList } from './cards/ad/AdList';
import { AcquisitionFormGrid } from './cards/AcquisitionForm/AcquisitionFormGrid';
import { AcquisitionFormList } from './cards/AcquisitionForm/AcquisitionFormList';
import { FreeformGrid } from './cards/Freeform/FreeformGrid';
import { FreeformList } from './cards/Freeform/FreeformList';
import { PostClick } from '../lib/click';
import { ArticleList } from './cards/article/ArticleList';
import { ArticleGrid } from './cards/article/ArticleGrid';
import { ShareGrid } from './cards/share/ShareGrid';
import { ShareList } from './cards/share/ShareList';
import { CollectionGrid } from './cards/collection';

const CommentPopup = dynamic(
() => import(/* webpackChunkName: "commentPopup" */ './cards/CommentPopup'),
() =>
import(
/* webpackChunkName: "commentPopup" */ './cards/common/CommentPopup'
),
);

export type FeedItemComponentProps = {
Expand Down Expand Up @@ -90,20 +93,20 @@ export function getFeedItemKey(item: FeedItem, index: number): string {
}

const PostTypeToTagCard: Record<PostType, FunctionComponent> = {
[PostType.Article]: ArticlePostCard,
[PostType.Share]: SharePostCard,
[PostType.Article]: ArticleGrid,
[PostType.Share]: ShareGrid,
[PostType.Welcome]: FreeformGrid,
[PostType.Freeform]: FreeformGrid,
[PostType.VideoYouTube]: ArticlePostCard,
[PostType.Collection]: CollectionCard,
[PostType.VideoYouTube]: ArticleGrid,
[PostType.Collection]: CollectionGrid,
};

const PostTypeToTagList: Record<PostType, FunctionComponent> = {
[PostType.Article]: ArticlePostList,
[PostType.Share]: SharePostList,
[PostType.Article]: ArticleList,
[PostType.Share]: ShareList,
[PostType.Welcome]: FreeformList,
[PostType.Freeform]: FreeformList,
[PostType.VideoYouTube]: ArticlePostList,
[PostType.VideoYouTube]: ArticleList,
[PostType.Collection]: CollectionList,
};

Expand All @@ -121,10 +124,10 @@ const getTags = ({
const useListCards = isListFeedLayout || shouldUseListMode;
return {
PostTag: useListCards
? PostTypeToTagList[postType] ?? ArticlePostList
: PostTypeToTagCard[postType] ?? ArticlePostCard,
? PostTypeToTagList[postType] ?? ArticleList
: PostTypeToTagCard[postType] ?? ArticleGrid,
AdTag: useListCards ? AdList : AdGrid,
PlaceholderTag: useListCards ? PlaceholderList : PlaceholderCard,
PlaceholderTag: useListCards ? PlaceholderList : PlaceholderGrid,
MarketingCtaTag: useListCards ? MarketingCtaList : MarketingCtaCard,
AcquisitionFormTag: useListCards
? AcquisitionFormList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement } from 'react';
import { Card } from '../Card';
import { Card } from '../common/Card';
import { AcquisitionFormInner } from './common/AcquisitionFormInner';

export function AcquisitionFormGrid(): ReactElement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactElement } from 'react';
import { ListCard } from '../list/ListCard';
import { ListCard } from '../common/list/ListCard';
import { AcquisitionFormInner } from './common/AcquisitionFormInner';

export function AcquisitionFormList(): ReactElement {
Expand Down

This file was deleted.

65 changes: 0 additions & 65 deletions packages/shared/src/components/cards/FeedbackCard.tsx

This file was deleted.

10 changes: 5 additions & 5 deletions packages/shared/src/components/cards/Freeform/FreeformGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { forwardRef, ReactElement, Ref, useRef } from 'react';
import classNames from 'classnames';
import { Container, generateTitleClamp, PostCardProps } from '../common';
import { Container, generateTitleClamp, PostCardProps } from '../common/common';
import { usePostImage } from '../../../hooks/post/usePostImage';
import { useSquadChecklist } from '../../../hooks/useSquadChecklist';
import { Squad } from '../../../graphql/sources';
import { PostType } from '../../../graphql/posts';
import { ActionType } from '../../../graphql/actions';
import FeedItemContainer from '../FeedItemContainer';
import { FreeformCardTitle, getPostClassNames } from '../Card';
import FeedItemContainer from '../common/FeedItemContainer';
import { FreeformCardTitle, getPostClassNames } from '../common/Card';
import CardOverlay from '../common/CardOverlay';
import OptionsButton from '../../buttons/OptionsButton';
import { SquadPostCardHeader } from '../common/SquadPostCardHeader';
import PostMetadata from '../PostMetadata';
import { WelcomePostCardFooter } from '../WelcomePostCardFooter';
import PostMetadata from '../common/PostMetadata';
import { WelcomePostCardFooter } from '../common/WelcomePostCardFooter';
import ActionButtons from '../ActionsButtons/ActionButtons';

export const FreeformGrid = forwardRef(function SharePostCard(
Expand Down
12 changes: 6 additions & 6 deletions packages/shared/src/components/cards/Freeform/FreeformList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, ReactElement, Ref, useMemo, useRef } from 'react';
import classNames from 'classnames';
import { sanitize } from 'dompurify';

import { Container, generateTitleClamp, PostCardProps } from '../common';
import { Container, generateTitleClamp, PostCardProps } from '../common/common';
import { useSquadChecklist } from '../../../hooks/useSquadChecklist';
import { Squad } from '../../../graphql/sources';
import { ActionType } from '../../../graphql/actions';
Expand All @@ -11,11 +11,11 @@ import { useFeedPreviewMode, useTruncatedSummary } from '../../../hooks';
import { usePostImage } from '../../../hooks/post/usePostImage';
import SquadHeaderPicture from '../common/SquadHeaderPicture';
import { PostContentReminder } from '../../post/common/PostContentReminder';
import FeedItemContainer from '../list/FeedItemContainer';
import { CardContainer, CardContent, CardTitle } from '../list/ListCard';
import { PostCardHeader } from '../list/PostCardHeader';
import { CardCoverList } from '../list/CardCover';
import ActionButtons from '../list/ActionButtons';
import FeedItemContainer from '../common/list/FeedItemContainer';
import { CardContainer, CardContent, CardTitle } from '../common/list/ListCard';
import { PostCardHeader } from '../common/list/PostCardHeader';
import { CardCoverList } from '../common/list/CardCover';
import ActionButtons from '../common/list/ActionButtons';

export const FreeformList = forwardRef(function SharePostCard(
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactElement } from 'react';
import classNames from 'classnames';
import { separatorCharacter } from '../common';
import { separatorCharacter } from '../common/common';
import { largeNumberFormat } from '../../../lib';

interface PostEngagementCountsProps {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/components/cards/ad/AdGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CardSpace,
CardTextContainer,
CardTitle,
} from '../Card';
} from '../common/Card';
import AdLink from './common/AdLink';
import AdAttribution from './common/AdAttribution';
import { AdImage } from './common/AdImage';
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/components/cards/ad/AdList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import React, {
ReactElement,
Ref,
} from 'react';
import { CardContent, CardImage, CardSpace, CardTitle } from '../list/ListCard';
import {
CardContent,
CardImage,
CardSpace,
CardTitle,
} from '../common/list/ListCard';
import AdAttribution from './common/AdAttribution';
import FeedItemContainer from '../list/FeedItemContainer';
import FeedItemContainer from '../common/list/FeedItemContainer';
import type { AdCardProps } from './common/common';
import { AdImage } from './common/AdImage';
import { AdPixel } from './common/AdPixel';
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/components/cards/ad/common/AdLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactElement } from 'react';
import { Ad } from '../../../../graphql/posts';
import { CardLink } from '../../Card';
import { CardLink } from '../../common/Card';
import { combinedClicks } from '../../../../lib/click';

export type AdLinkProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
waitFor,
} from '@testing-library/react';
import { QueryClient } from '@tanstack/react-query';
import { ArticlePostCard } from './ArticlePostCard';
import post from '../../../__tests__/fixture/post';
import { PostCardProps, visibleOnGroupHover } from './common';
import { PostType } from '../../graphql/posts';
import { TestBootProvider } from '../../../__tests__/helpers/boot';
import post from '../../../../__tests__/fixture/post';
import { PostCardProps, visibleOnGroupHover } from '../common/common';
import { PostType } from '../../../graphql/posts';
import { TestBootProvider } from '../../../../__tests__/helpers/boot';
import { ArticleGrid } from './ArticleGrid';

const defaultProps: PostCardProps = {
post,
Expand All @@ -31,7 +31,7 @@ beforeEach(() => {
const renderComponent = (props: Partial<PostCardProps> = {}): RenderResult => {
return render(
<TestBootProvider client={new QueryClient()}>
<ArticlePostCard {...defaultProps} {...props} />
<ArticleGrid {...defaultProps} {...props} />
</TestBootProvider>,
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import React, { forwardRef, ReactElement, Ref } from 'react';
import classNames from 'classnames';
import { Container, PostCardProps } from '../common/common';
import { useBlockPostPanel } from '../../../hooks/post/useBlockPostPanel';
import { usePostFeedback } from '../../../hooks';
import { isVideoPost } from '../../../graphql/posts';
import { PostTagsPanel } from '../../post/block/PostTagsPanel';
import FeedItemContainer from '../common/FeedItemContainer';
import {
CardSpace,
CardTextContainer,
CardTitle,
getPostClassNames,
} from './Card';
import PostMetadata from './PostMetadata';
import ActionButtons from './ActionsButtons/ActionButtons';
import { PostCardHeader } from './PostCardHeader';
import { PostCardFooter } from './PostCardFooter';
import { Container, PostCardProps } from './common';
import FeedItemContainer from './FeedItemContainer';
import { useBlockPostPanel } from '../../hooks/post/useBlockPostPanel';
import { PostTagsPanel } from '../post/block/PostTagsPanel';
import { usePostFeedback } from '../../hooks';
import styles from './Card.module.css';
import { FeedbackCard } from './FeedbackCard';
import { Origin } from '../../lib/log';
import { isVideoPost } from '../../graphql/posts';
import CardOverlay from './common/CardOverlay';
import PostTags from './PostTags';
} from '../common/Card';
import CardOverlay from '../common/CardOverlay';
import { Origin } from '../../../lib/log';
import styles from '../common/Card.module.css';
import { PostCardHeader } from '../common/PostCardHeader';
import PostTags from '../common/PostTags';
import PostMetadata from '../common/PostMetadata';
import { PostCardFooter } from '../common/PostCardFooter';
import ActionButtons from '../ActionsButtons';
import { FeedbackGrid } from './feedback/FeedbackGrid';

export const ArticlePostCard = forwardRef(function PostCard(
export const ArticleGrid = forwardRef(function ArticleGrid(
{
post,
onPostClick,
Expand Down Expand Up @@ -80,7 +80,7 @@ export const ArticlePostCard = forwardRef(function PostCard(
onPostCardAuxClick={onPostCardAuxClick}
/>
{showFeedback && (
<FeedbackCard
<FeedbackGrid
post={post}
onUpvoteClick={() => onUpvoteClick(post, Origin.FeedbackCard)}
onDownvoteClick={() => onDownvoteClick(post, Origin.FeedbackCard)}
Expand Down
Loading

0 comments on commit 3987298

Please sign in to comment.