Skip to content

Commit

Permalink
feat: get html content from editor correction
Browse files Browse the repository at this point in the history
  • Loading branch information
André Canuto authored and André Canuto committed Oct 26, 2023
1 parent 867324a commit a2356a3
Showing 1 changed file with 39 additions and 42 deletions.
81 changes: 39 additions & 42 deletions src/syncfusion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,33 @@ export class IaraSyncfusionAdapter
}

async sfdtToHtml(content: string) {
let endpoint = 'https://api.iarahealth.com/speech/syncfusion/sfdt_to_html/';
const endpoint =
"https://api.iarahealth.com/speech/syncfusion/sfdt_to_html/";

const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
...this._recognition.internal.iaraAPIMandatoryHeaders,
},
body: JSON.stringify({ sfdt: content }),
})
.then(async (response) => await response.json());
method: "POST",
headers: {
"Content-Type": "application/json",
...this._recognition.internal.iaraAPIMandatoryHeaders,
},
body: JSON.stringify({ sfdt: content }),
}).then(async response => await response.json());

return response;
}

async htmlToSfdt(content: string) {
let endpoint = 'https://api.iarahealth.com/speech/syncfusion/html_to_sfdt/';
const endpoint =
"https://api.iarahealth.com/speech/syncfusion/html_to_sfdt/";

const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
...this._recognition.internal.iaraAPIMandatoryHeaders,
},
body: JSON.stringify({ html: content }),
})
.then(async (response) => await response.json());
method: "POST",
headers: {
"Content-Type": "application/json",
...this._recognition.internal.iaraAPIMandatoryHeaders,
},
body: JSON.stringify({ html: content }),
}).then(async response => await response.json());

return response;
}
Expand All @@ -83,11 +83,25 @@ export class IaraSyncfusionAdapter
const response = await this.htmlToSfdt(template);
this._editor.open(response);
}

async getEditorContent() {
const content = await this._editor.saveAsBlob("Html")
const contentSfdt = await this._editor
.saveAsBlob("Sfdt")
.then((blob: Blob) => blob.text());
return content;

const response = fetch(
"https://api.iarahealth.com/speech/syncfusion/sfdt_to_html/",
{
headers: {
"Content-Type": "application/json",
...this._recognition.internal.iaraAPIMandatoryHeaders,
},
method: "POST",
body: contentSfdt,
}
);
const htmlContent = await response.then(response => response.json());
return htmlContent.html;
}

insertInference(inference: IaraInference) {
Expand All @@ -109,7 +123,7 @@ export class IaraSyncfusionAdapter
this.insertParagraph();
line = line.trimStart();
if (line) this.insertText(line);
});
});
}

private async _onContentChange() {
Expand All @@ -128,26 +142,9 @@ export class IaraSyncfusionAdapter
.saveAsBlob("Txt")
.then((blob: Blob) => blob.text());

const contentSfdt = await this._editor
.saveAsBlob("Sfdt")
.then((blob: Blob) => blob.text());
const contentHTML = await this.getEditorContent();

const response = fetch(
"https://api.iarahealth.com/speech/syncfusion/sfdt_to_html/",
{
headers: {
"Content-Type": "application/json",
...this._recognition.internal.iaraAPIMandatoryHeaders,
},
method: "POST",
body: contentSfdt,
}
);
const htmlContent = await response.then(response => response.json());

this._debounceToSave(() =>
this._onReportChanged(contentText, htmlContent.html)
);
this._debounceToSave(() => this._onReportChanged(contentText, contentHTML));
}

private _debounceToSave = (func: () => void) => {
Expand Down Expand Up @@ -202,7 +199,7 @@ export class IaraSyncfusionAdapter
}

editorToggleUnderline(): void {
this._editorAPI.toggleUnderline('Single');
this._editorAPI.toggleUnderline("Single");
}

editorToggleUppercase(): void {
Expand Down

0 comments on commit a2356a3

Please sign in to comment.