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

Allow adding multiple URLs at once #158 #167

Merged
merged 1 commit into from
May 19, 2024

Conversation

kamtschatka
Copy link
Contributor

Added a reusable dialog
opening a dialog that allows you to decide if you want to import multiple URLs at once if you provide only that

Copy link

vercel bot commented May 19, 2024

Someone is attempting to deploy a commit to the Mohamed Bassem's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@MohamedBassem MohamedBassem left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me and I really like the feature and I like that we're giving the user the choice! Great job.

I've suggested some simplifications ideas :)

apps/web/components/dashboard/bookmarks/EditorCard.tsx Outdated Show resolved Hide resolved
Comment on lines 46 to 47
const [open, setOpen] = React.useState(false);
const [importData, setImportData] = React.useState(initialImportData);
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's some room for simplification here:

  1. Have only one state which is multiURLImportState. This state can be either set when we detect a multi-url input, or null if we didn't (with null being the default)`.
  2. Remove the open control state for the dialog and instead only render the dialog if multiURLImportState is not null. In react, you typically do that with (multiURLImportState && <MultiInputDialog> ...). The dialog will need to set defaultOpen=true so that it's open when it's rendered.
  3. When the user takes an action or onOpenChange, just set multiURLImportState to null which will remove the dialog.

What do you think?

Copy link
Collaborator

@MohamedBassem MohamedBassem left a comment

Choose a reason for hiding this comment

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

After the changes, there's small new bug when the user clicks outside of the dialog. Repro:

  1. Input multiple URLs & click submit
  2. Click outside the dialog, the dialog will get closed.
  3. Try clicking submit again, nothing will happen.

children?: React.ReactNode;
}) {
return (
<Dialog defaultOpen={true}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that this is a generic dialog (in the ui dir), you'll want to make this as a prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok now I am confused. If the defaultOpen will no longer be true, then I will have to bring back the open function, otherwise this control will never show?
I was under the impression the goal was to make this always show, otherwise don't you have 2 ways of opening and closing it? (one with calling the open function and 1 by configuring it with defaultOpen=true)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kamtschatka Your new component is a generic dialog. So you'll need to pass params similar to that of the dialog to allow the different usecases to customize it. In that case, you'll want to expose open?, onOpenChange? and defaultOpen? (and forward them to Dialog). Then our usecase (which is the confirmation of multi URL), is the one that won't pass open, but will set defaultOpen to true, does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, i was just confused that above you said to remove the open control state and below you said open is no longer used.
So basically it was good as it was before, the idea was more to add an additional way to allow showing the dialog without calling setOpen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

open should continue being there, but you'll need to make it optional and pass it to the dialog. Currently, it's there, but not being used.

The whole suggestion for simplification was yes to not have a controlled open property for the dialog. We just render it when needed it, and un-render it when it's no longer needed. All of that while keeping the option to use MultiInputDialog in a controlled fashion in a different place if we want to (aka keeping it generic)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, but then I have to get rid of the defaultOpen again, because then I would have the open parameter and the defaultOpen parameter, where 1 could be true and 1 could be false, which would be weird.
I'll just pass true to open, without having a state to keep it, because that is implied by the MultiUrlImportState.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kamtschatka you need both. For example this the API of the dialog component (https://www.radix-ui.com/primitives/docs/components/dialog#root) we're using. As you can see, it has both.

open is a controlled param. If you pass open to true (instead of defaultOpen) people won't be able to close the dialog at all. defaultOpen just initializes the initial state of the dialog.

So in our case, we need defaultOpen=true but we need to tell the dialog component that it's not a controlled dialog by setting open=undefined in other words, not passing open.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but we are controlling the rendering state through {multiUrlImportState && (...., so if we don't want the dialog to show, we are not even rendering it.
And as for reusability: if you want to control the open state, then you pass in a proper state?

I will push again, for you to review, I am very convinced that the defaultOpen AND open state are not required at the same time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think functionality wise, this looks good. But with the current MultiInputDialog implementation, users won't be able to do an uncontrolled dialog with a trigger. I'll followup with a small PR to show you what I had in mind.

apps/web/components/ui/multiple-choice-dialog.tsx Outdated Show resolved Hide resolved
Added a reusable dialog
opening a dialog that allows you to decide if you want to import multiple URLs at once if you provide only that
Copy link
Collaborator

@MohamedBassem MohamedBassem left a comment

Choose a reason for hiding this comment

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

I think functionality wise, this PR looks good to me. Let me merge it and send a followup minor modifications to explain my point I guess.

@MohamedBassem MohamedBassem merged commit d1ad84b into hoarder-app:main May 19, 2024
3 of 5 checks passed
@kamtschatka kamtschatka deleted the multi-import branch June 23, 2024 16:58
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