diff --git a/packages/shared/src/components/popover/GifPopover.tsx b/packages/shared/src/components/popover/GifPopover.tsx index fa76bd92a5..e3743d0b1d 100644 --- a/packages/shared/src/components/popover/GifPopover.tsx +++ b/packages/shared/src/components/popover/GifPopover.tsx @@ -7,7 +7,7 @@ import { PopoverContent } from './Popover'; import { TextField } from '../fields/TextField'; import useDebounceFn from '../../hooks/useDebounceFn'; import useGif from '../../hooks/useGif'; -import { StarIcon } from '../icons'; +import { MiniCloseIcon, StarIcon } from '../icons'; import { Typography, TypographyColor, @@ -15,6 +15,8 @@ import { } from '../typography/Typography'; import { GenericLoaderSpinner } from '../utilities/loaders'; import { IconSize } from '../Icon'; +import { useViewSize, ViewSize } from '../../hooks'; +import { Drawer } from '../drawers'; const searchSuggestions = [ 'Nodding zoom', @@ -35,11 +37,121 @@ type GifPopoverProps = { textareaRef?: React.MutableRefObject; }; +type GifPickerContentProps = { + query: string; + debounceQuery: (value: string) => void; + debounceNextPage: () => void; + isLoadingGifs: boolean; + gifsToDisplay: ReturnType['data']; + favorites: ReturnType['favorites']; + favorite: ReturnType['favorite']; + scrollRef: (node?: Element | null) => void; + handleGifClick: (gif: { url: string; title: string }) => void; + showLoadingSpinner: boolean; +}; + +const GifPickerContent = ({ + query, + debounceQuery, + debounceNextPage, + isLoadingGifs, + gifsToDisplay, + favorites, + favorite, + scrollRef, + handleGifClick, + showLoadingSpinner, +}: GifPickerContentProps) => ( + <> +
+ debounceQuery(e.target.value)} + onKeyDown={(e) => { + // Prevent Enter key from submitting the parent form + if (e.key === 'Enter') { + e.preventDefault(); + } + }} + inputId="gifs" + label="Search Tenor" + placeholder={ + searchSuggestions[ + Math.floor(Math.random() * searchSuggestions.length) + ] + } + /> +
+
debounceNextPage()} + > + {!isLoadingGifs && gifsToDisplay?.length > 0 && ( + <> +
+ {gifsToDisplay.map((gif, idx) => ( +
+
+
+ +
+ ))} +
+ {showLoadingSpinner && ( +
+ +
+ )} + + )} + {!isLoadingGifs && (!gifsToDisplay || gifsToDisplay.length === 0) && ( +
+ + {!query + ? 'You have no favorites yet. Add some, and they will appear here!' + : 'no results matching your search 😞'} + +
+ )} +
+ +); + const GifPopover = ({ buttonProps, onGifCommand, textareaRef, }: GifPopoverProps) => { + const isTablet = useViewSize(ViewSize.Tablet); const { ref: scrollRef, inView } = useInView({ threshold: 0.5, }); @@ -99,6 +211,54 @@ const GifPopover = ({ setQuery(''); }; + const handleClose = () => { + setOpen(false); + setQuery(''); + }; + + const contentProps: GifPickerContentProps = { + query, + debounceQuery, + debounceNextPage, + isLoadingGifs, + gifsToDisplay, + favorites, + favorite, + scrollRef, + handleGifClick, + showLoadingSpinner: !!query, + }; + + if (!isTablet) { + return ( + <> + - - ))} - - {query && ( -
- -
- )} - - )} - {!isLoadingGifs && (!gifsToDisplay || gifsToDisplay.length === 0) && ( -
- - {!query - ? 'You have no favorites yet. Add some, and they will appear here!' - : 'no results matching your search 😞'} - -
- )} - + );