Use new api pkg APIs
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
FontAwesomeIconStyle,
|
||||
} from '@fortawesome/react-native-fontawesome'
|
||||
import BottomSheet, {BottomSheetBackdrop} from '@gorhom/bottom-sheet'
|
||||
import {sanitizeHashtag} from '@atproto/api'
|
||||
|
||||
import {Portal} from 'view/com/util/Portal'
|
||||
import {TagsAutocompleteModel} from 'state/models/ui/tags-autocomplete'
|
||||
@@ -23,7 +24,7 @@ import {useStores} from 'state/index'
|
||||
import {ActivityIndicator} from 'react-native'
|
||||
import {TagInputEntryButton} from './TagInputEntryButton'
|
||||
import {uniq} from 'lib/strings/helpers'
|
||||
import {sanitizeHashtag, sanitizeHashtagOnChange} from './util'
|
||||
import {sanitizeHashtagOnChange} from './util'
|
||||
|
||||
export function TagInput({
|
||||
max = 8,
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
FontAwesomeIconStyle,
|
||||
} from '@fortawesome/react-native-fontawesome'
|
||||
import {Pin} from 'pind'
|
||||
import {sanitizeHashtag} from '@atproto/api'
|
||||
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {TagsAutocompleteModel} from 'state/models/ui/tags-autocomplete'
|
||||
@@ -23,7 +24,7 @@ import {useStores} from 'state/index'
|
||||
import {TagInputEntryButton} from './TagInputEntryButton'
|
||||
import {TextInputFocusEventData} from 'react-native'
|
||||
import {uniq} from 'lib/strings/helpers'
|
||||
import {sanitizeHashtag, sanitizeHashtagOnChange} from './util'
|
||||
import {sanitizeHashtagOnChange} from './util'
|
||||
|
||||
export function TagInput({
|
||||
max = 8,
|
||||
|
||||
@@ -1,28 +1,19 @@
|
||||
import {
|
||||
HASHTAG_INVALID_CHARACTER_REGEX,
|
||||
TRAILING_PUNCTUATION_REGEX,
|
||||
LEADING_PUNCTUATION_REGEX,
|
||||
LEADING_NUMBER_REGEX,
|
||||
LEADING_HASH_REGEX,
|
||||
} from '@atproto/api'
|
||||
|
||||
/**
|
||||
* Trims leading numbers, all invalid characters, and any trailing punctuation.
|
||||
*/
|
||||
export function sanitizeHashtag(hashtag: string) {
|
||||
return hashtag
|
||||
.replace(LEADING_PUNCTUATION_REGEX, '')
|
||||
.replace(LEADING_NUMBER_REGEX, '')
|
||||
.replace(HASHTAG_INVALID_CHARACTER_REGEX, '')
|
||||
.replace(TRAILING_PUNCTUATION_REGEX, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims leading numbers and all invalid charactes, but ignores trailing
|
||||
* Basically `sanitizeHashtag` from `@atproto/api`, but ignores trailing
|
||||
* punctuation in case the user intends to use `_` or `-`.
|
||||
*/
|
||||
export function sanitizeHashtagOnChange(hashtag: string) {
|
||||
return hashtag
|
||||
.replace(LEADING_PUNCTUATION_REGEX, '')
|
||||
.replace(LEADING_HASH_REGEX, '')
|
||||
.replace(LEADING_NUMBER_REGEX, '')
|
||||
.replace(LEADING_PUNCTUATION_REGEX, '')
|
||||
.replace(HASHTAG_INVALID_CHARACTER_REGEX, '')
|
||||
.slice(0, 64)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
HASHTAG_REGEX_WITH_TRAILING_PUNCTUATION,
|
||||
HASHTAG_WITH_TRAILING_PUNCTUATION_REGEX,
|
||||
TRAILING_PUNCTUATION_REGEX,
|
||||
LEADING_HASH_REGEX,
|
||||
} from '@atproto/api'
|
||||
@@ -31,7 +31,7 @@ export function findSuggestionMatch({
|
||||
cursorPosition: number
|
||||
}) {
|
||||
const match = Array.from(
|
||||
text.matchAll(HASHTAG_REGEX_WITH_TRAILING_PUNCTUATION),
|
||||
text.matchAll(HASHTAG_WITH_TRAILING_PUNCTUATION_REGEX),
|
||||
).pop()
|
||||
|
||||
if (!match || match.input === undefined || match.index === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user