[Glitch] Autosuggest emojis rendering fix
Port d5a7b383faf9085e88e3c54639aefb026f2b3694 to glitch-soc Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
3f884ada27
commit
1aa53eb328
@ -1,7 +1,5 @@
|
|||||||
import type { FC } from 'react';
|
import type { FC } from 'react';
|
||||||
|
|
||||||
import { useCustomEmojis } from '@/flavours/glitch/hooks/useCustomEmojis';
|
|
||||||
|
|
||||||
import { Emoji } from './emoji';
|
import { Emoji } from './emoji';
|
||||||
|
|
||||||
interface LegacyEmoji {
|
interface LegacyEmoji {
|
||||||
@ -12,11 +10,10 @@ interface LegacyEmoji {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const AutosuggestEmoji: FC<{ emoji: LegacyEmoji }> = ({ emoji }) => {
|
export const AutosuggestEmoji: FC<{ emoji: LegacyEmoji }> = ({ emoji }) => {
|
||||||
const emojis = useCustomEmojis();
|
|
||||||
const colons = `:${emoji.id}:`;
|
const colons = `:${emoji.id}:`;
|
||||||
return (
|
return (
|
||||||
<div className='autosuggest-emoji'>
|
<div className='autosuggest-emoji'>
|
||||||
<Emoji code={emoji.native ?? colons} customEmoji={emojis} />
|
<Emoji code={emoji.native ?? colons} />
|
||||||
<div className='autosuggest-emoji__name'>{colons}</div>
|
<div className='autosuggest-emoji__name'>{colons}</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosugg
|
|||||||
|
|
||||||
import { AutosuggestEmoji } from './autosuggest_emoji';
|
import { AutosuggestEmoji } from './autosuggest_emoji';
|
||||||
import { AutosuggestHashtag } from './autosuggest_hashtag';
|
import { AutosuggestHashtag } from './autosuggest_hashtag';
|
||||||
|
import { LocalCustomEmojiProvider } from './emoji/context';
|
||||||
|
|
||||||
const textAtCursorMatchesToken = (str, caretPosition, searchTokens) => {
|
const textAtCursorMatchesToken = (str, caretPosition, searchTokens) => {
|
||||||
let word;
|
let word;
|
||||||
@ -219,15 +220,17 @@ export default class AutosuggestInput extends ImmutablePureComponent {
|
|||||||
spellCheck={spellCheck}
|
spellCheck={spellCheck}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Overlay show={!(suggestionsHidden || suggestions.isEmpty())} offset={[0, 0]} placement='bottom' target={this.input} popperConfig={{ strategy: 'fixed' }}>
|
<LocalCustomEmojiProvider>
|
||||||
{({ props }) => (
|
<Overlay show={!(suggestionsHidden || suggestions.isEmpty())} offset={[0, 0]} placement='bottom' target={this.input} popperConfig={{ strategy: 'fixed' }}>
|
||||||
<div {...props}>
|
{({ props }) => (
|
||||||
<div className='autosuggest-textarea__suggestions' style={{ width: this.input?.clientWidth }}>
|
<div {...props}>
|
||||||
{suggestions.map(this.renderSuggestion)}
|
<div className='autosuggest-textarea__suggestions' style={{ width: this.input?.clientWidth }}>
|
||||||
|
{suggestions.map(this.renderSuggestion)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</Overlay>
|
||||||
</Overlay>
|
</LocalCustomEmojiProvider>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosugg
|
|||||||
|
|
||||||
import { AutosuggestEmoji } from './autosuggest_emoji';
|
import { AutosuggestEmoji } from './autosuggest_emoji';
|
||||||
import { AutosuggestHashtag } from './autosuggest_hashtag';
|
import { AutosuggestHashtag } from './autosuggest_hashtag';
|
||||||
|
import { LocalCustomEmojiProvider } from './emoji/context';
|
||||||
|
|
||||||
const textAtCursorMatchesToken = (str, caretPosition) => {
|
const textAtCursorMatchesToken = (str, caretPosition) => {
|
||||||
let word;
|
let word;
|
||||||
@ -218,15 +219,17 @@ const AutosuggestTextarea = forwardRef(({
|
|||||||
lang={lang}
|
lang={lang}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Overlay show={!(suggestionsHidden || suggestions.isEmpty())} offset={[0, 0]} placement='bottom' target={textareaRef} popperConfig={{ strategy: 'fixed' }}>
|
<LocalCustomEmojiProvider>
|
||||||
{({ props }) => (
|
<Overlay show={!(suggestionsHidden || suggestions.isEmpty())} offset={[0, 0]} placement='bottom' target={textareaRef} popperConfig={{ strategy: 'fixed' }}>
|
||||||
<div {...props}>
|
{({ props }) => (
|
||||||
<div className='autosuggest-textarea__suggestions' style={{ width: textareaRef.current?.clientWidth }}>
|
<div {...props}>
|
||||||
{suggestions.map(renderSuggestion)}
|
<div className='autosuggest-textarea__suggestions' style={{ width: textareaRef.current?.clientWidth }}>
|
||||||
|
{suggestions.map(renderSuggestion)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
)}
|
||||||
)}
|
</Overlay>
|
||||||
</Overlay>
|
</LocalCustomEmojiProvider>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,9 @@
|
|||||||
import type { MouseEventHandler, PropsWithChildren } from 'react';
|
import type {
|
||||||
|
FC,
|
||||||
|
MouseEventHandler,
|
||||||
|
PropsWithChildren,
|
||||||
|
ReactNode,
|
||||||
|
} from 'react';
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
useCallback,
|
useCallback,
|
||||||
@ -8,6 +13,7 @@ import {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
|
|
||||||
import { cleanExtraEmojis } from '@/flavours/glitch/features/emoji/normalize';
|
import { cleanExtraEmojis } from '@/flavours/glitch/features/emoji/normalize';
|
||||||
|
import { useCustomEmojis } from '@/flavours/glitch/hooks/useCustomEmojis';
|
||||||
import { autoPlayGif } from '@/flavours/glitch/initial_state';
|
import { autoPlayGif } from '@/flavours/glitch/initial_state';
|
||||||
import { polymorphicForwardRef } from '@/types/polymorphic';
|
import { polymorphicForwardRef } from '@/types/polymorphic';
|
||||||
import type {
|
import type {
|
||||||
@ -103,3 +109,10 @@ export const CustomEmojiProvider = ({
|
|||||||
</CustomEmojiContext.Provider>
|
</CustomEmojiContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LocalCustomEmojiProvider: FC<{ children: ReactNode }> = ({
|
||||||
|
children,
|
||||||
|
}) => {
|
||||||
|
const emojis = useCustomEmojis();
|
||||||
|
return <CustomEmojiProvider emojis={emojis}>{children}</CustomEmojiProvider>;
|
||||||
|
};
|
||||||
|
|||||||
@ -19,7 +19,6 @@ import {
|
|||||||
stringToEmojiState,
|
stringToEmojiState,
|
||||||
tokenizeText,
|
tokenizeText,
|
||||||
} from '@/flavours/glitch/features/emoji/render';
|
} from '@/flavours/glitch/features/emoji/render';
|
||||||
import type { ExtraCustomEmojiMap } from '@/flavours/glitch/features/emoji/types';
|
|
||||||
|
|
||||||
import { AnimateEmojiContext, CustomEmojiContext } from './context';
|
import { AnimateEmojiContext, CustomEmojiContext } from './context';
|
||||||
|
|
||||||
@ -27,19 +26,14 @@ interface EmojiProps {
|
|||||||
code: string;
|
code: string;
|
||||||
showFallback?: boolean;
|
showFallback?: boolean;
|
||||||
showLoading?: boolean;
|
showLoading?: boolean;
|
||||||
customEmoji?: ExtraCustomEmojiMap | null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Emoji: FC<EmojiProps> = ({
|
export const Emoji: FC<EmojiProps> = ({
|
||||||
code,
|
code,
|
||||||
showFallback = true,
|
showFallback = true,
|
||||||
showLoading = true,
|
showLoading = true,
|
||||||
customEmoji: customEmojiOverride,
|
|
||||||
}) => {
|
}) => {
|
||||||
let customEmoji = useContext(CustomEmojiContext);
|
const customEmoji = useContext(CustomEmojiContext);
|
||||||
if (customEmojiOverride) {
|
|
||||||
customEmoji = customEmojiOverride;
|
|
||||||
}
|
|
||||||
|
|
||||||
// First, set the emoji state based on the input code.
|
// First, set the emoji state based on the input code.
|
||||||
const [state, setState] = useState(() =>
|
const [state, setState] = useState(() =>
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import type { ExtraCustomEmojiMap } from '../features/emoji/types';
|
import type { ExtraCustomEmojiMap } from '../features/emoji/types';
|
||||||
|
import { emojiLogger } from '../features/emoji/utils';
|
||||||
|
|
||||||
let emojis: ExtraCustomEmojiMap | null = null;
|
let emojis: ExtraCustomEmojiMap | null = null;
|
||||||
|
|
||||||
|
const log = emojiLogger('useCustomEmojis');
|
||||||
|
|
||||||
export function useCustomEmojis() {
|
export function useCustomEmojis() {
|
||||||
const [, setLoaded] = useState(emojis !== null);
|
const [, setLoaded] = useState(emojis !== null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -21,6 +24,7 @@ async function loadEmojisIntoCache() {
|
|||||||
const { loadAllCustomEmoji } = await import('../features/emoji/database');
|
const { loadAllCustomEmoji } = await import('../features/emoji/database');
|
||||||
const emojisRaw = await loadAllCustomEmoji();
|
const emojisRaw = await loadAllCustomEmoji();
|
||||||
if (emojisRaw === null) {
|
if (emojisRaw === null) {
|
||||||
|
log('Custom emojis not loaded yet');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,4 +36,5 @@ async function loadEmojisIntoCache() {
|
|||||||
static_url: emoji.static_url,
|
static_url: emoji.static_url,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
log('Loaded %d custom emojis into cache', Object.keys(emojis).length);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user