Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upBookmarks ordering #204
Bookmarks ordering #204
Conversation
| DELETE_SYNC_SITE_SETTINGS: _, | ||
| /** | ||
| * browser -> webview | ||
| * browser sends this to get base bookmarks order for the particular device. |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
| @@ -0,0 +1,4936 @@ | |||
| # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | |||
This comment has been minimized.
This comment has been minimized.
diracdeltas
May 11, 2018
Member
please delete this file since this repo no longer uses Yarn (has been replaced by package-lock.json)
|
Could you please split |
| platformPrefix = `2.` | ||
| } | ||
| platformPrefix += deviceId + `.` | ||
| return platformPrefix |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
| @@ -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.
This comment has been minimized.
| 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.
This comment has been minimized.
diracdeltas
May 15, 2018
Member
it would be cleaner to replace this for loop with prevOrderSplit.forEach
This comment has been minimized.
This comment has been minimized.
diracdeltas
May 15, 2018
Member
actually it's even better to just do order = prevOrderSplit.join('.') + '.'
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| } | ||
| } else { | ||
| if (prevOrderSplit.length > 2 && nextOrderSplit.length > 2) { | ||
| for (i = 0; i < prevOrderSplit.length - 1; i++) { |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| } | ||
| } else if (prevOrderSplit.length < nextOrderSplit.length) { | ||
| // Next order is longer than previous order | ||
| let lastNumberDiff = true |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
diracdeltas
May 15, 2018
Member
the input parameters: https://github.com/brave/sync/pull/204/files#diff-bfda8eb33ecdb505fea0ed734376e047R49
This comment has been minimized.
This comment has been minimized.
diracdeltas
May 15, 2018
Member
though since it doesn't include the last element, this may not actually be simpler
SergeyZhukovsky commentedMay 11, 2018
No description provided.