fix: Use watch function to watch changes

This commit is contained in:
Suraj Shetty 2023-06-23 14:37:33 +05:30
parent 3982eeea22
commit 0d4574e95b
3 changed files with 39 additions and 25 deletions

View file

@ -608,7 +608,8 @@ defineExpose({
add_files,
upload_files,
toggle_all_private,
wrapper_ready
wrapper_ready,
close_dialog,
});
</script>

View file

@ -1,5 +1,6 @@
import { createApp } from "vue";
import FileUploaderComponent from "./FileUploader.vue";
import { watch } from "vue";
class FileUploader {
constructor({
@ -52,8 +53,8 @@ class FileUploader {
this.uploader.wrapper_ready = true;
}
this.uploader.$watch(
"files",
watch(
() => this.uploader.files,
(files) => {
let all_private = files.every((file) => file.private);
if (this.dialog) {
@ -65,27 +66,36 @@ class FileUploader {
{ deep: true }
);
this.uploader.$watch("trigger_upload", (trigger_upload) => {
if (trigger_upload) {
this.upload_files();
watch(
() => this.uploader.trigger_upload,
(trigger_upload) => {
if (trigger_upload) {
this.upload_files();
}
}
});
);
this.uploader.$watch("close_dialog", (close_dialog) => {
if (close_dialog) {
this.dialog && this.dialog.hide();
watch(
() => this.uploader.close_dialog,
(close_dialog) => {
if (close_dialog) {
this.dialog && this.dialog.hide();
}
}
});
);
this.uploader.$watch("hide_dialog_footer", (hide_dialog_footer) => {
if (hide_dialog_footer) {
this.dialog && this.dialog.footer.addClass("hide");
this.dialog.$wrapper.data("bs.modal")._config.backdrop = "static";
} else {
this.dialog && this.dialog.footer.removeClass("hide");
this.dialog.$wrapper.data("bs.modal")._config.backdrop = true;
watch(
() => this.uploader.hide_dialog_footer,
(hide_dialog_footer) => {
if (hide_dialog_footer) {
this.dialog && this.dialog.footer.addClass("hide");
this.dialog.$wrapper.data("bs.modal")._config.backdrop = "static";
} else {
this.dialog && this.dialog.footer.removeClass("hide");
this.dialog.$wrapper.data("bs.modal")._config.backdrop = true;
}
}
});
);
if (files && files.length) {
this.uploader.add_files(files);

View file

@ -1,4 +1,4 @@
import { createApp } from "vue";
import { createApp, watch } from "vue";
import PrintFormatBuilderComponent from "./PrintFormatBuilder.vue";
class PrintFormatBuilder {
@ -32,8 +32,8 @@ class PrintFormatBuilder {
SetVueGlobals(app);
this.$component = app.mount(this.$wrapper.get(0));
this.$component.$watch(
"$store.dirty",
watch(
() => this.$component.$store.dirty,
(dirty) => {
if (dirty.value) {
this.page.set_indicator("Not Saved", "orange");
@ -48,9 +48,12 @@ class PrintFormatBuilder {
{ deep: true }
);
this.$component.$watch("show_preview", (value) => {
$toggle_preview_btn.text(value ? __("Hide Preview") : __("Show Preview"));
});
watch(
() => this.$component.show_preview,
(value) => {
$toggle_preview_btn.text(value ? __("Hide Preview") : __("Show Preview"));
}
);
}
}