From 08a32f3919097a299b0dd8aadf7adf7302ae5e65 Mon Sep 17 00:00:00 2001 From: 0xExp-po Date: Fri, 13 Sep 2024 16:46:45 +0900 Subject: [PATCH] feat: add dropdown, search box and register button --- dapp/public/icons/search.svg | 23 ++++++++ dapp/src/components/ProjectList.jsx | 75 ++++++++++++++++++++++++-- dapp/src/components/utils/DropDown.jsx | 57 ++++++++++++++++++++ 3 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 dapp/public/icons/search.svg create mode 100644 dapp/src/components/utils/DropDown.jsx diff --git a/dapp/public/icons/search.svg b/dapp/public/icons/search.svg new file mode 100644 index 0000000..fa79636 --- /dev/null +++ b/dapp/public/icons/search.svg @@ -0,0 +1,23 @@ + + + + \ No newline at end of file diff --git a/dapp/src/components/ProjectList.jsx b/dapp/src/components/ProjectList.jsx index ea0ad95..0efb111 100644 --- a/dapp/src/components/ProjectList.jsx +++ b/dapp/src/components/ProjectList.jsx @@ -1,26 +1,91 @@ import React, { useState, useEffect } from 'react'; import ProjectCard from './ProjectCard.jsx'; import { getDemoConfigData } from '../constants/demoConfigData.js'; +import Dropdown from './utils/DropDown.jsx'; +import { refreshLocalStorage, setProjectId } from '../service/StateService'; const ProjectList = () => { const [projects, setProjects] = useState([]); + const [filteredProjects, setFilteredProjects] = useState([]); + const [searchTerm, setSearchTerm] = useState(''); + const [category, setCategory] = useState('all'); + + const options = [ + { label: 'All', value: 'all' }, + { label: 'Web', value: 'web' }, + { label: 'Mobile', value: 'mobile' }, + { label: 'Desktop', value: 'desktop' }, + ]; useEffect(() => { const fetchProjects = async () => { - // Simulating an async operation await new Promise(resolve => setTimeout(resolve, 100)); const data = getDemoConfigData(); setProjects(data); + setFilteredProjects(data); }; fetchProjects(); }, []); + useEffect(() => { + const filtered = projects.filter(project => + project?.projectName.toLowerCase().includes(searchTerm.toLowerCase()) && + (category === 'all') + ); + setFilteredProjects(filtered); + }, [searchTerm, category, projects]); + + const handleSearch = () => { + console.log('Search function activated'); + }; + + const handleRegister = () => { + refreshLocalStorage(); + setProjectId(searchTerm.toLowerCase()); + window.location.href = '/register'; + } + return ( -
- {projects.map((project, index) => ( - - ))} +
+
+ setCategory(e.target.value)} /> +
+ setSearchTerm(e.target.value)} + /> +
+ +
+
+ {filteredProjects.length === 0 && ( + + )} +
+ + {filteredProjects.length > 0 ? ( +
+ {filteredProjects.map((project, index) => ( + + ))} +
+ ) : ( +
+

No projects found

+
+ )}
); }; diff --git a/dapp/src/components/utils/DropDown.jsx b/dapp/src/components/utils/DropDown.jsx new file mode 100644 index 0000000..282b681 --- /dev/null +++ b/dapp/src/components/utils/DropDown.jsx @@ -0,0 +1,57 @@ +import React, { useState } from 'react'; + +const Dropdown = ({ options, onSelect }) => { + const [isOpen, setIsOpen] = useState(false); + const [selectedOption, setSelectedOption] = useState(null); + + const toggleDropdown = () => setIsOpen(!isOpen); + + const handleOptionClick = (option) => { + setSelectedOption(option); + setIsOpen(false); + onSelect(option); + }; + + return ( +
+ + + {isOpen && ( +
    + {options.map((option, index) => ( +
  • handleOptionClick(option)} + > + {option.label} +
  • + ))} +
+ )} +
+ ); +}; + +export default Dropdown;