From 08a628519a0200c844a1eee3cdbd3b86ec9e8b88 Mon Sep 17 00:00:00 2001 From: Maharshi Patel <39730881+maharshivpatel@users.noreply.github.com> Date: Tue, 16 Apr 2024 19:46:08 +0530 Subject: [PATCH] chore: generate image at the end for performance (#236) as generating the image is a slow operation, we should do it at the end --- .../js/print_designer/store/ElementStore.js | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/print_designer/public/js/print_designer/store/ElementStore.js b/print_designer/public/js/print_designer/store/ElementStore.js index cd391ec..de0b811 100644 --- a/print_designer/public/js/print_designer/store/ElementStore.js +++ b/print_designer/public/js/print_designer/store/ElementStore.js @@ -112,18 +112,12 @@ export const useElementStore = defineStore("ElementStore", { r = JSON.parse(xhr.responseText); if (r.message.doctype === "File") { file_url = r.message.file_url; - // if format is not saved then update the preview image value with it - if (MainStore.isFormatSaving) { - MainStore.print_designer_preview_img = file_url; - } else { - // if format is already saved then update the print_designer_preview_img field - frappe.db.set_value( - "Print Format", - MainStore.printDesignName, - "print_designer_preview_img", - file_url - ); - } + frappe.db.set_value( + "Print Format", + MainStore.printDesignName, + "print_designer_preview_img", + file_url + ); } } catch (e) { r = xhr.responseText; @@ -254,16 +248,12 @@ export const useElementStore = defineStore("ElementStore", { css: css, }; const PrintFormatData = this.getPrintFormatData({ header, body, footer }); - MainStore.isFormatSaving = true; - await this.generatePreview(); objectToSave.print_designer_print_format = PrintFormatData; - objectToSave.print_designer_preview_img = MainStore.print_designer_preview_img; if (MainStore.isOlderSchema("1.1.0")) { await this.printFormatCopyOnOlderSchema(objectToSave); } else { await frappe.db.set_value("Print Format", MainStore.printDesignName, objectToSave); - MainStore.isFormatSaving = false; frappe.show_alert( { message: `Print Format Saved Successfully`, @@ -271,6 +261,7 @@ export const useElementStore = defineStore("ElementStore", { }, 5 ); + await this.generatePreview(); } }, checkIfAnyTableIsEmpty() {