michelson / dante2

A complete rewrite of dante editor in draft-js
https://michelson.github.io/dante2/
Other
912 stars 121 forks source link

default_storage not calling endpoint #203

Closed HugoSanchez closed 4 years ago

HugoSanchez commented 4 years ago

Hi!

I'm not being able to use the data_storage option to send the content to a basic backend endpoint that I've built with express.

Here's what I'm doing:

import React from 'react';
import DanteEditor from "Dante2";

const Editor = props => {

    const defaultOptions = {
        debug: true,
        read_only: true,

        xhr: {
            before_handler: () => console.log('Try1'),
            success_handler: () => console.log('Try2'),
            error_handler: () => console.log('Try3'),
        },

        data_storage: {
            url: 'http://localhost:8000/',
            method: "POST",
            success_handler: () => console.log('Succeeding'),
            failure_handler: () => console.log('Failing'),
            interval: 500,
            withCredentials: false,
            crossDomain: false,
            headers: {}
        },
    }

    return (
        <div className="Main">
               <DanteEditor  
                    content={null}  
                    config={defaultOptions}/>
        </div>
    );
}

export default Editor;

The editor works properly but no calls to the endpoint are being made.

Is there anything that I am missing?

I'm expecting to receive a request to the endpoint but absolutely nothing happens, nothing gets console logged neither. I've tested the endpoint with postman and it works.

Any tips would be very appreciated.

Thanks!

michelson commented 4 years ago

try passing the data_storage as a prop like DanteEditor data_storage={myConfig} />

Atte. Miguel Michelson Martinez www.vadb.org http://vadb.org

On Tue, Feb 4, 2020 at 5:10 PM Hugo Sanchez notifications@github.com wrote:

Hi!

I'm not being able to use the data_storage option to send the content to a basic backend endpoint that I've built with express.

Here's what I'm doing:

import React from 'react'; import DanteEditor from "Dante2";

const Editor = props => {

const defaultOptions = { data_storage: { url: 'http://localhost:8000/', method: "POST", success_handler: () => console.log('Succeeding'), failure_handler: () => console.log('Failing'), interval: 500, withCredentials: false, crossDomain: false, headers: {} }, }

return (

);

export default Editor;

The editor works properly but no calls to the endpoint are being made.

Is there anything that I am missing?

I'm expecting to receive a request to the endpoint but absolutely nothing happens, nothing gets console logged neither. I've tested the endpoint with postman and it works.

Any tips would be very appreciated.

Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/michelson/dante2/issues/203?email_source=notifications&email_token=AAAC5SCDJI34L7YPMHEDZB3RBHDVBA5CNFSM4KP5HEUKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ILAGBVA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAC5SHBJYHWCDNWNFJS5FLRBHDVBANCNFSM4KP5HEUA .

HugoSanchez commented 4 years ago

That seems to work although I now have a CORS problem I need to solve first.

By the way, is there any way to get the content before the endpoint is called?

Thank you for getting back so quick!

michelson commented 4 years ago

the editor content is updated without needing to update your component state.

if you want to get the content every time you have changes you can use save_handler: func (editorContext, content) and build your own ajax function.

also , there is indeed a before_handler but it's not returning the content on the callback

Atte. Miguel Michelson Martinez www.vadb.org http://vadb.org

On Tue, Feb 4, 2020 at 5:40 PM Hugo Sanchez notifications@github.com wrote:

That seems to work although I know have a CORS problem I need to solve first.

By the way, is there any way to get the content before the endpoint is called?

Thank you for getting back so quick!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/michelson/dante2/issues/203?email_source=notifications&email_token=AAAC5SGTNSZ4HKUB3TAERGLRBHHE5A5CNFSM4KP5HEUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKZDOJA#issuecomment-582104868, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAC5SC4S4P2PNNX5AOS6STRBHHE5ANCNFSM4KP5HEUA .

HugoSanchez commented 4 years ago

Thank you for your help and sorry to ask you again, but can you please share an example of how to use "save_handler"?

I've tried using it like so, but nothing happens: <DanteEditor content={null} config={defaultOptions} data_storage={{save_handler: function(editorContext, content) { console.log('Editor Context: ', editorContext) console.log('Editor Content: ', content) }}}/>

Not sure what I am doing wrong.

Thank you

michelson commented 4 years ago

sorry, use this structure, note the dummy url prop

data_storage={
{
url: "/",
save_handler: (editorContext, content)=>{ ... }
}
}

Atte. Miguel Michelson Martinez www.vadb.org http://vadb.org

On Tue, Feb 4, 2020 at 6:12 PM Hugo Sanchez notifications@github.com wrote:

Thank you for your help and sorry to ask you again, but can you please share an example of how to use "save_handler"?

I've tried using it like so, but nothing happens: <DanteEditor content={null} config={defaultOptions} data_storage={{save_handler: function(editorContext, content) { console.log('Editor Context: ', editorContext) console.log('Editor Content: ', content) }}}/>

Not sure what I am doing wrong.

Thank you

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/michelson/dante2/issues/203?email_source=notifications&email_token=AAAC5SHO2HSEOREWKIIUDBLRBHK25A5CNFSM4KP5HEUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKZGOWY#issuecomment-582117211, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAC5SA4STSHIYNYDUPEYU3RBHK25ANCNFSM4KP5HEUA .

HugoSanchez commented 4 years ago

That worked, thanks so much and congratulations on the great work!

michelson commented 4 years ago

glad it work , @HugoSanchez !