// Metro module 6170 (f6171). import { useState, useRef, useEffect } from "react"; import GameAutocompleteStore from "./GameAutocompleteStore"; import { QueryIds } from "../../../Constants"; import { createFetchStore } from "../../../_bundle/Module589"; import { normalizeGameAutocompleteQuery } from "./GameAutocompleteUtils"; import { fetchGameAutocomplete } from "./GameAutocompleteActionCreators"; const fetchStore = createFetchStore(GameAutocompleteStore, { getQueryId: (a0) => QueryIds.GAME_AUTOCOMPLETE(normalizeGameAutocompleteQuery(a0)), get: (a0) => { let r5 = GameAutocompleteStore.getResults(a0); if (r5 == null) { r5 = null; } return r5; }, load: (a0) => fetchGameAutocomplete(a0), getIsLoading: (a0) => GameAutocompleteStore.isFetching(a0), retryConfig: { retryableErrors: function isRetryableError({ status }) { return status != null && (status === 429 || status >= 500 && status !== 503); } }, staleAfter: 3600, failureStaleAfter: 60 }); export const GAME_AUTOCOMPLETE_DEBOUNCE_MS = 200; export const GAME_AUTOCOMPLETE_DEBOUNCE_MAX_WAIT_MS = 500; export { fetchStore as useGameAutocomplete }; export function useDebouncedGameAutocomplete(a0) { const current = normalizeGameAutocompleteQuery(a0); const [state, setState] = useState(current); const ref = useRef(state); const ref2 = useRef(0); useEffect(() => { if (current !== ref.current) { if (current != null && ref.current != null) { let c29681_0 = setTimeout(function emit() { ref2.current = Date.now(); ref.current = current; setState(current); }, Math.min(200, Math.max(0, 500 - (Date.now() - ref2.current)))); return () => { clearTimeout(c29681_0); }; } ref2.current = Date.now(); ref.current = current; setState(current); } }, [current]); const r31 = fetchStore(state); let data = r31.data; const error = r31.error; let isLoading = r31.isLoading; const [state2, setState2] = useState(null); if (current == null) { if (state2 != null) { setState2(null); } } else if (data != null && data !== state2) { setState2(data); } const r42 = current != null; let results = null; if (r42) { if (data == null) { data = state2; } results = data; } if (!isLoading) { isLoading = state !== current; } return { results, isLoading, error: state === current ? error : null }; }