From b05a25e6aa25951cbf9b5af2c839c9a717665e7c Mon Sep 17 00:00:00 2001 From: Anuj Subedi Date: Wed, 24 May 2023 11:56:23 +0545 Subject: [PATCH 01/19] =?UTF-8?q?=F0=9F=90=B9=20Tweak:=20How=20reactive=20?= =?UTF-8?q?state=20on=20plugin=20setting's=20page=20is=20managed=20(vue=20?= =?UTF-8?q?js).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🐹 Tweak: How reactive state on plugin setting's page is managed (vue js). --- README.txt | 8 ++++-- addonify-wishlist.php | 4 +-- admin/app/dist/manifest.json | 14 ---------- admin/app/dist/vite-dev-server.json | 1 + admin/app/src/helpers/api.ts | 12 +++++++++ admin/app/src/stores/products.js | 5 +++- admin/app/src/stores/settings.ts | 42 ++++++++++++++++++++++++++--- admin/app/src/views/Products.vue | 14 +++++++++- admin/app/src/views/Setting.vue | 13 ++++++++- admin/app/src/views/Upsell.vue | 13 ++++++++- 10 files changed, 101 insertions(+), 25 deletions(-) delete mode 100644 admin/app/dist/manifest.json create mode 100644 admin/app/dist/vite-dev-server.json create mode 100644 admin/app/src/helpers/api.ts diff --git a/README.txt b/README.txt index 69d264c..153c476 100644 --- a/README.txt +++ b/README.txt @@ -3,8 +3,8 @@ Contributors: addonify Tags: wishlist, woocommerce wishlist, product wishlist, woocommerce, ecommerce, e-commerce Requires at least: 5.9 -Tested up to: 6.2.1 -Stable tag: 2.0.2 +Tested up to: 6.2.2 +Stable tag: 2.0.3 Requires PHP: 7.4 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -141,6 +141,10 @@ You can use this `[addonify_wishlist]` shortcode to display the wishlist table i == Changelog == += 2.0.3 - 24 May, 2023 = + +- Tweak: How reactive state on plugin setting's page is managed (vue js). + = 2.0.2 - 18 May, 2023 = - Removed: Added to cart popup modal displayed when product is added to cart in wishlist page. diff --git a/addonify-wishlist.php b/addonify-wishlist.php index 11754dc..0b09422 100644 --- a/addonify-wishlist.php +++ b/addonify-wishlist.php @@ -10,7 +10,7 @@ * Plugin Name: Addonify - WooCommerce Wishlist * Plugin URI: https://wordpress.org/plugins/addonify-wishlist * Description: Addonify WooCommerce Wishlist is a light-weight yet powerful tool that adds a wishlist functionality to your e-commerce shop. - * Version: 2.0.2 + * Version: 2.0.3 * Requires at least: 5.9 * Requires PHP: 7.4 * Author: Addonify @@ -26,7 +26,7 @@ die; } -define( 'ADDONIFY_WISHLIST_VERSION', '2.0.2' ); +define( 'ADDONIFY_WISHLIST_VERSION', '2.0.3' ); define( 'ADDONIFY_WISHLIST_DB_INITIALS', 'addonify_wishlist_' ); define( 'ADDONIFY_WISHLIST_PLUGIN_PATH', dirname( __FILE__ ) ); define( 'ADDONIFY_WISHLIST_PLUGIN_FILE', __FILE__ ); diff --git a/admin/app/dist/manifest.json b/admin/app/dist/manifest.json deleted file mode 100644 index b9bd749..0000000 --- a/admin/app/dist/manifest.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "admin/app/src/main.css": { - "file": "assets/main-3233b0e6.css", - "src": "admin/app/src/main.css" - }, - "admin/app/src/main.js": { - "css": [ - "assets/main-3233b0e6.css" - ], - "file": "assets/main-98d2bd3a.js", - "isEntry": true, - "src": "admin/app/src/main.js" - } -} \ No newline at end of file diff --git a/admin/app/dist/vite-dev-server.json b/admin/app/dist/vite-dev-server.json new file mode 100644 index 0000000..cd9d30e --- /dev/null +++ b/admin/app/dist/vite-dev-server.json @@ -0,0 +1 @@ +{"base":"/","origin":"http://localhost:5173","port":5173,"plugins":[]} \ No newline at end of file diff --git a/admin/app/src/helpers/api.ts b/admin/app/src/helpers/api.ts new file mode 100644 index 0000000..daa7514 --- /dev/null +++ b/admin/app/src/helpers/api.ts @@ -0,0 +1,12 @@ +/** + * + * Common headers for all requests. + * + * @since: 2.0.3 + */ + +export const commonHeader = { + charset: "utf-8", + "cache-control": "no-cache", + "content-type": "application/json", +}; diff --git a/admin/app/src/stores/products.js b/admin/app/src/stores/products.js index 8ee7718..c03ee27 100644 --- a/admin/app/src/stores/products.js +++ b/admin/app/src/stores/products.js @@ -2,6 +2,7 @@ import { defineStore } from "pinia"; import { ElMessage } from "element-plus"; import { useSettingsStore } from "@stores/settings"; import { recommendedProductsList } from "@helpers/endpoint"; +import { commonHeader } from "@helpers/api"; /** * @@ -200,6 +201,7 @@ export const useProductStore = defineStore({ method: "GET", path: `/wp/v2/plugins`, + headers: commonHeader, }); //console.log(res); @@ -291,7 +293,7 @@ export const useProductStore = defineStore({ method: "POST", path: "/wp/v2/plugins", - + headers: commonHeader, data: { slug: slug, status: "active", @@ -361,6 +363,7 @@ export const useProductStore = defineStore({ method: "POST", path: `/wp/v2/plugins/${slug}`, + headers: commonHeader, data: { status: "active", plugin: `${slug}/${slug}`, diff --git a/admin/app/src/stores/settings.ts b/admin/app/src/stores/settings.ts index 9e03de4..2b65dc0 100644 --- a/admin/app/src/stores/settings.ts +++ b/admin/app/src/stores/settings.ts @@ -2,6 +2,7 @@ import { defineStore } from "pinia"; import { ElMessage } from "element-plus"; // @ts-ignore import { apiEndpoint } from "@helpers/endpoint"; // @ts-ignore import { jsonFileName } from "@helpers/global"; // @ts-ignore +import { commonHeader } from "@helpers/api"; // @ts-ignore /** * @@ -22,7 +23,7 @@ const { __ } = wp.i18n; * @since 2.0.0 */ -let oldSettings: any = {}; +let oldSettings: any = []; /** * @@ -70,6 +71,19 @@ export const useSettingsStore = defineStore({ */ haveChanges: (state: any): boolean => !isEqual(state.settings, oldSettings) ? true : false, + + /** + * + * Check if we do have state of settings in the memory. + * If we do have, then return true. + * + * @param {Object} state + * @returns {boolean} true/false + * @since 2.0.3 + */ + + haveSettingsStateInMemory: (state: any): boolean => + Object.keys(state.settings).length === 0 ? false : true, }, actions: { @@ -95,6 +109,7 @@ export const useSettingsStore = defineStore({ apiFetch({ path: apiEndpoint + "/get_options", method: "GET", + headers: commonHeader, }) .then((res: any) => { /** @@ -151,6 +166,7 @@ export const useSettingsStore = defineStore({ apiFetch({ path: `${apiEndpoint}/${endpoint}`, method: "POST", + headers: commonHeader, }) .then((res: any) => { /** @@ -234,6 +250,7 @@ export const useSettingsStore = defineStore({ apiFetch({ path: apiEndpoint + "/update_options", method: "POST", + headers: commonHeader, data: { settings_values: payload, }, @@ -255,12 +272,21 @@ export const useSettingsStore = defineStore({ offset: 50, duration: 3000, }); + + let tempOptionsState = cloneDeep(this.settings); + this.settings = {}; + this.settings = cloneDeep(tempOptionsState); + oldSettings = cloneDeep(this.settings); } else { ElMessage.error({ message: res.message, offset: 50, duration: 10000, }); + + setTimeout(() => { + window.location.reload(); + }, 2000); } }) .catch((err: any) => { @@ -276,9 +302,13 @@ export const useSettingsStore = defineStore({ offset: 50, duration: 10000, }); + + let tempOptionsState = cloneDeep(oldSettings); + this.settings = {}; + this.settings = cloneDeep(tempOptionsState); }) .finally(() => { - this.fetchSettings(); + //this.fetchSettings(); this.status.isSaving = false; }); }, @@ -306,6 +336,7 @@ export const useSettingsStore = defineStore({ apiFetch({ path: apiEndpoint + "/export_options", method: "GET", + headers: commonHeader, }) .then((res: any) => { /** @@ -380,6 +411,7 @@ export const useSettingsStore = defineStore({ apiFetch({ path: apiEndpoint + "/import_options", method: "POST", + headers: commonHeader, body: payload, }) .then((res: any) => { @@ -396,6 +428,10 @@ export const useSettingsStore = defineStore({ offset: 50, duration: 3000, }); + + setTimeout(() => { + window.location.reload(); + }, 2000); } else { ElMessage.error({ message: this.status.message, @@ -420,7 +456,7 @@ export const useSettingsStore = defineStore({ }); }) .finally(() => { - this.fetchSettings(); + //this.fetchSettings(); this.status.isImporting = false; }); }, diff --git a/admin/app/src/views/Products.vue b/admin/app/src/views/Products.vue index b0e095c..644163a 100644 --- a/admin/app/src/views/Products.vue +++ b/admin/app/src/views/Products.vue @@ -53,7 +53,19 @@ onBeforeMount(() => { onMounted(() => { scrollToTop(); - store.fetchSettings(); // For the route links. + + /** + * + * Check state of options in memory. + * If we have state in memory, we can use it. + * If not, we need to fetch it from the server. + * + * @since: 2.0.3 + */ + + if (!store.haveSettingsStateInMemory) { + store.fetchSettings(); + } /** * diff --git a/admin/app/src/views/Setting.vue b/admin/app/src/views/Setting.vue index 5a8d10b..c4cc0c1 100644 --- a/admin/app/src/views/Setting.vue +++ b/admin/app/src/views/Setting.vue @@ -12,7 +12,18 @@ import { advertiseUpsell } from "@helpers/global"; const store = useSettingsStore(); onMounted(() => { - store.fetchSettings(); + /** + * + * Check state of options in memory. + * If we have state in memory, we can use it. + * If not, we need to fetch it from the server. + * + * @since: 2.0.3 + */ + + if (!store.haveSettingsStateInMemory) { + store.fetchSettings(); + } });