Skip to content

Commit 6270432

Browse files
committed
feat: search component users repositories
1 parent 52d59c1 commit 6270432

File tree

4 files changed

+133
-6
lines changed

4 files changed

+133
-6
lines changed

src/ui/components/Search/Search.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Search.css */
2+
3+
.search-container {
4+
display: flex;
5+
align-items: center;
6+
margin-bottom: 10px;
7+
margin-top: 10px;
8+
margin-right: 10 px;
9+
}
10+
11+
.search-input {
12+
padding: 10px;
13+
margin-right: 8px;
14+
border: 1px solid #ccc;
15+
border-radius: 10px;
16+
width: 200px; /* Adjust width as needed */
17+
font-size: 14px;
18+
transition: border-color 0.3s;
19+
}
20+
21+
.search-input:focus {
22+
border-color: #007bff; /* Change to your desired focus color */
23+
outline: none; /* Remove default outline */
24+
}
25+
26+
.search-button {
27+
padding: 10px 16px;
28+
border: none;
29+
border-radius: 10px;
30+
background-color: #007bff; /* Change to your desired button color */
31+
color: white;
32+
cursor: pointer;
33+
font-size: 14px;
34+
transition: background-color 0.3s;
35+
}
36+
37+
.search-button:hover {
38+
background-color: #0056b3; /* Darker shade for hover effect */
39+
}

src/ui/components/Search/Search.jsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useState } from 'react';
2+
import PropTypes from 'prop-types';
3+
import './Search.css'; // Import the CSS file
4+
5+
export default function Search({ placeholder = 'Search...', onSearch }) {
6+
const [query, setQuery] = useState('');
7+
8+
const handleInputChange = (e) => {
9+
setQuery(e.target.value);
10+
};
11+
12+
const handleSearch = () => {
13+
onSearch(query);
14+
};
15+
16+
const handleKeyDown = (event) => {
17+
if (event.key === 'Enter') {
18+
handleSearch(); // Trigger search on Enter
19+
}
20+
};
21+
22+
return (
23+
<div className="search-container">
24+
<input
25+
type="text"
26+
placeholder={placeholder}
27+
value={query}
28+
onChange={handleInputChange}
29+
onKeyDown={handleKeyDown} // Add keydown event
30+
className="search-input" // Apply the class
31+
/>
32+
<button onClick={handleSearch} className="search-button">
33+
Search
34+
</button>
35+
</div>
36+
);
37+
}
38+
39+
Search.propTypes = {
40+
placeholder: PropTypes.string,
41+
onSearch: PropTypes.func.isRequired,
42+
};

src/ui/views/RepoList/Components/RepoOverview.jsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import GridItem from '../../../components/Grid/GridItem';
66
import { CodeReviewIcon, LawIcon, PeopleIcon } from '@primer/octicons-react';
77

88

9+
10+
911
const colors = {
1012
'1C Enterprise': '#814CCC',
1113
'2-Dimensional Array': '#38761D',
@@ -570,11 +572,13 @@ const colors = {
570572
import moment from 'moment';
571573
import CodeActionButton from '../../../components/CustomButtons/CodeActionButton';
572574
import Pagination from '../../../components/Pagination/Pagination';
575+
import Search from '../../../components/Search/Search';
573576

574577
export default function Repositories(props) {
575578
// const [github, setGitHub] = React.useState({});
576579
// const [repositories, setRepositories] = useState([]); // To hold all repositories
577580
const [currentPage, setCurrentPage] = useState(1);
581+
const [searchQuery, setSearchQuery] = useState('');
578582
const itemsPerPage = 5;
579583

580584

@@ -606,10 +610,23 @@ export default function Repositories(props) {
606610
// };
607611

608612

613+
// Handle search functionality
614+
const handleSearch = (query) => {
615+
setSearchQuery(query);
616+
setCurrentPage(1); // Reset to first page when searching
617+
};
618+
619+
// Filter repositories based on search query
620+
const filteredRepositories = dummyRepositories.filter(repo =>
621+
repo.name.toLowerCase().includes(searchQuery.toLowerCase())
622+
);
623+
624+
625+
609626
// Pagination logic to get current items for the page
610627
const indexOfLastItem = currentPage * itemsPerPage;
611628
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
612-
const currentItems = dummyRepositories.slice(indexOfFirstItem, indexOfLastItem);
629+
const currentItems = filteredRepositories.slice(indexOfFirstItem, indexOfLastItem);
613630

614631
const handlePageChange = (page) => {
615632
setCurrentPage(page);
@@ -620,6 +637,10 @@ export default function Repositories(props) {
620637

621638
return (
622639
<>
640+
641+
<Search onSearch={handleSearch} placeholder="Search repositories..." />
642+
643+
623644
{currentItems.map((repo, index) => (
624645
<TableRow key={index}>
625646
<TableCell>
@@ -684,10 +705,12 @@ export default function Repositories(props) {
684705
{/* Render the Pagination component */}
685706
<Pagination
686707
currentPage={currentPage}
687-
totalItems={dummyRepositories.length}
708+
totalItems={filteredRepositories.length} // Use filtered repositories for pagination
688709
itemsPerPage={itemsPerPage}
689710
onPageChange={handlePageChange}
690711
/>
712+
691713
</>
714+
692715
);
693716
}

src/ui/views/UserList/Components/UserList.jsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import TableRow from '@material-ui/core/TableRow';
1212
import Paper from '@material-ui/core/Paper';
1313
import { CloseRounded, Check, KeyboardArrowRight } from '@material-ui/icons';
1414
import Pagination from '../../../components/Pagination/Pagination';
15+
import Search from '../../../components/Search/Search';
16+
1517

1618
const useStyles = makeStyles({
1719
table: {
@@ -38,19 +40,40 @@ export default function UserList() {
3840

3941
// Pagination states
4042
const [currentPage, setCurrentPage] = useState(1);
41-
const itemsPerPage = 5; // Set the number of items per page
43+
const itemsPerPage = 5;
44+
const [searchQuery, setSearchQuery] = useState('');
4245

4346
// Calculate the items for the current page
4447
const indexOfLastItem = currentPage * itemsPerPage;
4548
const indexOfFirstItem = indexOfLastItem - itemsPerPage;
46-
const currentItems = dummyUsers.slice(indexOfFirstItem, indexOfLastItem);
47-
const totalItems = dummyUsers.length;
4849

49-
const handlePageChange = (page) => setCurrentPage(page);
50+
// Filter users based on the search query
51+
const filteredUsers = dummyUsers.filter(user =>
52+
user.displayName.toLowerCase().includes(searchQuery.toLowerCase()) ||
53+
user.username.toLowerCase().includes(searchQuery.toLowerCase())
54+
);
55+
56+
const currentItems = filteredUsers.slice(indexOfFirstItem, indexOfLastItem);
57+
const totalItems = filteredUsers.length;
58+
// Function to handle page change
59+
const handlePageChange = (page) => {
60+
setCurrentPage(page);
61+
};
62+
63+
64+
// Function to handle search
65+
const handleSearch = (query) => {
66+
setSearchQuery(query);
67+
setCurrentPage(1); // Reset to the first page when searching
68+
};
5069

5170
return (
5271
<GridContainer>
5372
<GridItem xs={12} sm={12} md={12}>
73+
74+
{/* Search Component */}
75+
<Search onSearch={handleSearch} placeholder="Search users..." />
76+
5477
<TableContainer component={Paper}>
5578
<Table className={classes.table} aria-label='simple table'>
5679
<TableHead>

0 commit comments

Comments
 (0)