decord/source/modules/games/autocomplete/useGameAutocomplete.tsx
2026-07-27 11:26:19 +00:00

131 lines
3.6 KiB
TypeScript

// Module ID: 6118
// Function ID: 54933
// Name: fetchStore
// Dependencies: [57, 31, 6108, 653, 566, 6109, 6119, 2]
// Exports: useDebouncedGameAutocomplete
// Module 6118 (fetchStore)
import _slicedToArray from "_slicedToArray";
import result from "result";
import importDefaultResult from "_isNativeReflectConstruct";
import { QueryIds } from "ME";
import initialize from "initialize";
const require = arg1;
initialize = {
getQueryId(query) {
return QueryIds.GAME_AUTOCOMPLETE(require(6109) /* GAME_AUTOCOMPLETE_MAX_QUERY_LENGTH */.normalizeGameAutocompleteQuery(query));
},
get(arg0) {
const results = importDefaultResult.getResults(arg0);
let tmp2 = null;
if (null != results) {
tmp2 = results;
}
return tmp2;
},
load(arg0) {
return require(6119) /* _fetchGameAutocomplete */.fetchGameAutocomplete(arg0);
},
getIsLoading(wishlistId) {
return importDefaultResult.isFetching(wishlistId);
},
retryConfig: initialize,
staleAfter: 3600,
failureStaleAfter: 60
};
initialize = {
retryableErrors: function isRetryableError(status) {
status = status.status;
let tmp = null != status;
if (tmp) {
let tmp2 = 429 === status;
if (!tmp2) {
let tmp3 = status >= 500;
if (tmp3) {
tmp3 = 503 !== status;
}
tmp2 = tmp3;
}
tmp = tmp2;
}
return tmp;
}
};
const fetchStore = initialize.createFetchStore(importDefaultResult, initialize);
let result = require("_isNativeReflectConstruct").fileFinishedImporting("modules/games/autocomplete/useGameAutocomplete.tsx");
export const GAME_AUTOCOMPLETE_DEBOUNCE_MS = 200;
export const GAME_AUTOCOMPLETE_DEBOUNCE_MAX_WAIT_MS = 500;
export const useGameAutocomplete = fetchStore;
export const useDebouncedGameAutocomplete = function useDebouncedGameAutocomplete(query) {
let data;
let isLoading;
let obj = require(6109) /* GAME_AUTOCOMPLETE_MAX_QUERY_LENGTH */;
const result = obj.normalizeGameAutocompleteQuery(query);
const tmp2 = (function useDebouncedQueryValue(result) {
let closure_0 = result;
const tmp = outer1_2(outer1_3.useState(result), 2);
const first = tmp[0];
let closure_1 = tmp[1];
let _slicedToArray = outer1_3.useRef(first);
let result = outer1_3.useRef(0);
const items = [result];
const effect = outer1_3.useEffect(() => {
function emit() {
outer1_3.current = Date.now();
outer1_2.current = closure_0;
outer1_1(closure_0);
}
if (timeout !== ref.current) {
if (null != timeout) {
if (null != ref.current) {
const _Date = Date;
const _Math = Math;
const _Math2 = Math;
const _setTimeout = setTimeout;
timeout = setTimeout(emit, Math.min(200, Math.max(0, 500 - (Date.now() - ref2.current))));
return () => {
clearTimeout(closure_0);
};
}
}
emit();
}
}, items);
return first;
})(result);
const tmp3 = fetchStore(tmp2);
({ data, isLoading } = tmp3);
const tmp4 = callback(React.useState(null), 2);
let first = tmp4[0];
if (null == result) {
if (null != first) {
tmp6(null);
}
} else {
if (tmp7) {
tmp6(data);
}
tmp7 = null != data && data !== first;
}
obj = {};
let tmp10 = null;
if (null != result) {
if (null != data) {
first = data;
}
tmp10 = first;
}
obj.results = tmp10;
if (!isLoading) {
isLoading = tmp2 !== result;
}
obj.isLoading = isLoading;
let error = null;
if (tmp2 === result) {
error = tmp3.error;
}
obj.error = error;
return obj;
};