From 05955cb99d22c644526a719d84556a9850f48b2a Mon Sep 17 00:00:00 2001 From: vineyardbovines Date: Tue, 14 Apr 2026 16:23:14 -0400 Subject: [PATCH] Wire GifCategoryPills into GifPickerDialog Adds activeCategory state and effectiveSearch logic to GifPickerBody so selecting a category pill filters GIFs via the category's searchterm. Pills hide when the user types a search query, and going back resets to trending. Co-Authored-By: Claude Sonnet 4.6 --- src/features/gifPicker/GifPickerDialog.tsx | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/features/gifPicker/GifPickerDialog.tsx b/src/features/gifPicker/GifPickerDialog.tsx index b7876608a6..f8bfdfb241 100644 --- a/src/features/gifPicker/GifPickerDialog.tsx +++ b/src/features/gifPicker/GifPickerDialog.tsx @@ -6,6 +6,11 @@ import {type ListMethods} from '#/view/com/util/List' import {ios, useBreakpoints} from '#/alf' import * as Dialog from '#/components/Dialog' import {useThrottledValue} from '#/components/hooks/useThrottledValue' +import { + GIF_CATEGORIES, + type GifCategory, + GifCategoryPills, +} from '#/features/gifPicker/components/GifCategoryPills' import {GifPickerErrorBoundary} from '#/features/gifPicker/components/GifPickerErrorBoundary' import {GifPickerGrid} from '#/features/gifPicker/components/GifPickerGrid' import {GifPickerHeader} from '#/features/gifPicker/components/GifPickerHeader' @@ -64,8 +69,17 @@ function GifPickerBody({ const textInputRef = useRef(null) const listRef = useRef(null) const [rawSearch, setRawSearch] = useState('') + const [activeCategory, setActiveCategory] = useState('trending') const search = useThrottledValue(rawSearch, 750) + // Determine the effective search query: + // - If user is typing, use the typed text + // - If a non-trending category is active, use its searchterm + // - Otherwise (trending), empty string triggers the featured endpoint + const activeCategorySearchterm = + GIF_CATEGORIES.find(c => c.id === activeCategory)?.searchterm ?? '' + const effectiveSearch = search.length > 0 ? search : activeCategorySearchterm + const { data, fetchNextPage, @@ -76,7 +90,7 @@ function GifPickerBody({ isError, isSearching, refetch, - } = useGifPickerData(search) + } = useGifPickerData(effectiveSearch) const items = data?.pages.flatMap(page => page.results) ?? [] const hasData = items.length > 0 @@ -90,6 +104,7 @@ function GifPickerBody({ if (isSearching) { textInputRef.current?.clear() setRawSearch('') + setActiveCategory('trending') } else { control.close() } @@ -100,6 +115,13 @@ function GifPickerBody({ listRef.current?.scrollToOffset({offset: 0, animated: false}) } + const onSelectCategory = (category: GifCategory) => { + setActiveCategory(category.id) + listRef.current?.scrollToOffset({offset: 0, animated: false}) + } + + const showPills = rawSearch.length === 0 + const header = ( <> control.close()} onEscape={() => control.close()} /> + {showPills && ( + + )} {!hasData && (