-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
import React, {useState, useEffect} from 'react' | ||
import appwriteService from "../appwrite/config" | ||
import {Container, PostCard} from "../components" | ||
import { useSelector } from 'react-redux' | ||
import React, { useState, useEffect } from 'react'; | ||
import appwriteService from "../appwrite/config"; | ||
import { Container, PostCard } from "../components"; | ||
|
||
function AllPosts() { | ||
const [posts, setPosts] = useState([]) | ||
useEffect(() => {}, []) | ||
const [posts, setPosts] = useState<any[]>([]); | ||
const [searchTerm, setSearchTerm] = useState<string>(""); | ||
|
||
useEffect(() => { | ||
appwriteService.getPosts([]).then((posts) => { | ||
if(posts){ | ||
setPosts(posts.documents) | ||
if (posts) { | ||
setPosts(posts.documents); | ||
} | ||
}) | ||
|
||
|
||
}); | ||
}, []); | ||
|
||
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchTerm(e.target.value.toLowerCase()); | ||
}; | ||
|
||
const filteredPosts = posts.filter(post => | ||
post.title.toLowerCase().includes(searchTerm) || | ||
post.content.toLowerCase().includes(searchTerm) | ||
); | ||
|
||
return ( | ||
<div className='w-full py-8'> | ||
<Container> | ||
<div className='flex justify-center mb-4'> | ||
<input | ||
type="text" | ||
placeholder="Search posts" | ||
value={searchTerm} | ||
onChange={handleSearch} | ||
className="input input-bordered input-success w-96" | ||
/> | ||
</div> | ||
<div className='flex flex-wrap'> | ||
{posts.map((post) => ( | ||
{filteredPosts.map((post) => ( | ||
<div key={post.$id} className='p-2 w-1/4'> | ||
<PostCard {...post}/> | ||
<PostCard {...post} /> | ||
</div> | ||
))} | ||
</div> | ||
</Container> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
export default AllPosts | ||
export default AllPosts; |