Skip to content

Commit

Permalink
removed merge conflicts #41
Browse files Browse the repository at this point in the history
  • Loading branch information
its-kumar-yash committed Jun 2, 2024
1 parent f74056e commit 0acdb2b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions frontend/src/pages/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useEffect, useState, useRef } from 'react';
import axios from 'axios';
import { IPost } from '../types';
import Loader from '../components/Loader';
import PostCard from '../components/PostCard';

const Posts = () => {
const [posts, setPosts] = useState<IPost[]>([]);
Expand Down Expand Up @@ -71,8 +70,8 @@ const Posts = () => {
const filteredPosts = posts.filter(post =>
filterTags.every(tag => post.tags.map(t => t.toLowerCase()).includes(tag)) &&
(post.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
post.description.toLowerCase().includes(searchQuery.toLowerCase()) ||
post.author.username.toLowerCase().includes(searchQuery.toLowerCase()))
post.description.toLowerCase().includes(searchQuery.toLowerCase()) ||
post.author.username.toLowerCase().includes(searchQuery.toLowerCase()))
);

const handlePreviousPage = () => {
Expand Down Expand Up @@ -158,30 +157,37 @@ const Posts = () => {
className="p-2 w-full max-w-xs rounded-md bg-gray-700 text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 w-full">
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6 w-full">
{filteredPosts.map((post, index) => (
<PostCard key={index} post={post} />
<div key={index} className="bg-gray-800 p-4 rounded-lg shadow-md hover:shadow-lg transition-shadow duration-300">
<h2 className="text-xl font-semibold text-white mb-2">{post.title}</h2>
<p className="text-gray-400 mb-4">{post.description}</p>
<div className="text-gray-500 text-sm">By {post.author.username}</div>
</div>
))}
</div>
<div className="flex justify-center items-center mt-4 w-full space-x-2">
<button
onClick={handlePreviousPage}
disabled={page === 1}
className={`text-white px-4 py-2 rounded ${page === 1 ? 'bg-gray-600 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`} >
className={`text-white px-4 py-2 rounded ${page === 1 ? 'bg-gray-600 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`}
>
Previous
</button>
{Array.from({ length: totalPages }, (_, i) => (
<button
key={i}
onClick={() => handlePageClick(i + 1)}
className={`text-white px-4 py-2 rounded ${page === i + 1 ? 'bg-blue-500 text-white' : 'bg-blue-600 hover:bg-blue-700'}`} >
className={`text-white px-4 py-2 rounded ${page === i + 1 ? 'bg-blue-500 text-white' : 'bg-blue-600 hover:bg-blue-700'}`}
>
{i + 1}
</button>
))}
<button
onClick={handleNextPage}
disabled={page === totalPages}
className={`text-white px-6 py-2 rounded ${page === totalPages ? 'bg-gray-600 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`} >
className={`text-white px-6 py-2 rounded ${page === totalPages ? 'bg-gray-600 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700'}`}
>
Next
</button>
</div>
Expand Down

0 comments on commit 0acdb2b

Please sign in to comment.