From 83faefecdc1aa5d98e1585a186d196b5523e2d62 Mon Sep 17 00:00:00 2001 From: zeppi Date: Wed, 16 Jun 2021 14:38:30 -0400 Subject: [PATCH] bump lighthouse throttle --- ui/component/wunderbarSuggestions/view.jsx | 3 ++- ui/effects/use-lighthouse.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/component/wunderbarSuggestions/view.jsx b/ui/component/wunderbarSuggestions/view.jsx index 145d6ebe2..7121528e6 100644 --- a/ui/component/wunderbarSuggestions/view.jsx +++ b/ui/component/wunderbarSuggestions/view.jsx @@ -46,6 +46,7 @@ export default function WunderBarSuggestions(props: Props) { const inputRef: ElementRef = React.useRef(); const isFocused = inputRef && inputRef.current && inputRef.current === document.activeElement; + const THROTTLE_MS = 1000; const { push, location: { search }, @@ -53,7 +54,7 @@ export default function WunderBarSuggestions(props: Props) { const urlParams = new URLSearchParams(search); const queryFromUrl = urlParams.get('q') || ''; const [term, setTerm] = React.useState(queryFromUrl); - const throttledTerm = useThrottle(term, 500) || ''; + const throttledTerm = useThrottle(term, THROTTLE_MS) || ''; const searchSize = isMobile ? 20 : 5; const { results, loading } = useLighthouse(throttledTerm, showMature, searchSize); const noResults = throttledTerm && !loading && results && results.length === 0; diff --git a/ui/effects/use-lighthouse.js b/ui/effects/use-lighthouse.js index 2d3c2f731..5948b73c4 100644 --- a/ui/effects/use-lighthouse.js +++ b/ui/effects/use-lighthouse.js @@ -5,11 +5,12 @@ import { getSearchQueryString } from 'util/query-params'; import { isURIValid } from 'lbry-redux'; import useThrottle from './use-throttle'; -export default function useLighthouse(query: string, showMature?: boolean, size?: number = 5) { +export default function useLighthouse(query: string, showMature?: boolean, size?: number = 6) { + const THROTTLE_MS = 1000; const [results, setResults] = React.useState(); const [loading, setLoading] = React.useState(); const queryString = query ? getSearchQueryString(query, { nsfw: showMature, size }) : ''; - const throttledQuery = useThrottle(queryString, 500); + const throttledQuery = useThrottle(queryString, THROTTLE_MS); React.useEffect(() => { if (throttledQuery) { @@ -19,9 +20,11 @@ export default function useLighthouse(query: string, showMature?: boolean, size? let isSubscribed = true; lighthouse .search(throttledQuery) - .then(results => { + .then((results) => { if (isSubscribed) { - setResults(results.map(result => `lbry://${result.name}#${result.claimId}`).filter(uri => isURIValid(uri))); + setResults( + results.map((result) => `lbry://${result.name}#${result.claimId}`).filter((uri) => isURIValid(uri)) + ); setLoading(false); } })