This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
99c0709
commit 2a04b46
Showing
19 changed files
with
3,063 additions
and
1,359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React, {memo, useCallback} from 'react'; | ||
import {useSelector} from 'react-redux'; | ||
import {EmojiVariationsListProps, Grid} from '@giphy/react-components'; | ||
import {GifsResult} from '@giphy/js-fetch-api'; | ||
|
||
import {getGiphyFetchInstance} from 'mattermost-redux/selectors/entities/general'; | ||
|
||
import NoResultsIndicator from 'components/no_results_indicator'; | ||
import {NoResultsVariant} from 'components/no_results_indicator/types'; | ||
|
||
const GUTTER_BETWEEN_GIFS = 8; | ||
const NUM_OF_GIFS_COLUMNS = 2; | ||
|
||
interface Props { | ||
width: number; | ||
filter: string; | ||
onClick: EmojiVariationsListProps['onGifClick']; | ||
} | ||
|
||
function GifPickerItems(props: Props) { | ||
const giphyFetch = useSelector(getGiphyFetchInstance); | ||
|
||
const fetchGifs = useCallback(async (offset: number) => { | ||
if (!giphyFetch) { | ||
return {} as GifsResult; | ||
} | ||
|
||
// We dont have to throttled the fetching as the library does it for us | ||
if (props.filter.length > 0) { | ||
const filteredResult = await giphyFetch.search(props.filter, {offset, limit: 10}); | ||
return filteredResult; | ||
} | ||
|
||
const trendingResult = await giphyFetch.trending({offset, limit: 10}); | ||
return trendingResult; | ||
}, [props.filter, giphyFetch]); | ||
|
||
return ( | ||
<div className='emoji-picker__items gif-picker__items'> | ||
<Grid | ||
key={props.filter.length === 0 ? 'trending' : props.filter} | ||
columns={NUM_OF_GIFS_COLUMNS} | ||
gutter={GUTTER_BETWEEN_GIFS} | ||
hideAttribution={true} | ||
width={props.width} | ||
noResultsMessage={ | ||
<NoResultsIndicator | ||
variant={NoResultsVariant.ChannelSearch} | ||
titleValues={{channelName: `"${props.filter}"`}} | ||
/> | ||
} | ||
fetchGifs={fetchGifs} | ||
onGifClick={props.onClick} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(GifPickerItems); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React, {ChangeEvent, memo, useCallback, useMemo} from 'react'; | ||
import {useIntl} from 'react-intl'; | ||
import {useSelector} from 'react-redux'; | ||
import tinycolor from 'tinycolor2'; | ||
|
||
import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; | ||
|
||
import giphyWhiteImage from 'images/gif_picker/powered-by-giphy-white.png'; | ||
import giphyBlackImage from 'images/gif_picker/powered-by-giphy-black.png'; | ||
|
||
interface Props { | ||
value: string; | ||
onChange: (value: string) => void; | ||
} | ||
|
||
function GifPickerSearch(props: Props) { | ||
const theme = useSelector(getTheme); | ||
|
||
const {formatMessage} = useIntl(); | ||
|
||
const handleChange = useCallback((event: ChangeEvent<HTMLInputElement>) => { | ||
event.preventDefault(); | ||
|
||
// remove trailing and leading colons | ||
const value = event.target?.value?.replace(/^:|:$/g, '') ?? ''; | ||
props.onChange(value); | ||
}, [props.onChange]); | ||
|
||
const shouldUseWhiteLogo = useMemo(() => { | ||
const WHITE_COLOR = '#FFFFFF'; | ||
const BLACK_COLOR = '#000000'; | ||
|
||
const mostReadableColor = tinycolor.mostReadable(theme.centerChannelBg, [WHITE_COLOR, BLACK_COLOR], {includeFallbackColors: false}); | ||
|
||
if (mostReadableColor.isLight()) { | ||
return true; | ||
} | ||
return false; | ||
}, [theme.centerChannelBg]); | ||
|
||
return ( | ||
<div className='emoji-picker__search-container'> | ||
<div className='emoji-picker__text-container'> | ||
<span className='icon-magnify icon emoji-picker__search-icon'/> | ||
<input | ||
id='emojiPickerSearch' | ||
className='emoji-picker__search' | ||
aria-label={formatMessage({id: 'gif_picker.input.label', defaultMessage: 'Search for GIFs'})} | ||
placeholder={formatMessage({id: 'gif_picker.input.placeholder', defaultMessage: 'Search GIPHY'})} | ||
type='text' | ||
autoFocus={true} | ||
autoComplete='off' | ||
onChange={handleChange} | ||
value={props.value} | ||
/> | ||
</div> | ||
<div className='gif-attribution'> | ||
<img | ||
src={shouldUseWhiteLogo ? giphyWhiteImage : giphyBlackImage} | ||
alt={formatMessage({id: 'gif_picker.attribution.alt', defaultMessage: 'Powered by GIPHY'})} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(GifPickerSearch); |
Oops, something went wrong.