Skip to content

Commit

Permalink
Broke Post out and added granular arguments. (#6)
Browse files Browse the repository at this point in the history
* Broke Post out and added granular arguments.

* Removed unused arguments

* Fixed eslint issues
  • Loading branch information
Pdzly authored Dec 14, 2023
1 parent 9ea7147 commit 05c1b91
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 47 deletions.
123 changes: 122 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"react": "^18",
"react-dom": "^18",
"react-markdown": "^9.0.1",
"remark-gfm": "^4.0.0"
"remark-gfm": "^4.0.0",
"sublinks-js-client": "^0.0.3"
},
"devDependencies": {
"@stylistic/eslint-plugin-js": "^1.4.1",
Expand Down
53 changes: 8 additions & 45 deletions src/components/post-feed/index.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,17 @@
import React from 'react';
import Link from 'next/link';

import { getCommunitySlugFromUrl } from '@/utils/communities';
import PostVotes from '../post-votes';
import { BodyText, BodyTitle, PaleBodyText } from '../text';
import * as testData from '../../../test-data.json';
import PostThumbnail from '../post-thumbnail';
import { PostCard } from '../post';

const PostFeed = () => (
<div className="bg-primary dark:bg-primary-dark flex flex-col gap-8">
{testData.posts.map(postData => {
const {
id, body, name: title, thumbnail_url: thumbnailUrl
} = postData.post;
const { actor_id: communityUrl } = postData.community;
const { score } = postData.counts;
const communitySlug = getCommunitySlugFromUrl(communityUrl);
const postUrl = `/p/${communitySlug}/${id}`;

return (
<div key={id}>
<div className="flex">
<div className="flex items-center ml-8">
<PostVotes points={score} />
</div>
<Link href={postUrl} className="w-full group">
<div className="flex h-100 relative">
<div className="h-full flex gap-12 px-12 py-6 items-start">
<div className="h-80 w-80 mt-8 flex flex-shrink-0 relative">
<PostThumbnail postThumbnailUrl={thumbnailUrl} />
</div>
<div className="h-full w-full flex">
<div className="h-full flex flex-col">
<BodyTitle className="text-sm font-semibold line-clamp-2 group-hover:text-brand dark:group-hover:text-brand-dark group-visited:text-gray-500 group-visited:dark:text-gray-400">{title}</BodyTitle>
<div className="mb-8 flex max-md:flex-col">
<PaleBodyText className="text-xs">
{`Posted to ${communitySlug}`}
</PaleBodyText>
</div>
{body && <BodyText className="text-xs max-md:hidden line-clamp-2 group-visited:text-gray-500 group-visited:dark:text-gray-400">{body}</BodyText>}
</div>
</div>
</div>
</div>
</Link>
</div>
<div className="border-b-2 border-secondary dark:border-secondary-dark" />
</div>
);
})}
{testData.posts.map(postData => (
<PostCard
community={postData.community}
counts={postData.counts}
post={postData.post}
/>
))}
</div>
);

Expand Down
68 changes: 68 additions & 0 deletions src/components/post/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';
import Link from 'next/link';

import { getCommunitySlugFromUrl } from '@/utils/communities';
import {
Post, Community, PostAggregates
} from 'sublinks-js-client';
import {
BodyText, BodyTitle, PaleBodyText
} from '../text';
import PostVotes from '../post-votes';
import PostThumbnail from '../post-thumbnail';

interface PostCardProps {
post: Post;
community: Community;
counts: PostAggregates
}

export const PostCard = ({
post,
community,
counts
}: PostCardProps) => {
const {
id, body, name: title, thumbnail_url: thumbnailUrl
} = post;
const { actor_id: communityUrl } = community;
const { score } = counts;
const communitySlug = getCommunitySlugFromUrl(communityUrl);
const postUrl = `/p/${communitySlug}/${id}`;

return (
<div key={id}>
<div className="flex">
<div className="flex items-center ml-8">
<PostVotes points={score} />
</div>
<Link href={postUrl} className="w-full group">
<div className="flex h-100 relative">
<div className="h-full flex gap-12 px-12 py-6 items-start">
<div className="h-80 w-80 mt-8 flex flex-shrink-0 relative">
<PostThumbnail postThumbnailUrl={thumbnailUrl} />
</div>
<div className="h-full w-full flex">
<div className="h-full flex flex-col">
<BodyTitle
className="text-sm font-semibold line-clamp-2 group-hover:text-brand dark:group-hover:text-brand-dark group-visited:text-gray-500 group-visited:dark:text-gray-400"
>
{title}

</BodyTitle>
<div className="mb-8 flex max-md:flex-col">
<PaleBodyText className="text-xs">
{`Posted to ${communitySlug}`}
</PaleBodyText>
</div>
{body && <BodyText className="text-xs max-md:hidden line-clamp-2 group-visited:text-gray-500 group-visited:dark:text-gray-400">{body}</BodyText>}
</div>
</div>
</div>
</div>
</Link>
</div>
<div className="border-b-2 border-secondary dark:border-secondary-dark" />
</div>
);
};

0 comments on commit 05c1b91

Please sign in to comment.