2026-05-15 13:37:03 -04:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
|
import FocusTrap from 'focus-trap-react';
|
|
|
|
|
import { Grid, SearchBar, SearchContext, SearchContextManager } from '@giphy/react-components';
|
|
|
|
|
import { IGif } from '@giphy/js-types';
|
|
|
|
|
import { Box } from 'folds';
|
|
|
|
|
import { useSetting } from '../state/hooks/settings';
|
|
|
|
|
import { settingsAtom } from '../state/settings';
|
|
|
|
|
|
|
|
|
|
const PICKER_WIDTH = 312;
|
|
|
|
|
|
|
|
|
|
type GifPickerInnerProps = {
|
|
|
|
|
onSelect: (url: string, width: number, height: number) => void;
|
|
|
|
|
requestClose: () => void;
|
|
|
|
|
lotusTerminal: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function GifPickerInner({ onSelect, requestClose, lotusTerminal }: GifPickerInnerProps) {
|
|
|
|
|
const { fetchGifs, searchKey } = React.useContext(SearchContext);
|
|
|
|
|
|
|
|
|
|
const handleClick = useCallback(
|
|
|
|
|
(gif: IGif, e: React.SyntheticEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const r = gif.images.downsized ?? gif.images.original;
|
2026-05-22 12:08:50 -04:00
|
|
|
const { url } = r;
|
2026-05-15 13:37:03 -04:00
|
|
|
const width = Number(r.width) || 200;
|
|
|
|
|
const height = Number(r.height) || 200;
|
|
|
|
|
onSelect(url, width, height);
|
|
|
|
|
requestClose();
|
|
|
|
|
},
|
2026-05-21 23:30:50 -04:00
|
|
|
[onSelect, requestClose],
|
2026-05-15 13:37:03 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box direction="Column" style={{ width: `${PICKER_WIDTH}px` }}>
|
|
|
|
|
{lotusTerminal && (
|
2026-05-21 20:49:33 -04:00
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
padding: '5px 10px 4px',
|
2026-06-10 00:01:12 -04:00
|
|
|
borderBottom: '1px solid color-mix(in srgb, var(--lt-accent-orange) 20%, transparent)',
|
2026-05-21 20:49:33 -04:00
|
|
|
fontFamily: "'JetBrains Mono', 'Cascadia Code', monospace",
|
|
|
|
|
fontSize: '10px',
|
|
|
|
|
fontWeight: 700,
|
|
|
|
|
letterSpacing: '0.1em',
|
2026-06-10 00:01:12 -04:00
|
|
|
color: 'var(--lt-accent-orange)',
|
2026-05-21 20:49:33 -04:00
|
|
|
userSelect: 'none',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-05-23 22:51:56 -04:00
|
|
|
{'// GIF_SEARCH'}
|
2026-05-15 13:37:03 -04:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<Box style={{ padding: '8px 8px 4px' }}>
|
2026-05-22 11:16:11 -04:00
|
|
|
<div style={{ width: '100%', borderRadius: lotusTerminal ? '4px' : '8px' }}>
|
|
|
|
|
<SearchBar />
|
|
|
|
|
</div>
|
2026-05-15 13:37:03 -04:00
|
|
|
</Box>
|
2026-05-21 20:49:33 -04:00
|
|
|
<div
|
|
|
|
|
style={{ overflowY: 'auto', overflowX: 'hidden', maxHeight: '340px', padding: '0 8px 8px' }}
|
|
|
|
|
>
|
2026-05-15 13:37:03 -04:00
|
|
|
<Grid
|
|
|
|
|
key={searchKey}
|
|
|
|
|
fetchGifs={fetchGifs}
|
|
|
|
|
width={PICKER_WIDTH - 16}
|
|
|
|
|
columns={2}
|
|
|
|
|
gutter={4}
|
|
|
|
|
onGifClick={handleClick}
|
|
|
|
|
hideAttribution={false}
|
|
|
|
|
noLink
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GifPickerProps = {
|
|
|
|
|
apiKey: string;
|
|
|
|
|
onSelect: (url: string, width: number, height: number) => void;
|
|
|
|
|
requestClose: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function GifPicker({ apiKey, onSelect, requestClose }: GifPickerProps) {
|
|
|
|
|
const [lotusTerminal] = useSetting(settingsAtom, 'lotusTerminal');
|
|
|
|
|
|
|
|
|
|
const containerStyle = lotusTerminal
|
|
|
|
|
? {
|
2026-06-10 00:01:12 -04:00
|
|
|
background: 'var(--lt-bg-secondary)',
|
|
|
|
|
border: '1px solid color-mix(in srgb, var(--lt-accent-orange) 35%, transparent)',
|
2026-05-15 13:37:03 -04:00
|
|
|
borderRadius: '4px',
|
|
|
|
|
overflow: 'hidden',
|
2026-06-10 22:55:32 -04:00
|
|
|
boxShadow:
|
|
|
|
|
'0 4px 24px color-mix(in srgb, var(--lt-accent-orange) 10%, transparent), 0 0 0 1px color-mix(in srgb, var(--lt-accent-orange) 8%, transparent)',
|
2026-05-15 13:37:03 -04:00
|
|
|
width: `${PICKER_WIDTH}px`,
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
background: 'var(--bg-surface)',
|
|
|
|
|
border: '1px solid rgba(255,255,255,0.08)',
|
|
|
|
|
borderRadius: '12px',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
boxShadow: '0 8px 32px rgba(0,0,0,0.4)',
|
|
|
|
|
width: `${PICKER_WIDTH}px`,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FocusTrap
|
|
|
|
|
focusTrapOptions={{
|
|
|
|
|
initialFocus: false,
|
|
|
|
|
onDeactivate: requestClose,
|
|
|
|
|
clickOutsideDeactivates: true,
|
|
|
|
|
allowOutsideClick: true,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
direction="Column"
|
|
|
|
|
data-gif-terminal={lotusTerminal ? '' : undefined}
|
|
|
|
|
style={containerStyle}
|
|
|
|
|
>
|
|
|
|
|
<SearchContextManager apiKey={apiKey} initialTerm="">
|
2026-05-21 20:49:33 -04:00
|
|
|
<GifPickerInner
|
|
|
|
|
onSelect={onSelect}
|
|
|
|
|
requestClose={requestClose}
|
|
|
|
|
lotusTerminal={!!lotusTerminal}
|
|
|
|
|
/>
|
2026-05-15 13:37:03 -04:00
|
|
|
</SearchContextManager>
|
|
|
|
|
</Box>
|
|
|
|
|
</FocusTrap>
|
|
|
|
|
);
|
|
|
|
|
}
|