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

Bookmarks ordering #204

Merged
merged 10 commits into from May 15, 2018
Merged

Bookmarks ordering #204

merged 10 commits into from May 15, 2018

Conversation

@SergeyZhukovsky
Copy link
Member

SergeyZhukovsky commented May 11, 2018

No description provided.

@SergeyZhukovsky SergeyZhukovsky requested a review from diracdeltas May 11, 2018
DELETE_SYNC_SITE_SETTINGS: _,
/**
* browser -> webview
* browser sends this to get base bookmarks order for the particular device.

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

does this also need to send the device type? (Mobile vs Desktop)
@davidtemkin's spec says "Desktop devices come first, followed by mobile devices."

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

NVM, i see it's the platform string.

yarn.lock Outdated
@@ -0,0 +1,4936 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

please delete this file since this repo no longer uses Yarn (has been replaced by package-lock.json)

Copy link
Member

diracdeltas left a comment

Could you please split getBaseBookmarksOrder and getBookmarkOrder into a utility module (like client/bookmarkUtil.js) and then add some unit tests for this module (liketest/client/bookmarkUtil.js) ?

platformPrefix = `2.`
}
platformPrefix += deviceId + `.`
return platformPrefix

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

minor: this function could be simplified into

return `${(platform === 'ios' || platform === 'android') ? 2 : 1}.${deviceId}.`
}

const getBookmarkOrder = (prevOrder, nextOrder) => {
let prevOrderSplit = prevOrder.split(`.`)

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

you can replace the backtick quote with single quotes (') for strings in JS in most of this code since backticks are only needed for template strings. by convention, if a string is not a template string, it uses quotes instead of backticks. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

return platformPrefix
}

const getBookmarkOrder = (prevOrder, nextOrder) => {

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

this should handle the case where prevOrder or nextOrder are null/empty (in order to get a bookmark at the start of the list or at the end of the list) - see comment in https://docs.google.com/a/brave.com/document/d/1t2IEFQF0Xj2aNnlEf0KaIXEqbfQ_RCn4b01LuIuef6I/edit?disco=AAAABxDSFGk

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 11, 2018

Member

^ nvm, i see you assume they are empty strings instead of null. 👍

@@ -60,7 +60,7 @@ module.exports.getBookmarkOrder = (prevOrder, nextOrder) => {
order += prevOrderSplit[i] + '.'
}
let lastNumber = parseInt(prevOrderSplit[prevOrderSplit.length - 1])
order = getNextOrderFromPrevOrder(lastNumber, order)
order = getNextOrderFromPrevOrder(lastNumber, order)

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

extra space

if (nextOrderSplit.length === 1) {
// Next order is an empty string
if (prevOrderSplit.length > 2) {
for (var i = 0; i < prevOrderSplit.length - 1; i++) {

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

it would be cleaner to replace this for loop with prevOrderSplit.forEach

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

actually it's even better to just do order = prevOrderSplit.join('.') + '.'

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

or order = prevOrder + '.' ?

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky May 15, 2018

Author Member

the loop doesn't include the last element, it's not really forEach and not a join of all elements

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

ah sorry i missed that it doesn't include the last element.

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

in that case you could replace all these forloops with a regex like order = prevOrder.replace(/\.\d*$/, '') + '.'

}
} else if (prevOrderSplit.length === 1) {
// Prev order is an empty string
if (nextOrderSplit.length > 2) {

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

can replace this for loop with order = nextOrder + '.'

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky May 15, 2018

Author Member

the same as above

}
} else {
if (prevOrderSplit.length > 2 && nextOrderSplit.length > 2) {
for (i = 0; i < prevOrderSplit.length - 1; i++) {

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky May 15, 2018

Author Member

the same as above

}
} else if (prevOrderSplit.length < nextOrderSplit.length) {
// Next order is longer than previous order
let lastNumberDiff = true

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

you can replace this and the following for loop with const lastNumberDiff = !nextOrder.startsWith(prevOrder) i think

This comment has been minimized.

Copy link
@SergeyZhukovsky

SergeyZhukovsky May 15, 2018

Author Member

what is nextOrder and prevOrder in your example? again the loop doesn't include the last element

This comment has been minimized.

This comment has been minimized.

Copy link
@diracdeltas

diracdeltas May 15, 2018

Member

though since it doesn't include the last element, this may not actually be simpler

@SergeyZhukovsky SergeyZhukovsky merged commit 75c1bb1 into staging May 15, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.