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

FIX: Make the post card clickable #482

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 12 additions & 78 deletions frontend/package-lock.json

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

144 changes: 73 additions & 71 deletions frontend/src/components/PostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,81 +178,83 @@ const PostCard = ({ post, onDelete, currentUser }: Props) => {
};

return (
<div
key={post.id}
className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 border border-gray-600 p-6 rounded-lg shadow-lg hover:shadow-2xl hover:border-blue-500 hover:-translate-y-2 transition-transform duration-300 ease-in-out"style={{ backgroundImage: `url(${bgHero})`, backgroundSize: 'cover', backgroundPosition: 'center' }}
>
<div className="flex justify-between items-center">
<h2 className="text-xl font-bold mb-3 text-[#c94aff] bg-white dark:text-[#c94aff] dark:bg-blue-950">{post.title}</h2>
{isFavorite ? (
<MdFavorite
onClick={handleRemoveFromFavorite}
size={33}
className="cursor-pointer text-[#fe4c4c]"
/>
) : (
<MdFavoriteBorder
onClick={handleAddToFavorite}
size={33}
className="cursor-pointer text-[#e74e4e] dark:text-white"
/>
)}
</div> <p className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 mb-4">
{post.description.length > 100
? `${post.description.slice(0, 100)}...`
: post.description}
</p>
<p className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 mb-4">By :
<Link to={`/app/profile/${post.author.id}`} data-tooltip-content={`View ${post.author.username} profile 👀`} data-tooltip-id="my-tooltip" className="text-base">
<strong className="text-sky-500">
{' '} @{post.author.username}{' '}
</strong>
</Link>
</p>

<div className="flex flex-wrap gap-2">
{post.tags.map((tag, index) => (
<Link to={`/app/posts/${post.id}`}>
<div
key={post.id}
className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 border border-gray-600 p-6 rounded-lg shadow-lg hover:shadow-2xl hover:border-blue-500 hover:-translate-y-2 transition-transform duration-300 ease-in-out"style={{ backgroundImage: `url(${bgHero})`, backgroundSize: 'cover', backgroundPosition: 'center' }}
>
<div className="flex justify-between items-center">
<h2 className="text-xl font-bold mb-3 text-[#c94aff] bg-white dark:text-[#c94aff] dark:bg-blue-950">{post.title}</h2>
{isFavorite ? (
<MdFavorite
onClick={handleRemoveFromFavorite}
size={33}
className="cursor-pointer text-[#fe4c4c]"
/>
) : (
<MdFavoriteBorder
onClick={handleAddToFavorite}
size={33}
className="cursor-pointer text-[#e74e4e] dark:text-white"
/>
)}
</div> <p className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 mb-4">
{post.description.length > 100
? `${post.description.slice(0, 100)}...`
: post.description}
</p>
<p className="text-[#000435] bg-white dark:text-white dark:bg-blue-950 mb-4">By :
<Link to={`/app/profile/${post.author.id}`} data-tooltip-content={`View ${post.author.username} profile 👀`} data-tooltip-id="my-tooltip" className="text-base">
<strong className="text-sky-500">
{' '} @{post.author.username}{' '}
</strong>
</Link>
</p>

<div className="flex flex-wrap gap-2">
{post.tags.map((tag, index) => (
<Link
to={`/app/posts?tags=${tag}`}
key={index}
className="inline-flex items-center px-2 py-1 border-2 border-[#5f67de] text-[#5f67de] font-semibold dark:border-white dark:text-white dark:bg-transparent text-sm rounded-md transition-colors duration-300 hover:bg-[#5f67de] hover:text-white dark:hover:bg-white dark:hover:text-black"
>
{tag}
</Link>
))}
</div>
<div className="flex justify-between mt-1 ">
{/* <button>
<Link
to={`/app/posts/${post.id}`}
className="inline-block mt-4 text-blue-400 hover:text-blue-300 transition-colors duration-200 rounded-3xl border-2 border-blue-500 hover:border-blue-300 px-4 py-2"
>
Read More
</Link>
</button> */}
{currentUser && currentUser.id === post.author.id && (
<div className="flex space-x-2">
<button>
<Link
to={`/app/posts?tags=${tag}`}
key={index}
className="inline-flex items-center px-2 py-1 border-2 border-[#5f67de] text-[#5f67de] font-semibold dark:border-white dark:text-white dark:bg-transparent text-sm rounded-md transition-colors duration-300 hover:bg-[#5f67de] hover:text-white dark:hover:bg-white dark:hover:text-black"
to={`/app/posts/edit/${post.id}`}
className="justify-end mt-4 inline-block text-blue-400 hover:text-blue-300 transition-colors duration-200 border-2 border-blue-500 hover:border-blue-300 p-2 rounded-3xl"
>
{tag}
<FaEdit size={23} />
</Link>
))}
</div>
<div className="flex justify-between mt-1 ">
<button>
<Link
to={`/app/posts/${post.id}`}
className="inline-block mt-4 text-blue-400 hover:text-blue-300 transition-colors duration-200 rounded-3xl border-2 border-blue-500 hover:border-blue-300 px-4 py-2"
>
Read More
</Link>
</button>
{currentUser && currentUser.id === post.author.id && (
<div className="flex space-x-2">
<button>
<Link
to={`/app/posts/edit/${post.id}`}
className="justify-end mt-4 inline-block text-blue-400 hover:text-blue-300 transition-colors duration-200 border-2 border-blue-500 hover:border-blue-300 p-2 rounded-3xl"
>
<FaEdit size={23} />
</Link>
</button>
<button
onClick={handleDelete}
disabled={isDeleting}
className=""
> <Link className="justify-end mt-4 inline-block text-red-500 hover:text-red-400 transition-colors duration-200 border-2 border-red-500 dark:border-red-500 hover:border-red-400 p-2 rounded-3xl" to={""}>
{isDeleting ? "Deleting..." : <MdDeleteOutline size={23} />}
</Link>
</button>
</div>
)}
</button>
<button
onClick={handleDelete}
disabled={isDeleting}
className=""
> <Link className="justify-end mt-4 inline-block text-red-500 hover:text-red-400 transition-colors duration-200 border-2 border-red-500 dark:border-red-500 hover:border-red-400 p-2 rounded-3xl" to={""}>
{isDeleting ? "Deleting..." : <MdDeleteOutline size={23} />}
</Link>
</button>
</div>
)}
</div>
{renderReactions()}
</div>
{renderReactions()}
</div>
</Link>
);
};

Expand Down
Loading