File tree Expand file tree Collapse file tree 4 files changed +53
-5
lines changed
Expand file tree Collapse file tree 4 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -7,11 +7,13 @@ import About from './pages/AboutMe';
77import Projects from './pages/Projects' ;
88import Contact from './pages/Contact' ;
99import ProjectSingle from './pages/ProjectSingle' ;
10+ import ScrollToTop from './components/ScrollToTop' ;
1011
1112function App ( ) {
1213 return (
1314 < div className = " bg-secondary-light dark:bg-primary-dark transition duration-300" >
1415 < Router >
16+ < ScrollToTop />
1517 < AppHeader > </ AppHeader >
1618 < Routes >
1719 < Route path = "/" element = { < Home /> } />
Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react' ;
2+
3+ const BackToTop = ( ) => {
4+ const userScrollPosition = 0 ;
5+
6+ useEffect ( ( ) => {
7+ window . scrollTo ( 0 , 0 ) ;
8+ } , [ userScrollPosition ] ) ;
9+
10+ return < div > </ div > ;
11+ } ;
12+
13+ export default BackToTop ;
Original file line number Diff line number Diff line change @@ -4,6 +4,31 @@ import ProjectsFilter from './ProjectsFilter';
44import ProjectSingle from './ProjectSingle' ;
55
66const ProjectsGrid = ( ) => {
7+ const selectedProject = '' ;
8+ const searchProject = '' ;
9+
10+ const filteredProjects = ( ) => {
11+ if ( selectedProject ) {
12+ return filterProjectsByCategory ( ) ;
13+ } else if ( searchProject ) {
14+ return filterProjectsBySearch ( ) ;
15+ }
16+ return ProjectsData ;
17+ } ;
18+
19+ const filterProjectsByCategory = ( ) => {
20+ return ProjectsData . filter ( ( item ) => {
21+ let category =
22+ item . category . charAt ( 0 ) . toUpperCase ( ) + item . category . slice ( 1 ) ;
23+ return category . includes ( selectedProject ) ;
24+ } ) ;
25+ } ;
26+
27+ const filterProjectsBySearch = ( ) => {
28+ let project = new RegExp ( searchProject , 'i' ) ;
29+ return ProjectsData . filter ( ( el ) => el . title . match ( project ) ) ;
30+ } ;
31+
732 return (
833 < section className = "py-5 sm:py-10 mt-5 sm:mt-10" >
934 { /* Projects grid title start */ }
@@ -92,11 +117,6 @@ const ProjectsGrid = () => {
92117
93118 { /* Projects grid start */ }
94119 < div className = "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 mt-6 sm:gap-10" >
95- { /* <ProjectSingle
96- v-for="project in filteredProjects"
97- :key="project.id"
98- :project="project"
99- /> */ }
100120 { ProjectsData . map ( ( project ) => (
101121 < ProjectSingle
102122 title = { project . title }
Original file line number Diff line number Diff line change 1+ import { useEffect } from 'react' ;
2+ import { useLocation } from 'react-router-dom' ;
3+
4+ const ScrollToTop = ( ) => {
5+ const { pathname } = useLocation ( ) ;
6+
7+ useEffect ( ( ) => {
8+ window . scrollTo ( 0 , 0 ) ;
9+ } , [ pathname ] ) ;
10+ return null ;
11+ } ;
12+
13+ export default ScrollToTop ;
You can’t perform that action at this time.
0 commit comments