I have react
and editor.js
that I use to create an entry in my Solid pod
. Everything seems to be good, but when I write text too quickly / often, from time to time I get a 409 (Conflict)
error and the text in the Solid pod
is not saved correctly. I can’t debug why this is happening.
editor
<EditorJs data={{blocks: editorData}}
defaultBlock={'solidNote'}
enableReInitialize={true}
tools={{
solidNote: {
class: SolidNote,
inlineToolbar: true
},
}}
/>
SolidNote
export default class SolidBase {
public readonly blockApi: BlockAPI;
public readonly config: any;
public readonly coreApi: API;
public readonly data: { model: Model | null };
public model: Model | null;
public element: HTMLDivElement;
public HYPERCUBE_URL: string | undefined;
constructor(toolConfig: any) {
this.data = toolConfig.data;
this.coreApi = toolConfig.api;
this.config = toolConfig.config;
this.blockApi = toolConfig.block;
this.model = this.data.model;
this.element = this.createElement()
getSession().then((session) => {
// @ts-ignore
this.HYPERCUBE_URL = HYPERCUBE_ROOT.replace('{podUrl}', new URL(session.webId).origin)
})
}
getInput() {
return this.element.innerHTML
}
removed() {
this.model!.delete()
}
updated() {
if (this.model!.content != this.getInput()) {
this.model!.content = this.getInput()
// @ts-ignore
this.model.save(this.HYPERCUBE_URL)
.then(r => console.log('item saved', r))
.catch(err => console.log(err))
}
}
createElement(): HTMLDivElement {
throw new Error("Method 'createElement()' must be implemented.");
}
render() {
return this.element
}
}
export default class SolidNote extends SolidBase{
private readonly placeholder: string;
constructor(toolConfig: any) {
super(toolConfig)
this.placeholder = '...add your note'
if (this.data.model === null || this.data.model === undefined) {
this.model = new Note({
content: '',
type: BLOCK_TYPES.note
});
}
this.element = this.createElement()
}
createElement(): HTMLDivElement {
let el = document.createElement('div')
el.classList.add('ce-paragraph', this.coreApi.styles.block)
// @ts-ignore
el.contentEditable = true;
el.dataset.placeholder = this.coreApi.i18n.t(this.placeholder)
if (this.model !== undefined) {
el.innerHTML = this.model!.content;
}
return el;
}
}