Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/frontend/enhancement new sort #131

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Jasonwei1106
Copy link
Collaborator

@Jasonwei1106 Jasonwei1106 commented Nov 1, 2020

This change is Reviewable

@ghost
Copy link

ghost commented Nov 1, 2020

DeepCode's analysis on #db1b19 found:

  • ⚠️ 1 warning 👇

Top issues

Description Example fixes
React component state should only be modified through setState. The call sort modifies an element of state. This could lead to undesired behavior, since other state updates may be batched and run asynchronously by React. If you need to build new state that depends on previous state, use the callback version of setState. Occurrences: 🔧 Example fixes

👉 View analysis in DeepCode’s Dashboard | Configure the bot

Copy link
Contributor

@codecakes codecakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecakes codecakes requested a review from ksr89 November 1, 2020 05:31
@codecakes
Copy link
Contributor

@Jasonwei1106 pls make sure to tag @ksr89 as reviewer in all PRs

@@ -11,5 +11,4 @@ const Header = () => {
);
};

export default Header;

export default Header;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing end of file empty line

inputArr.forEach(element => {
element.dist = callback(element.geometry.location,this.state.lat,this.state.lng,"K");
});
console.log(inputArr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove this from production code

@@ -137,32 +147,35 @@ class Search extends Component {
* @param {string} unit - required unit of distance in kilometers('K') or nautical miles('N').
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls check if jsdoc annotations for each parameter are provided

@@ -228,7 +241,8 @@ class Search extends Component {
} = this.state;
const result_list =
results && results.length !== 0
? results.map(
? results.sort((a,b)=>a.dist-b.dist)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use absolute value;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is sorted based on if it is a negative or positive number, if I use abs it will always put 'a' at the front

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way you do sorting here is to find relevant distances from user location, find a diff/ in distance from user location. it can never be < zero.

@Jasonwei1106
Copy link
Collaborator Author

After I merge from master App.css has stylelint error.

@@ -228,8 +247,12 @@ class Search extends Component {
} = this.state;
const result_list =
results && results.length !== 0
? results.map(
({ facility_type, formatted_address, geometry: { location } }, index) => {
? results.sort((a,b)=>a.dist-b.dist)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jasonwei1106 Don't use JavaScript sort inside the render, Use it inside distancesort function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants