Skip to content

Fix issue #39: Ensure new files are consistently added under folders …#47

Open
SahilLamba0008 wants to merge 3 commits intometz-sh:mainfrom
SahilLamba0008:fix-file-tree-add-file-issue-39
Open

Fix issue #39: Ensure new files are consistently added under folders …#47
SahilLamba0008 wants to merge 3 commits intometz-sh:mainfrom
SahilLamba0008:fix-file-tree-add-file-issue-39

Conversation

@SahilLamba0008
Copy link
Copy Markdown
Contributor

Fix: Issue #39 - File-tree View Add New File Bug

  • This fix ensures that new folders and files can be added even when the folder's state is open. I verified that the folder state is correctly updated to handle this behavior consistently.
  • Refer to the video for more context.

Video :

Screen.Recording.2024-10-08.at.7.53.08.PM.mp4

Please review and let me know if any additional changes are needed.

@iostreamer-X
Copy link
Copy Markdown
Member

@SahilLamba0008 this looks good, but can you add details about the bug, why it happens and how your solution handles all cases?

@SahilLamba0008
Copy link
Copy Markdown
Contributor Author

@SahilLamba0008 this looks good, but can you add details about the bug, why it happens and how your solution handles all cases?

As per my understanding of the code :

  • Clicking the "Add New File" button while the folder is open prevents adding new files. To address this, we temporarily close the folder by setting opened to false using setOpened((open) => !open), and we can also directly set it using setOpened(false).

  • This allows users to add files even when the folder is open. Once the file is created successfully, the opened state will be set to false again, as this time it refers to the newly created folder or file.

  • If a user cancels the action after clicking "Add New File," the opened state will revert to false. These automatic updates are managed by useEffects and their dependencies, ensuring everything works smoothly.

  • This temporary change to the opened state is brief, enabling the getAddNewComponent() function to work properly without impacting other functionalities of the app. Opting for a different solution can result in unexpected behavior throughout the entire file-tree.

Comment thread src/ui/components/ide/folder/folder.tsx Outdated
getFolderContextMenu(props.path, {
onAddNewClick() {
setIsBeingAddedTo(true);
setOpened((open) => !open); // change folder open state when adding new file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's be explicit about the state of 'opened' here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

by being explicit, do you mean to set the state directly here instead on depending on prevState ? In that case the solution would be just set the opened state as false setOpened(false);. should I raise a new pr for this ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That sounds workable but the end result would look like:

  • open folder with lot of files under it
  • right click
  • select 'Add new'
  • and the the folder will fully collapse

This can be a bit jarring UX. Can we figure out what the root cause it and fix it in such a way that opening or closing a folder has no impact on adding new files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If you are worried about the parent folder collapsing when adding a new folder inside it, don't worry-it won't happen. I have tested this solution locally. However, in my opinion, the optimal solution would be that opening and closing the folder should not affect adding new files. Working on the same.

@iostreamer-X
Copy link
Copy Markdown
Member

Sorry for the delay @SahilLamba0008! I have added a small comment, please take a look.

@SahilLamba0008
Copy link
Copy Markdown
Contributor Author

Hi @iostreamer-X , sorry for the delay, got busy with some office work. Talking about the issue, upon further debugging it caught my eye that actually, the functionality of adding folders is working completey fine already. It is not dependent on any state as it is calling add-new-component.tsx regardless opened state being true or false, as after making a few changes in styles we can see it clearly. (Refer the attached video...) . Maybe the issue is with stylings and states !

Screen.Recording.2024-10-23.at.12.06.58.PM.1.mp4

Will update soon with a PR, meanwhile if have any insights that can help feel free to share.

@iostreamer-X
Copy link
Copy Markdown
Member

Hi @iostreamer-X , sorry for the delay, got busy with some office work. Talking about the issue, upon further debugging it caught my eye that actually, the functionality of adding folders is working completey fine already. It is not dependent on any state as it is calling add-new-component.tsx regardless opened state being true or false, as after making a few changes in styles we can see it clearly. (Refer the attached video...) . Maybe the issue is with stylings and states !

Screen.Recording.2024-10-23.at.12.06.58.PM.1.mp4
Will update soon with a PR, meanwhile if have any insights that can help feel free to share.

Ohh, good eye. To be honest, I am not really sure of its root cause. Let me check this as well. Thank you sharing this!

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