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

Fix Renaming Bug #786

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Fix Renaming Bug #786

wants to merge 8 commits into from

Conversation

philippark
Copy link
Collaborator

No description provided.

@philippark
Copy link
Collaborator Author

Next on the agenda is to make the styling better looking

Copy link
Contributor

@curran curran left a comment

Choose a reason for hiding this comment

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

Thank you for this! I left a comment about a suggested refactoring.

@@ -64,6 +64,19 @@ export const Item = ({
[id, setHoveredItemId],
);

const validateFileName = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Please refactor this so that there is only a single definition of validateFileName in the codebase. I see there is another definition of this over in src/client/VZSidebar/CreateDirModal.tsx. Please pull this function out into its own separate file, then call it from both places. Thanks!

Copy link
Contributor

@curran curran Jul 12, 2024

Choose a reason for hiding this comment

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

Something like this:

export const validateFileName = ({files}) => {
  // Returns true if file name is valid, false otherwise.
  return useCallback(
    (fileName: string) => {
      let valid;
      // General Character Check
      const regex =
        /^[a-zA-Z0-9](?:[a-zA-Z0-9 ./+=_-]*[a-zA-Z0-9])?$/;
      valid = regex.test(fileName);

      // Check for Duplicate Filename
      for (const key in files) {
        if (fileName + '/' === files[key].name) {
          valid = false;
        }
      }

      return valid;
    },
    [files],
  );
}

This is a "custom hook" in React parlance.

@curran curran self-assigned this Jul 12, 2024
@curran
Copy link
Contributor

curran commented Jul 12, 2024

I'll take it from here. Thanks for this work!

@curran
Copy link
Contributor

curran commented Jul 14, 2024

Does this close a specific existing issue? If so which one?

@philippark
Copy link
Collaborator Author

Hi, yes it resolves this: #658

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants