argous 1.2.149 → 1.2.150
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.
|
@@ -284,6 +284,18 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
284
284
|
}), dados = _d[0], setDados = _d[1];
|
|
285
285
|
var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
|
|
286
286
|
var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
|
|
287
|
+
var interval = react_1.useRef(null);
|
|
288
|
+
var _g = react_1.useState(1), seconds = _g[0], setSeconds = _g[1];
|
|
289
|
+
var startCounter = function () { return interval.current = setInterval(function () { return setSeconds(1); }, 1000); };
|
|
290
|
+
var stopCounter = function () {
|
|
291
|
+
clearInterval(interval.current);
|
|
292
|
+
setSeconds(0);
|
|
293
|
+
};
|
|
294
|
+
var setInput = function (value) {
|
|
295
|
+
stopCounter();
|
|
296
|
+
setInputValue(value);
|
|
297
|
+
startCounter();
|
|
298
|
+
};
|
|
287
299
|
function carimbaLista(lista) {
|
|
288
300
|
return __awaiter(this, void 0, void 0, function () {
|
|
289
301
|
var completo;
|
|
@@ -306,6 +318,7 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
306
318
|
return __generator(this, function (_c) {
|
|
307
319
|
switch (_c.label) {
|
|
308
320
|
case 0:
|
|
321
|
+
stopCounter();
|
|
309
322
|
setLoading(true);
|
|
310
323
|
return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
|
|
311
324
|
case 1:
|
|
@@ -327,10 +340,10 @@ var AutoCompleteFavorites = function (_a) {
|
|
|
327
340
|
}
|
|
328
341
|
});
|
|
329
342
|
}); }, [inputValue, searchParams]);
|
|
330
|
-
react_1.useEffect(function () { return buscar(); }, [
|
|
343
|
+
react_1.useEffect(function () { return seconds === 1 && buscar(); }, [seconds, buscar]);
|
|
331
344
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
332
345
|
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
333
|
-
return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value, onChange: onChange }, { options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', onInputChange: function (e) { var _a; return
|
|
346
|
+
return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value, onChange: onChange }, { options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', onInputChange: function (e) { var _a; return setInput(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, getOptionSelected: function (o, v) { return o[0] === v; }, autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
334
347
|
params.InputProps.endAdornment,
|
|
335
348
|
react_1.default.createElement(core_1.Fade, { in: loading },
|
|
336
349
|
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })))) }) }))); }, ListboxComponent: ListboxFavorites, ListboxProps: { dados: dados, setDados: setDados, favoritePage: favoritePage, groupHeaderColor: groupHeaderColor, groupTitleColor: groupTitleColor } })));
|
|
@@ -3,7 +3,7 @@ import { CircularProgress, Fade, ListItem, ListItemText, ListSubheader, makeStyl
|
|
|
3
3
|
import { Autocomplete } from '@material-ui/lab';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import { isObject, isString } from 'lodash';
|
|
6
|
-
import React, { forwardRef, useCallback, useEffect, useState } from 'react';
|
|
6
|
+
import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
const useStyles = makeStyles((theme) => ({
|
|
9
9
|
subHeader: {
|
|
@@ -226,6 +226,21 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
226
226
|
const [loading, setLoading] = useState(false);
|
|
227
227
|
const [inputValue, setInputValue] = useState('');
|
|
228
228
|
|
|
229
|
+
const interval = useRef(null);
|
|
230
|
+
const [seconds, setSeconds] = useState(1);
|
|
231
|
+
|
|
232
|
+
const startCounter = () => interval.current = setInterval(() => setSeconds(1), 1000);
|
|
233
|
+
const stopCounter = () => {
|
|
234
|
+
clearInterval(interval.current);
|
|
235
|
+
setSeconds(0);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const setInput = value => {
|
|
239
|
+
stopCounter();
|
|
240
|
+
setInputValue(value);
|
|
241
|
+
startCounter();
|
|
242
|
+
};
|
|
243
|
+
|
|
229
244
|
async function carimbaLista(lista) {
|
|
230
245
|
let completo = [];
|
|
231
246
|
lista.map((arr, index) => {
|
|
@@ -237,6 +252,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
237
252
|
}
|
|
238
253
|
|
|
239
254
|
const buscar = useCallback(async valor => {
|
|
255
|
+
stopCounter();
|
|
240
256
|
setLoading(true);
|
|
241
257
|
const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
|
|
242
258
|
if (res[resposta || 'result']?.length > 1) await carimbaLista(res[resposta || 'result']);
|
|
@@ -246,7 +262,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
246
262
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
247
263
|
}, [inputValue, searchParams]);
|
|
248
264
|
|
|
249
|
-
useEffect(() => buscar(), [
|
|
265
|
+
useEffect(() => seconds === 1 && buscar(), [seconds, buscar]);
|
|
250
266
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
251
267
|
useEffect(() => isString(value) && buscar(value), []);
|
|
252
268
|
|
|
@@ -257,7 +273,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
|
|
|
257
273
|
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
258
274
|
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
259
275
|
noOptionsText={inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado'}
|
|
260
|
-
onInputChange={e =>
|
|
276
|
+
onInputChange={e => setInput(e?.target?.value || '')}
|
|
261
277
|
getOptionSelected={(o, v) => o[0] === v}
|
|
262
278
|
autoComplete
|
|
263
279
|
autoHighlight
|