@credithub/harlan-components 1.59.2 → 1.59.3
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/components/liminar/liminar.js +41 -4
- package/lib/cjs/index.js +42 -5
- package/lib/esm/index.js +42 -5
- package/package.json +1 -1
|
@@ -16,19 +16,49 @@ import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
|
16
16
|
import StatusMessage from '../interface/statusMessage';
|
|
17
17
|
import Section from '../section';
|
|
18
18
|
import { Queries, RequestStatus } from '../webservice';
|
|
19
|
+
function useStableValue(value) {
|
|
20
|
+
var _a = useState(value), stableValue = _a[0], setStableValue = _a[1];
|
|
21
|
+
var lastValueRef = useRef(value);
|
|
22
|
+
var consecutiveFramesRef = useRef(0);
|
|
23
|
+
useEffect(function () {
|
|
24
|
+
lastValueRef.current = value;
|
|
25
|
+
consecutiveFramesRef.current = 0;
|
|
26
|
+
var frame;
|
|
27
|
+
function check() {
|
|
28
|
+
if (lastValueRef.current === value) {
|
|
29
|
+
consecutiveFramesRef.current++;
|
|
30
|
+
if (consecutiveFramesRef.current >= 2) {
|
|
31
|
+
setStableValue(value);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
consecutiveFramesRef.current = 0;
|
|
37
|
+
lastValueRef.current = value;
|
|
38
|
+
}
|
|
39
|
+
frame = requestAnimationFrame(check);
|
|
40
|
+
}
|
|
41
|
+
frame = requestAnimationFrame(check);
|
|
42
|
+
return function () { return cancelAnimationFrame(frame); };
|
|
43
|
+
}, [value]);
|
|
44
|
+
return stableValue;
|
|
45
|
+
}
|
|
19
46
|
var Liminar = function () {
|
|
20
47
|
var _a, _b, _c;
|
|
21
48
|
var ctx = useContext(Queries.LiminarCenprot);
|
|
22
49
|
var _d = useGlobalData(), globalData = _d.data, setData = _d.setData;
|
|
23
50
|
var _e = useState(undefined), liminarResult = _e[0], setLiminarResult = _e[1];
|
|
24
51
|
var _f = useState(true), isProcessing = _f[0], setIsProcessing = _f[1];
|
|
25
|
-
var didRunRef = useRef(false);
|
|
26
52
|
var carousel = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.dossie) === null || _a === void 0 ? void 0 : _a.carousel;
|
|
27
53
|
var isPJDataLoaded = (_b = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _b === void 0 ? void 0 : _b.isLoaded;
|
|
28
54
|
var empresas = (_c = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData) === null || _c === void 0 ? void 0 : _c.empresa;
|
|
55
|
+
var dataHash = useMemo(function () { return JSON.stringify({ carousel: carousel, isPJDataLoaded: isPJDataLoaded, empresas: empresas }); }, [carousel, isPJDataLoaded, empresas]);
|
|
56
|
+
var stableDataHash = useStableValue(dataHash);
|
|
29
57
|
useEffect(function () {
|
|
30
58
|
var _a;
|
|
31
|
-
if (
|
|
59
|
+
if (stableDataHash !== dataHash)
|
|
60
|
+
return;
|
|
61
|
+
if (!carousel || !isPJDataLoaded)
|
|
32
62
|
return;
|
|
33
63
|
var empresaNomeNormalizado = normalizeName((carousel === null || carousel === void 0 ? void 0 : carousel.name) || '');
|
|
34
64
|
var validAssuntos = [
|
|
@@ -71,8 +101,15 @@ var Liminar = function () {
|
|
|
71
101
|
setData(function (prev) { return (__assign(__assign({}, prev), { liminar: { indiciosDeLiminar: indiciosDeLiminar, message: finalStatus } })); });
|
|
72
102
|
setLiminarResult(finalStatus);
|
|
73
103
|
setIsProcessing(false);
|
|
74
|
-
|
|
75
|
-
|
|
104
|
+
}, [
|
|
105
|
+
stableDataHash,
|
|
106
|
+
dataHash,
|
|
107
|
+
carousel,
|
|
108
|
+
isPJDataLoaded,
|
|
109
|
+
empresas,
|
|
110
|
+
ctx,
|
|
111
|
+
setData
|
|
112
|
+
]);
|
|
76
113
|
var isProcessoNaoEncontrado = ctx.type === RequestStatus.Error &&
|
|
77
114
|
String(ctx.error).includes('Processo(s) não encontrado(s).');
|
|
78
115
|
var derivedCtx = useMemo(function () { return (__assign(__assign({}, ctx), { type: isProcessoNaoEncontrado ? RequestStatus.Success : ctx.type, document: isProcessoNaoEncontrado
|