searching for available users

This commit is contained in:
noumantahir 2022-01-27 13:25:35 +05:00
parent 153d99e863
commit ae34c14870

View File

@ -47,6 +47,7 @@ import applySnippet from './formats/applySnippet';
import { MainButton } from '../../mainButton';
import isAndroidOreo from '../../../utils/isAndroidOreo';
import { extractWordAtIndex } from '../../../utils/editor';
import { searchAccount } from '../../../providers/ecency/ecency';
const MIN_BODY_INPUT_HEIGHT = 300;
@ -82,6 +83,7 @@ const MarkdownEditorView = ({
const [bodyInputHeight, setBodyInputHeight] = useState(MIN_BODY_INPUT_HEIGHT);
const [isSnippetsOpen, setIsSnippetsOpen] = useState(false);
const [showDraftLoadButton, setShowDraftLoadButton] = useState(false);
const [autoCompleteUsers, setAutoCompleteUsers] = useState([]);
const inputRef = useRef(null);
const galleryRef = useRef(null);
@ -109,6 +111,9 @@ const MarkdownEditorView = ({
if (selection.start === selection.end && text) {
const word = extractWordAtIndex(text, selection.start);
console.log('selection word is: ', word);
if(word.startsWith('@')){
_handleUserSearch(word.substring(1));
}
}
}, [text, selection]);
@ -192,6 +197,17 @@ const MarkdownEditorView = ({
dispatch(toggleAccountsBottomSheet(!isVisibleAccountsBottomSheet));
};
const _handleUserSearch = async (username) => {
let users = [];
if(username){
users = await searchAccount(username, 5);
console.log("result users", users)
}
setAutoCompleteUsers(users);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
const _changeText = useCallback((input) => {
setText(input);
@ -311,6 +327,16 @@ const MarkdownEditorView = ({
}
};
const _renderLookedUpAccounts = () => {
return <FlatList
horizontal={true}
data={autoCompleteUsers}
renderItem={(user)=>{
return <Text>{user.name + ' '}</Text>
}}
/>
}
const _renderEditorButtons = () => (
<StickyBar>
<View style={styles.leftButtonsWrapper}>
@ -459,6 +485,7 @@ const MarkdownEditorView = ({
{isAndroidOreo() ? _renderEditorWithoutScroll() : _renderEditorWithScroll()}
{_renderFloatingDraftButton()}
{_renderLookedUpAccounts()}
{!isPreviewActive && _renderEditorButtons()}
<Modal