link out tags
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
NativeSyntheticEvent,
|
NativeSyntheticEvent,
|
||||||
TextInputKeyPressEventData,
|
TextInputKeyPressEventData,
|
||||||
Pressable,
|
Pressable,
|
||||||
|
InteractionManager,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {
|
import {
|
||||||
FontAwesomeIcon,
|
FontAwesomeIcon,
|
||||||
@@ -60,19 +61,19 @@ export function TagInput({
|
|||||||
|
|
||||||
const onKeyPress = React.useCallback(
|
const onKeyPress = React.useCallback(
|
||||||
(e: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
|
(e: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
|
||||||
if (e.nativeEvent.key === 'Enter') {
|
if (e.nativeEvent.key === 'Enter' || e.nativeEvent.key === ' ') {
|
||||||
const _tags = value.trim().split(' ').filter(Boolean)
|
const _tags = value.trim().split(' ').filter(Boolean)
|
||||||
|
|
||||||
if (_tags.length > 0) {
|
if (_tags.length > 0) {
|
||||||
handleChangeTags(
|
handleChangeTags(
|
||||||
Array.from(new Set([...tags, ..._tags])).slice(0, max),
|
Array.from(new Set([...tags, ..._tags])).slice(0, max),
|
||||||
)
|
)
|
||||||
setValue('')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
InteractionManager.runAfterInteractions(() => {
|
||||||
|
setValue('')
|
||||||
input.current?.focus()
|
input.current?.focus()
|
||||||
}, 100)
|
})
|
||||||
} else if (e.nativeEvent.key === 'Backspace' && value === '') {
|
} else if (e.nativeEvent.key === 'Backspace' && value === '') {
|
||||||
handleChangeTags(tags.slice(0, -1))
|
handleChangeTags(tags.slice(0, -1))
|
||||||
}
|
}
|
||||||
@@ -85,6 +86,15 @@ export function TagInput({
|
|||||||
setValue(sanitized)
|
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(
|
const removeTag = React.useCallback(
|
||||||
(tag: string) => {
|
(tag: string) => {
|
||||||
handleChangeTags(tags.filter(t => t !== tag))
|
handleChangeTags(tags.filter(t => t !== tag))
|
||||||
@@ -110,6 +120,7 @@ export function TagInput({
|
|||||||
value={value}
|
value={value}
|
||||||
onKeyPress={onKeyPress}
|
onKeyPress={onKeyPress}
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
|
onBlur={onBlur}
|
||||||
style={[styles.input, pal.textLight]}
|
style={[styles.input, pal.textLight]}
|
||||||
placeholder="Add tags..."
|
placeholder="Add tags..."
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
|
|||||||
@@ -339,12 +339,18 @@ export const PostThreadItem = observer(function PostThreadItem({
|
|||||||
paddingBottom: 12,
|
paddingBottom: 12,
|
||||||
}}>
|
}}>
|
||||||
{item.post.record.tags.map(tag => (
|
{item.post.record.tags.map(tag => (
|
||||||
<Text
|
<Link
|
||||||
key={tag}
|
key={tag}
|
||||||
type="xs-medium"
|
asAnchor
|
||||||
style={[styles.tag, pal.viewLight, pal.textLight]}>
|
accessible
|
||||||
#{tag}
|
anchorNoUnderline
|
||||||
</Text>
|
href={`/search?q=${tag}`}>
|
||||||
|
<Text
|
||||||
|
type="xs-medium"
|
||||||
|
style={[styles.tag, pal.viewLight, pal.textLight]}>
|
||||||
|
#{tag}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
Reference in New Issue
Block a user