Skip to content

Commit f9124e2

Browse files
committed
added search option and fixed sorting issue
1 parent 284d9c8 commit f9124e2

3 files changed

Lines changed: 56 additions & 18 deletions

File tree

src/homeComponents/cards.jsx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,45 @@ import sort from "./sort.png"
99
import queen from './images/queen.PNG'
1010
import binSearch from './images/binaryTree.png'
1111
import {getDetails} from "./cardDetails";
12+
import TextField from "@material-ui/core/TextField";
1213
class Cards extends Component {
1314

1415
state = {
15-
cards:[]
16+
cards:[],
17+
filter:""
1618
}
1719

1820
componentDidMount() {
1921
this.setState({cards:getDetails()});
2022
}
21-
23+
getData = (e)=>{
24+
console.log(e.target.value);
25+
this.setState({filter:e.target.value});
26+
}
2227
render() {
2328
return (
24-
<div className="d-flex flex-wrap justify-content-center Cards p-lg-5" >
25-
{
26-
this.state.cards.map(card=>(
27-
<div>
28-
<ImgMediaCard2
29-
className="d-flex flex-wrap"
30-
key={card.id}
31-
card={card}/>
32-
</div>
33-
))
34-
}
29+
<React.Fragment>
30+
<div className="d-flex justify-content-end Cards">
31+
<TextField
32+
id="standard-basic" label="Search"
33+
color="secondary"
34+
onChange={this.getData}
35+
/>
36+
</div>
37+
<div className="d-flex flex-wrap justify-content-center Cards p-lg-5" >
38+
{
39+
this.state.cards.filter((card) => card.title.toLowerCase().includes(this.state.filter.toLowerCase())||card.description.toLowerCase().includes(this.state.filter.toLowerCase())).map(card=>(
40+
<div>
41+
<ImgMediaCard2
42+
className="d-flex flex-wrap"
43+
key={card.id}
44+
card={card}/>
45+
</div>
46+
))
47+
}
3548

36-
</div>
49+
</div>
50+
</React.Fragment>
3751
);
3852
}
3953
}

src/homeComponents/searchText.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { makeStyles } from '@material-ui/core/styles';
3+
import TextField from '@material-ui/core/TextField';
4+
5+
const useStyles = makeStyles((theme) => ({
6+
root: {
7+
'& > *': {
8+
margin: theme.spacing(1),
9+
width: '25ch',
10+
},
11+
},
12+
}));
13+
14+
export default function BasicTextFields() {
15+
const classes = useStyles();
16+
17+
return (
18+
<form className={classes.root} noValidate autoComplete="off">
19+
<TextField id="standard-basic" label="Search" />
20+
</form>
21+
);
22+
}

src/sortComponents/sort.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Sort extends Component {
106106
steps1 = bubbleSort(this.state.rects);
107107
break;
108108
}
109-
this.handleFirst(steps1);
109+
110110
if( this.state.doubles ){
111111
let steps2;
112112
switch (this.state.algo2){
@@ -123,6 +123,7 @@ class Sort extends Component {
123123
steps2 = bubbleSort(this.state.rects2);
124124
break;
125125
}
126+
this.handleFirst(steps1);
126127
this.handleSecond(steps2);
127128
}
128129
}
@@ -168,12 +169,12 @@ class Sort extends Component {
168169
// },i*speed);
169170
}
170171
}
171-
handleSecond = (steps) =>{
172+
handleSecond = async (steps) =>{
172173
const {speed} = this.state;
173174
this.setState({isRunning2:true});
174175
const prevRect = this.state.rects2;
175176
for(let i = 0;i<steps.length;i++){
176-
setTimeout(()=>{
177+
// setTimeout(()=>{
177178
if( i!==0 ){
178179
prevRect[steps[i-1].xx] = { ...prevRect[steps[i-1].xx],isSorting:false };
179180
prevRect[steps[i-1].yy] = { ...prevRect[steps[i-1].yy],isSorting:false };
@@ -204,7 +205,8 @@ class Sort extends Component {
204205
}
205206
}*/
206207
this.setState({rects2:prevRect});
207-
},i*speed);
208+
await sleep(this.state.speed);
209+
// },i*speed);
208210
}
209211
}
210212

0 commit comments

Comments
 (0)