Skip to content

Commit f3c5d57

Browse files
authored
Merge pull request #21 from Dev-Goel/main
Updated SearchBar Component
2 parents 1531324 + 4341ff7 commit f3c5d57

File tree

5 files changed

+213
-277
lines changed

5 files changed

+213
-277
lines changed

frontend/family_tree/src/App.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
display: flex;
55
align-items: center;
66
flex-direction: column;
7-
/* background-image: linear-gradient(90deg, #8820dd, orange); */
87
}
98

109
.help {
@@ -47,4 +46,4 @@
4746
margin-right: 10px;
4847
width: 150px;
4948
height: 170px;
50-
}
49+
}

frontend/family_tree/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import StudentData from "./Data.json";
77
function App() {
88
return (
99
<div className="App">
10-
<SearchBar placeholder="Enter the Name or Roll Number..." data={StudentData} />
10+
<SearchBar placeholder="Enter the Name or Roll Number..." studentData={StudentData} />
1111
<div className="help">
1212
<Help />
1313
</div>

frontend/family_tree/src/Components/SearchBar.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
import React, { useState } from "react";
2-
import "./SearchBar.css";
2+
import "../Styles/SearchBar.css";
33
import SearchIcon from "@material-ui/icons/Search";
44
import CloseIcon from "@material-ui/icons/Close"
55

6-
function SearchBar({ placeholder, data }) {
6+
function SearchBar({ placeholder, studentData }) {
77
const [filteredData, setFilteredData] = useState([]);
88
const [wordEntered, setWordEntered] = useState("");
99

1010
const handleFilter = (event) => {
1111
const searchWord = event.target.value;
1212
setWordEntered(searchWord);
13-
const newFilter = data.filter((value) => {
14-
return value.title.toLowerCase().includes(searchWord.toLowerCase());
15-
});
16-
1713
if (searchWord.length < 3) {
1814
setFilteredData([]);
1915
} else {
20-
setFilteredData(newFilter);
16+
const filteredResults = studentData.filter((query) => {
17+
return query.student.name.toLowerCase().includes(searchWord.toLowerCase()) + query.student.id.toLowerCase().includes(searchWord.toLowerCase());
18+
});
19+
setFilteredData(filteredResults);
2120
}
2221
};
2322

24-
const clearInput = () => {
23+
const clearState = () => {
2524
setFilteredData([]);
2625
setWordEntered("");
2726
};
@@ -36,20 +35,18 @@ function SearchBar({ placeholder, data }) {
3635
onChange={handleFilter}
3736
/>
3837
<div className="searchIcon">
39-
{filteredData.length === 0 ? (
38+
{wordEntered.length === 0 ? (
4039
<SearchIcon />
4140
) : (
42-
<CloseIcon id="clearBtn" onClick={clearInput} />
41+
<CloseIcon id="clearBtn" onClick={clearState} />
4342
)}
4443
</div>
4544
</div>
46-
{filteredData.length != 0 && (
45+
{filteredData.length !== 0 && (
4746
<div className="dataResult">
48-
{filteredData.slice(0, 5).map((value, key) => {
47+
{filteredData.slice(0, 5).map((value) => {
4948
return (
50-
<a className="dataItem" href={value.link} target="_blank">
51-
<p>{value.title} </p>
52-
</a>
49+
<p className="dataItem">{`${value.student.name} (${value.student.id})`} </p>
5350
);
5451
})}
5552
</div>

0 commit comments

Comments
 (0)