-
Notifications
You must be signed in to change notification settings - Fork 29
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
Keep the path as string instead of an array #678
Conversation
testBookmark fails everwhere. |
357dbb1
to
1bf739b
Compare
src/files-breadcrumbs.tsx
Outdated
path = path.slice(path.length - 1); | ||
const PathBreadcrumbs = ({ path }: { path: string }) => { | ||
const path_array = path.split("/"); | ||
if (path.endsWith("/") && path_array.length > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a comment, why this is needed :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or alternative implementation..
if (!currentPath.startsWith("/")) { | ||
currentPath = `/${currentPath}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a test :)
defaultBookmarks.push({ name: _("Home"), loc: user?.home }); // TODO: add trash | ||
if (user?.home) { | ||
// Ensure the home dir has a trailing / like the path | ||
const home_dir = user.home.endsWith('/') ? user.home : `${user.home}/`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, never seen user.home
be /home/admin/ it always is /home/admin
so that's logical.
73043d9
to
e7a7c0d
Compare
There is no good reason to keep the path as an array of strings, usually we want to just append a file to the path for file operations as most of the code simply joined the path back to a string. This also makes sure the path is properly formatted as /path/to/thing/ with a leading and trailing /.
if (!currentPath.startsWith("/")) { | ||
currentPath = `/${currentPath}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 added lines are not executed by any test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test this in a follow up!
defaultBookmarks.push({ name: _("Home"), loc: user?.home }); // TODO: add trash | ||
if (user?.home) { | ||
// Ensure the home dir has a trailing / like the path | ||
const home_dir = user.home.endsWith('/') ? user.home : `${user.home}/`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test.
} | ||
); | ||
} else if (selected.length > 1) { | ||
menuItems.push( | ||
{ | ||
id: "copy-item", | ||
title: _("Copy"), | ||
onClick: () => setClipboard(selected.map(s => path.join("/") + "/" + s.name)), | ||
onClick: () => setClipboard(selected.map(s => path + s.name)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good... and so the path.join("/")
is no more!
There is no good reason to keep the path as an array of strings, usually we want to just append a file to the path for file operations as most of the code simply joined the path back to a string.
This also makes sure the path is properly formatted as /path/to/thing/ with a leading and trailing /.
///
and///foo///