From 03c3d0bc84cec7ee90fa4d48f59da23abf1cf58d Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Mon, 19 Aug 2024 10:02:52 -0400 Subject: [PATCH] Enable posting tree node selected keys via fetch (#18) --- package.json | 2 +- src/components/Tree/composable/tree.js | 18 ++++++-- src/components/Tree/tree.component.vue | 58 ++++++++++++++++++-------- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index b9a1927..64653dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fohn-ui", - "version": "1.8.0", + "version": "1.8.1", "description": "Javascript library for Fohn-Ui php framework.", "main": "dist/fohn-ui.min.js", "files": [ diff --git a/src/components/Tree/composable/tree.js b/src/components/Tree/composable/tree.js index b5ed358..ffb1897 100644 --- a/src/components/Tree/composable/tree.js +++ b/src/components/Tree/composable/tree.js @@ -1,4 +1,10 @@ import apiService from '../../../services/api.service'; +import { ref, watch } from 'vue'; + +const isTreeFetching = ref(false); +const useIsTreeFetching = () => { + return isTreeFetching; +}; /** * @@ -43,13 +49,17 @@ const useExtendedNode = (nodes, options) => { * - the raw value of the entire tree node, * */ -const usePostData = (url, action, key, selectedKeys, treeValue) => { +const useFetch = (url, payload) => { const options = { method: 'POST', - body: JSON.stringify({ __nodeAction: action, __nodeKey: key, __nodeKeys: selectedKeys, __treeValue: treeValue }), + body: JSON.stringify(payload), }; - const { data, onFetchFinally } = apiService.fetchAsResponse(url, options); + const { isFetching, data, onFetchFinally } = apiService.fetchAsResponse(url, options); + watch(isFetching, (inProgress) => { + isTreeFetching.value = inProgress; + }); + onFetchFinally(() => { const js = data.value?.jsRendered; if (js) { @@ -58,4 +68,4 @@ const usePostData = (url, action, key, selectedKeys, treeValue) => { }); }; -export { useStringKey, useExtendedNode, usePostData }; +export { useStringKey, useExtendedNode, useFetch, useIsTreeFetching }; diff --git a/src/components/Tree/tree.component.vue b/src/components/Tree/tree.component.vue index 4bd6f52..e280c32 100644 --- a/src/components/Tree/tree.component.vue +++ b/src/components/Tree/tree.component.vue @@ -1,7 +1,7 @@