From bfdbf43119f40a80c655eee357810b28ac4e88f7 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 25 Sep 2023 16:15:27 -0500 Subject: [PATCH] link out tags --- src/view/com/composer/TagInput.tsx | 19 +++++++++++++++---- src/view/com/post-thread/PostThreadItem.tsx | 16 +++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/view/com/composer/TagInput.tsx b/src/view/com/composer/TagInput.tsx index 9d4a80d3f2..50f38465c7 100644 --- a/src/view/com/composer/TagInput.tsx +++ b/src/view/com/composer/TagInput.tsx @@ -6,6 +6,7 @@ import { NativeSyntheticEvent, TextInputKeyPressEventData, Pressable, + InteractionManager, } from 'react-native' import { FontAwesomeIcon, @@ -60,19 +61,19 @@ export function TagInput({ const onKeyPress = React.useCallback( (e: NativeSyntheticEvent) => { - if (e.nativeEvent.key === 'Enter') { + if (e.nativeEvent.key === 'Enter' || e.nativeEvent.key === ' ') { const _tags = value.trim().split(' ').filter(Boolean) if (_tags.length > 0) { handleChangeTags( Array.from(new Set([...tags, ..._tags])).slice(0, max), ) - setValue('') } - setTimeout(() => { + InteractionManager.runAfterInteractions(() => { + setValue('') input.current?.focus() - }, 100) + }) } else if (e.nativeEvent.key === 'Backspace' && value === '') { handleChangeTags(tags.slice(0, -1)) } @@ -85,6 +86,15 @@ export function TagInput({ setValue(sanitized) }, []) + const onBlur = React.useCallback(() => { + const _tags = value.trim().split(' ').filter(Boolean) + + if (_tags.length > 0) { + handleChangeTags(Array.from(new Set([...tags, ..._tags])).slice(0, max)) + setValue('') + } + }, [value, tags, max, handleChangeTags]) + const removeTag = React.useCallback( (tag: string) => { handleChangeTags(tags.filter(t => t !== tag)) @@ -110,6 +120,7 @@ export function TagInput({ value={value} onKeyPress={onKeyPress} onChangeText={onChangeText} + onBlur={onBlur} style={[styles.input, pal.textLight]} placeholder="Add tags..." autoCapitalize="none" diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index a69ff862d9..bc51a06d6d 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -339,12 +339,18 @@ export const PostThreadItem = observer(function PostThreadItem({ paddingBottom: 12, }}> {item.post.record.tags.map(tag => ( - - #{tag} - + asAnchor + accessible + anchorNoUnderline + href={`/search?q=${tag}`}> + + #{tag} + + ))} ) : null}