- replace pin-to-top with persistent launched-once state (filled play/cast icons) - move download/vlc actions into a more-options dropdown when cast is available - scope Toloka search query by show year (no IMDB filter on the tracker) - strip session sid from Toloka download hrefs so cached magnets stay valid - restore row hover, subtle row borders, taller rows; drop table rounding - stacked modal backdrops: :has(~ [data-overlay]) instead of :not(:last-of-type) - only count search in analytics after the query has settled (1s debounce)
34 lines
1017 B
TypeScript
34 lines
1017 B
TypeScript
import { useRef } from 'react';
|
|
|
|
import searchQuery, { SearchQueryProps } from '@/data/queries/search';
|
|
import useInfiniteList from '@/hooks/useInfiniteList';
|
|
import analytics from '@/lib/analytics';
|
|
import useTrackOnce from '@/lib/analytics/useTrackOnce';
|
|
|
|
const useSearch = (props: SearchQueryProps & { settled: boolean }) => {
|
|
const previousRef = useRef<Show[]>([]);
|
|
|
|
const infiniteQuery = useInfiniteList({ ...searchQuery(props), mode: 'default', list: 'search' });
|
|
|
|
useTrackOnce(
|
|
analytics.searchPerformed,
|
|
props.query && props.settled && infiniteQuery.isFetched ? `${props.type}:${props.query}` : undefined,
|
|
() => ({ query: props.query, showType: props.type, results: infiniteQuery.shows.length })
|
|
);
|
|
|
|
if (infiniteQuery.isFetched) {
|
|
previousRef.current = infiniteQuery.shows;
|
|
}
|
|
|
|
if (!props.query) {
|
|
previousRef.current = [];
|
|
}
|
|
|
|
return {
|
|
...infiniteQuery,
|
|
shows: infiniteQuery.isLoading ? previousRef.current : infiniteQuery.shows
|
|
};
|
|
};
|
|
|
|
export default useSearch;
|