Skip to content

Commit

Permalink
Sorting Issue Solved
Browse files Browse the repository at this point in the history
  • Loading branch information
utsavshukla committed Jan 1, 2021
1 parent e23b034 commit f5e95ec
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 194 deletions.
19 changes: 14 additions & 5 deletions controller/image/getGenre.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const Vision = require("../../models/vision");


function compare( a, b ) {
if(a.label.length === b.label.length){return 0;}
return a.label.length > b.label.length;
if(a.label.length < b.label.length) return 1;
if(a.label.length > b.label.length) return -1;
return 0;
}

class GetGenre{
Expand All @@ -13,9 +14,17 @@ class GetGenre{
Vision.find({user_id : req.params.user_id})
.then((user) =>{
let labels = user[0].image_labels;
labels.sort(compare);
labels = labels.slice(0,5);
// console.log(labels);
labels.sort(compare);

// labels.forEach(element => {
// console.log(element.name,element.label.length);
// });


labels = labels.slice(0,6);

// console.log("asd",labels);
// return res.status(200);
return res.status(200).json(labels);
}
)
Expand Down
27 changes: 17 additions & 10 deletions frontend/src/pages/MainPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MainPage extends React.Component{
showOptions: false,
userInput: '',
isGenreDisplay : false,

enableName : '',

};

Expand All @@ -54,8 +54,8 @@ onPageChange = (page) => {

onOpenGenre = (e) => {
// console.log(e.target.id);
this.setState({userInput : e.target.id});
this.setState({isGenreDisplay : true});
this.setState({enableName : e.target.id});
this.setState({isGenreDisplay : true,showOptions : false});
this.props.getImages(e.target.id);
}

Expand Down Expand Up @@ -117,12 +117,19 @@ changeSearchList = (e) =>{
optionName.toLowerCase().indexOf(userInput.toLowerCase()) > -1
);
// console.log(filteredGenres);

if(filteredGenres.length === 0){
this.setState({
filteredGenres : [],
showOptions : false,
});
}
else{
this.setState({
filteredGenres,
showOptions: true,
userInput
});
}

}

Expand All @@ -146,11 +153,11 @@ render(){
<div className="container-fluid mt-5">
<div className="card mb-4 wow fadeIn">
<div className="card-body d-sm-flex justify-content-between">
<h4 className="mb-2 mb-sm-0 pt-1">
{/* <a href="https://mdbootstrap.com/docs/jquery/" target="_blank">Home Page</a>
<span>/</span> */}
<span>Dashboard</span>
</h4>
<h4 className="mb-2 mb-sm-0 pt-1">
{/* <a href="https://mdbootstrap.com/docs/jquery/" target="_blank">Home Page</a>
<span>/</span> */}
<span>Dashboard</span>
</h4>
<div>
<form className="d-flex justify-content-center">

Expand Down Expand Up @@ -179,7 +186,7 @@ render(){
<div key = {"all"} className="p-2 bd-highlight ">
<button type="button"
className={"btn btn-outline-info waves-effect"}>
{this.state.userInput}
{this.state.enableName}
</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ class Profile extends React.Component {
const { authMessage,userData} = this.props;
const { username, email, password, otp} = this.state.data;
const {errors} = this.state;
console.log("user",userData.user_image);
// console.log("user",userData);
if(localStorage.getItem('loggedIn') === 'false'){
return <Redirect to = {"/login"} />
}
}

let coverImage;

Expand Down
Loading

0 comments on commit f5e95ec

Please sign in to comment.