decord/alpha/source/modules/games/autocomplete/useGameAutocomplete.tsx

135 lines
3.9 KiB
TypeScript
Raw Normal View History

// Module ID: 8558
// Function ID: 8559
// Name: useGameAutocomplete
// Dependencies: [32, 19, 5604, 1074, 504, 5605, 5606, 8559, 2]
2026-07-20 16:05:17 +00:00
// Exports: useDebouncedGameAutocomplete
// Module 8558 (useGameAutocomplete)
import GameAutocompleteTypes from "GameAutocompleteTypes" /* 5605 */;
import GameAutocompleteUtils from "GameAutocompleteUtils" /* 5606 */;
import GameAutocompleteActionCreators from "GameAutocompleteActionCreators" /* 8559 */;
import _slicedToArray from "module_32" /* 32 */;
import noop from "module_19" /* 19 */;
import GameAutocompleteStore from "GameAutocompleteStore" /* 5604 */;
2026-07-23 10:11:24 +00:00
require = fn;
const QueryIds = fn(1074).QueryIds;
const initialize = fn(504);
const fetchStore = initialize.createFetchStore(GameAutocompleteStore, {
getQueryId(query, DEFAULT) {
if (DEFAULT === undefined) {
DEFAULT = GameAutocompleteTypes.GameAutocompleteProfile.DEFAULT;
}
return QueryIds.GAME_AUTOCOMPLETE(GameAutocompleteUtils.normalizeGameAutocompleteQuery(query), DEFAULT);
2026-07-20 16:05:17 +00:00
},
get(arg0, arg1) {
let results = GameAutocompleteStore.getResults(arg0, arg1);
2026-07-29 08:29:29 +00:00
if (results == null) {
results = null;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
return results;
2026-07-20 16:05:17 +00:00
},
load(arg0, arg1) {
return GameAutocompleteActionCreators.fetchGameAutocomplete(arg0, arg1);
2026-07-20 16:05:17 +00:00
},
getIsLoading(arg0, arg1) {
return GameAutocompleteStore.isFetching(arg0, arg1);
2026-07-20 16:05:17 +00:00
},
retryConfig: {
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;
2026-07-20 16:05:17 +00:00
}
tmp = tmp2;
2026-07-20 16:05:17 +00:00
}
return tmp;
2026-07-20 16:05:17 +00:00
}
},
staleAfter: 3600,
failureStaleAfter: 60
});
const size = fn(2);
let result = size.fileFinishedImporting("modules/games/autocomplete/useGameAutocomplete.tsx");
2026-07-20 16:05:17 +00:00
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 DEFAULT = arg1;
if (arg1 === undefined) {
DEFAULT = GameAutocompleteTypes.GameAutocompleteProfile.DEFAULT;
}
const result = GameAutocompleteUtils.normalizeGameAutocompleteQuery(query);
2026-07-29 08:29:29 +00:00
require = result;
c1 = undefined;
[tmp5, c1] = noop.useState(result);
noop.useRef(tmp5);
noop.useRef(0);
2026-07-29 08:29:29 +00:00
const items = [result];
const effect = noop.useEffect(() => {
if (current !== ref.current) {
2026-07-29 08:29:29 +00:00
if (null != tmp) {
if (null != tmp2.current) {
const _Date2 = Date;
function emit() {
ref2.current = Date.now();
ref.current = current;
_undefined(current);
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const _Math = Math;
const _Math2 = Math;
const _setTimeout = setTimeout;
current = setTimeout(emit, Math.min(200, Math.max(0, 500 - (Date.now() - ref2.current))));
2026-07-29 08:29:29 +00:00
return () => {
clearTimeout(closure_0);
};
2026-07-20 16:05:17 +00:00
}
}
2026-07-29 08:29:29 +00:00
const _Date = Date;
ref2.current = Date.now();
tmp2.current = tmp;
_undefined(tmp);
}
}, items);
const tmp7 = fetchStore(tmp5, DEFAULT);
({ data, isLoading } = tmp7);
const tmp4 = _slicedToArray(noop.useState(result), 2);
[tmp9, tmp10] = noop.useState(null);
2026-07-20 16:05:17 +00:00
if (null == result) {
if (null != tmp9) {
tmp10(null);
2026-07-20 16:05:17 +00:00
}
} else {
if (tmp11) {
tmp10(data);
2026-07-20 16:05:17 +00:00
}
tmp11 = null != data && data !== tmp9;
2026-07-20 16:05:17 +00:00
}
let tmp14 = null;
2026-07-20 16:05:17 +00:00
if (null != result) {
2026-07-29 08:29:29 +00:00
if (data == null) {
data = tmp9;
2026-07-20 16:05:17 +00:00
}
tmp14 = data;
2026-07-20 16:05:17 +00:00
}
const obj2 = { results: tmp14, isLoading: null, error: null };
2026-07-20 16:05:17 +00:00
if (!isLoading) {
isLoading = tmp5 !== result;
2026-07-20 16:05:17 +00:00
}
obj2.isLoading = isLoading;
let error = null;
if (tmp5 === result) {
error = tmp7.error;
2026-07-20 16:05:17 +00:00
}
obj2.error = error;
return obj2;
2026-07-20 16:05:17 +00:00
};