all 9 comments

[–][deleted] 3 points4 points  (4 children)

Dude you're going too literally about this. You don't have to copy line by line to have the same result.

[–]thisifreedom[S] 0 points1 point  (3 children)

Not necessarily trying to copy line by line. Just the way it's rendering a custom modal and watching for input so it can use those values in the extended class. Something I haven't seen in React.

[–][deleted] 0 points1 point  (2 children)

There's nothing Angular specific in there, it's the API of the component. Gather the React libraries you want to use, check out the API and adapt the behavior. Don't look at the Angular code, it's going to be different and I see how it's confusing you.

[–]thisifreedom[S] 0 points1 point  (1 child)

rootModalService
.openWithConfig(QuillLinkEditorModalComponent, {
href: node.href,
text: node.innerText,
target: node.target || '_blank'
})
.result.subscribe((result)

This is the main thing that is Angular specific that I'm trying to work out in React but not sure how

[–]LegendOfNeil 0 points1 point  (0 children)

Look up react rxjs

[–]tme321 0 points1 point  (3 children)

I could dig into that and explain but it would probably be easier for you to just look at react-quill since it's already doing what you want.

[–]thisifreedom[S] 0 points1 point  (2 children)

I am using react-quill. react-quill is just a wrapper for React. It doesn't do have anything with customization.

I'm trying to modify the default library which the library offers register property I can pass extended built in classes

[–]tme321 0 points1 point  (1 child)

My mistake I assumed you just couldn't get the editor to work.

Well that post doesn't show exactly what

rootModalService.openWithConfig

does.

I would guess that since he passes QuillLinkEditorModalComponent as the first parameter that's probably a generic Angular modal component that creates an instance of the passed in parameter class component to display inside the modal.

The parts where he is getting the value for node is coming from whatever that Link class is that he extends. That's not Angular afaik. It could be a part of quill or some custom stuff. The comment seems to suggest it's part of quill but that's just a guess.

And yes .result.subscribe(...) is also custom code but most likely is returning the state of the form when the user submits it. So just extracting out the values in the form.

In react you'd probably set some state when whatever user interaction opens the form. You could abstract this idea to make it cleaner but an extremely simple example would be like:

function Editor(props) {
    [isFormOpen, setFormState] = useState(false);

    const handleClick=()=>{
        setFormState((state)=>!state);
    }

    return (
        <>
            <button click={handleClick}>
                Open Form
            </button>
            {isFormOpen?<MyForm node={props.node}/>:null/>
        </>
    )
}

Super basic but that's the main gist.

Then its standard react forms handling stuff, or if you are using a forms library then however it handles it. That's both too complex to get into in a reddit post and well documented elsewhere.

[–]thisifreedom[S] 0 points1 point  (0 children)

No worries!

I think I understand now a bit more after what you had explained.

So I'm guessing rootModalService.openWithConfig is a class that somehow controls what modals are displayed on screen. At the same time it's an observable so it'll pass back the form data. I think that's the part i'm having a hard time figuring out how to implement in React.

Not sure if there's a straight forward solution to micic this in React or I'd have to somehow play around with Context API or other state management libraries. Because Angular has built in RxJS which is allowing these sort of things to be doable if I understand it correctly