File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ import { ProjectsContext } from '../../context/ProjectsContext';
5
5
import ProjectsFilter from './ProjectsFilter' ;
6
6
7
7
const ProjectsGrid = ( ) => {
8
- const { projects } = useContext ( ProjectsContext ) ;
8
+ const { setSearchProject, searchProjectsByTitle } =
9
+ useContext ( ProjectsContext ) ;
9
10
10
11
// const selectedProject = '';
11
12
// const searchProject = '';
@@ -86,6 +87,9 @@ const ProjectsGrid = () => {
86
87
< FiSearch className = "text-ternary-dark dark:text-ternary-light w-5 h-5" > </ FiSearch >
87
88
</ span >
88
89
< input
90
+ onChange = { ( e ) => {
91
+ setSearchProject ( e . target . value ) ;
92
+ } }
89
93
className = "
90
94
pl-3
91
95
pr-1
@@ -120,7 +124,7 @@ const ProjectsGrid = () => {
120
124
121
125
{ /* Projects grid start */ }
122
126
< div className = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 mt-6 sm:gap-10" >
123
- { projects . map ( ( project ) => (
127
+ { searchProjectsByTitle . map ( ( project ) => (
124
128
< ProjectSingle
125
129
title = { project . title }
126
130
category = { project . category }
Original file line number Diff line number Diff line change @@ -7,9 +7,24 @@ export const ProjectsContext = createContext();
7
7
// Create the projects context provider
8
8
export const ProjectsProvider = ( props ) => {
9
9
const [ projects , setProjects ] = useState ( projectsData ) ;
10
+ const [ searchProject , setSearchProject ] = useState ( '' ) ;
11
+
12
+ // Search projects
13
+ const searchProjectsByTitle = projects . filter ( ( item ) => {
14
+ if ( item . title . toLowerCase ( ) . includes ( searchProject . toLowerCase ( ) ) )
15
+ return item ;
16
+ else if ( searchProject === '' ) return item ;
17
+ } ) ;
10
18
11
19
return (
12
- < ProjectsContext . Provider value = { { projects, setProjects } } >
20
+ < ProjectsContext . Provider
21
+ value = { {
22
+ projects,
23
+ setProjects,
24
+ setSearchProject,
25
+ searchProjectsByTitle,
26
+ } }
27
+ >
13
28
{ props . children }
14
29
</ ProjectsContext . Provider >
15
30
) ;
You can’t perform that action at this time.
0 commit comments