@zauru-sdk/hooks 2.0.122 → 2.0.123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/catalogs.js +5 -0
- package/dist/esm/templates.js +5 -6
- package/package.json +2 -2
package/dist/esm/catalogs.js
CHANGED
|
@@ -21,6 +21,7 @@ const redux_1 = require("@zauru-sdk/redux");
|
|
|
21
21
|
function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherParams } = {}) {
|
|
22
22
|
const dispatch = (0, redux_1.useAppDispatch)();
|
|
23
23
|
const fetcher = (0, react_1.useFetcher)();
|
|
24
|
+
const [fetchTriggered, setFetchTriggered] = (0, react_2.useState)(false);
|
|
24
25
|
const catalogData = (0, redux_1.useAppSelector)((state) => state.catalogs[CATALOG_NAME]);
|
|
25
26
|
// Verifica si ya tenemos algo en Redux
|
|
26
27
|
const hasLocalData = Boolean(catalogData?.data?.length);
|
|
@@ -61,6 +62,7 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
61
62
|
: "";
|
|
62
63
|
// Disparamos la carga a través de fetcher
|
|
63
64
|
try {
|
|
65
|
+
setFetchTriggered(true);
|
|
64
66
|
fetcher.load(`/api/catalogs?catalog=${CATALOG_NAME}${queryString}`);
|
|
65
67
|
}
|
|
66
68
|
catch (error) {
|
|
@@ -97,6 +99,9 @@ function useGetReduxCatalog(CATALOG_NAME, { online = false, wheres = [], otherPa
|
|
|
97
99
|
* y decide qué hacer con la data o error recibidos.
|
|
98
100
|
*/
|
|
99
101
|
(0, react_2.useEffect)(() => {
|
|
102
|
+
// Solo ejecuto la lógica si ya disparé al menos un fetch
|
|
103
|
+
if (!fetchTriggered)
|
|
104
|
+
return;
|
|
100
105
|
// Cuando fetcher se pone en "idle", significa que ya terminó la petición.
|
|
101
106
|
if (fetcher.state === "idle") {
|
|
102
107
|
// Caso: tenemos algo en fetcher.data
|
package/dist/esm/templates.js
CHANGED
|
@@ -9,6 +9,7 @@ function useGetTemplateObject(TEMPLATE_NAME, config = {}) {
|
|
|
9
9
|
try {
|
|
10
10
|
const dispatch = (0, redux_1.useAppDispatch)();
|
|
11
11
|
const fetcher = (0, react_1.useFetcher)();
|
|
12
|
+
const [fetchTriggered, setFetchTriggered] = (0, react_2.useState)(false);
|
|
12
13
|
// Obtenemos del store lo que ya se tenga
|
|
13
14
|
const objectData = (0, redux_1.useAppSelector)((state) => state.templates[TEMPLATE_NAME]);
|
|
14
15
|
// Verifica si ya tenemos algo en Redux
|
|
@@ -32,6 +33,7 @@ function useGetTemplateObject(TEMPLATE_NAME, config = {}) {
|
|
|
32
33
|
dispatch((0, redux_1.templateFetchStart)(TEMPLATE_NAME));
|
|
33
34
|
// Aquí hacemos la llamada a la API a través del fetcher
|
|
34
35
|
try {
|
|
36
|
+
setFetchTriggered(true);
|
|
35
37
|
fetcher.load(`/api/templates?object=${TEMPLATE_NAME}`);
|
|
36
38
|
}
|
|
37
39
|
catch (error) {
|
|
@@ -63,6 +65,9 @@ function useGetTemplateObject(TEMPLATE_NAME, config = {}) {
|
|
|
63
65
|
* Decidimos si lo que vino es error o data, y procedemos.
|
|
64
66
|
*/
|
|
65
67
|
(0, react_2.useEffect)(() => {
|
|
68
|
+
// Solo ejecuto la lógica si ya disparé al menos un fetch
|
|
69
|
+
if (!fetchTriggered)
|
|
70
|
+
return;
|
|
66
71
|
if (fetcher.state === "idle") {
|
|
67
72
|
if (fetcher.data) {
|
|
68
73
|
// Podría ser un error o ser la data
|
|
@@ -72,12 +77,6 @@ function useGetTemplateObject(TEMPLATE_NAME, config = {}) {
|
|
|
72
77
|
if (possibleError.description) {
|
|
73
78
|
// Ya teníamos datos locales?
|
|
74
79
|
if (hasLocalData) {
|
|
75
|
-
// Mostramos alert, pero NO borramos los datos locales
|
|
76
|
-
(0, index_js_1.showAlert)({
|
|
77
|
-
type: possibleError.type || "error",
|
|
78
|
-
title: possibleError.title || "Error",
|
|
79
|
-
description: possibleError.description,
|
|
80
|
-
});
|
|
81
80
|
// Dejamos loading en false, data queda como estaba
|
|
82
81
|
setData((prev) => ({ ...prev, loading: false }));
|
|
83
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.123",
|
|
4
4
|
"description": "Hooks reutilizables dentro de las webapps de Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"react": "^18.2.0",
|
|
34
34
|
"react-dom": "^18.2.0"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a09530092b4fe47f91456c18b9463fe012737e09"
|
|
37
37
|
}
|