AutosuggestAccountInput: improve types
This commit is contained in:
parent
0ff1887fec
commit
318b9f0d3b
|
@ -3,7 +3,7 @@ import { throttle } from 'lodash';
|
||||||
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
||||||
|
|
||||||
import { accountSearch } from 'soapbox/actions/accounts';
|
import { accountSearch } from 'soapbox/actions/accounts';
|
||||||
import AutosuggestInput from 'soapbox/components/autosuggest_input';
|
import AutosuggestInput, { Suggestion } from 'soapbox/components/autosuggest_input';
|
||||||
import { useAppDispatch } from 'soapbox/hooks';
|
import { useAppDispatch } from 'soapbox/hooks';
|
||||||
|
|
||||||
import type { Menu } from 'soapbox/components/dropdown_menu';
|
import type { Menu } from 'soapbox/components/dropdown_menu';
|
||||||
|
@ -59,8 +59,10 @@ const AutosuggestAccountInput: React.FC<IAutosuggestAccountInput> = ({
|
||||||
onChange(e);
|
onChange(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelected = (_tokenStart: number, _lastToken: string | null, accountId: string) => {
|
const handleSelected = (_tokenStart: number, _lastToken: string | null, suggestion: Suggestion) => {
|
||||||
onSelected(accountId);
|
if (typeof suggestion === 'string' && suggestion[0] !== '#') {
|
||||||
|
onSelected(suggestion);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -3,7 +3,8 @@ import React from 'react';
|
||||||
import unicodeMapping from 'soapbox/features/emoji/emoji_unicode_mapping_light';
|
import unicodeMapping from 'soapbox/features/emoji/emoji_unicode_mapping_light';
|
||||||
import { joinPublicPath } from 'soapbox/utils/static';
|
import { joinPublicPath } from 'soapbox/utils/static';
|
||||||
|
|
||||||
type Emoji = {
|
export type Emoji = {
|
||||||
|
id: string,
|
||||||
custom: boolean,
|
custom: boolean,
|
||||||
imageUrl: string,
|
imageUrl: string,
|
||||||
native: string,
|
native: string,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { List as ImmutableList } from 'immutable';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
|
|
||||||
import AutosuggestEmoji from 'soapbox/components/autosuggest_emoji';
|
import AutosuggestEmoji, { Emoji } from 'soapbox/components/autosuggest_emoji';
|
||||||
import Icon from 'soapbox/components/icon';
|
import Icon from 'soapbox/components/icon';
|
||||||
import AutosuggestAccount from 'soapbox/features/compose/components/autosuggest_account';
|
import AutosuggestAccount from 'soapbox/features/compose/components/autosuggest_account';
|
||||||
import { isRtl } from 'soapbox/rtl';
|
import { isRtl } from 'soapbox/rtl';
|
||||||
|
@ -15,6 +15,8 @@ type CursorMatch = [
|
||||||
token: string | null,
|
token: string | null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export type Suggestion = string | Emoji;
|
||||||
|
|
||||||
const textAtCursorMatchesToken = (str: string, caretPosition: number, searchTokens: string[]): CursorMatch => {
|
const textAtCursorMatchesToken = (str: string, caretPosition: number, searchTokens: string[]): CursorMatch => {
|
||||||
let word: string;
|
let word: string;
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ interface IAutosuggestInput extends Pick<React.HTMLAttributes<HTMLInputElement>,
|
||||||
suggestions: ImmutableList<any>,
|
suggestions: ImmutableList<any>,
|
||||||
disabled?: boolean,
|
disabled?: boolean,
|
||||||
placeholder?: string,
|
placeholder?: string,
|
||||||
onSuggestionSelected: (tokenStart: number, lastToken: string | null, suggestion: any) => void,
|
onSuggestionSelected: (tokenStart: number, lastToken: string | null, suggestion: Suggestion) => void,
|
||||||
onSuggestionsClearRequested: () => void,
|
onSuggestionsClearRequested: () => void,
|
||||||
onSuggestionsFetchRequested: (token: string) => void,
|
onSuggestionsFetchRequested: (token: string) => void,
|
||||||
autoFocus: boolean,
|
autoFocus: boolean,
|
||||||
|
@ -193,7 +195,7 @@ export default class AutosuggestInput extends ImmutablePureComponent<IAutosugges
|
||||||
this.input = c;
|
this.input = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderSuggestion = (suggestion: any, i: number) => {
|
renderSuggestion = (suggestion: Suggestion, i: number) => {
|
||||||
const { selectedSuggestion } = this.state;
|
const { selectedSuggestion } = this.state;
|
||||||
let inner, key;
|
let inner, key;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue