Enforce limits on create scene as well

zio/stable
Paul Frazee 2022-11-14 15:19:08 -06:00
parent 4a0b79da4a
commit 4a2170be49
3 changed files with 26 additions and 6 deletions

View File

@ -4,7 +4,6 @@ import {
ActivityIndicator, ActivityIndicator,
StyleSheet, StyleSheet,
Text, Text,
TextInput,
TouchableOpacity, TouchableOpacity,
View, View,
} from 'react-native' } from 'react-native'
@ -13,7 +12,13 @@ import {BottomSheetScrollView, BottomSheetTextInput} from '@gorhom/bottom-sheet'
import {ErrorMessage} from '../util/ErrorMessage' import {ErrorMessage} from '../util/ErrorMessage'
import {useStores} from '../../../state' import {useStores} from '../../../state'
import {s, colors, gradients} from '../../lib/styles' import {s, colors, gradients} from '../../lib/styles'
import {makeValidHandle, createFullHandle} from '../../lib/strings' import {
makeValidHandle,
createFullHandle,
enforceLen,
MAX_DISPLAY_NAME,
MAX_DESCRIPTION,
} from '../../lib/strings'
import {AppBskyActorCreateScene} from '../../../third-party/api/index' import {AppBskyActorCreateScene} from '../../../third-party/api/index'
export const snapPoints = ['60%'] export const snapPoints = ['60%']
@ -102,6 +107,7 @@ export function Component({}: {}) {
<BottomSheetTextInput <BottomSheetTextInput
style={styles.textInput} style={styles.textInput}
placeholder="e.g. alices-friends" placeholder="e.g. alices-friends"
autoCorrect={false}
value={handle} value={handle}
onChangeText={str => setHandle(makeValidHandle(str))} onChangeText={str => setHandle(makeValidHandle(str))}
/> />
@ -112,7 +118,9 @@ export function Component({}: {}) {
style={styles.textInput} style={styles.textInput}
placeholder="e.g. Alice's Friends" placeholder="e.g. Alice's Friends"
value={displayName} value={displayName}
onChangeText={setDisplayName} onChangeText={v =>
setDisplayName(enforceLen(v, MAX_DISPLAY_NAME))
}
/> />
</View> </View>
<View style={styles.group}> <View style={styles.group}>
@ -122,7 +130,7 @@ export function Component({}: {}) {
placeholder="e.g. Artists, dog-lovers, and memelords." placeholder="e.g. Artists, dog-lovers, and memelords."
multiline multiline
value={description} value={description}
onChangeText={setDescription} onChangeText={v => setDescription(enforceLen(v, MAX_DESCRIPTION))}
/> />
</View> </View>
{error !== '' && ( {error !== '' && (

View File

@ -6,6 +6,7 @@ import {ErrorMessage} from '../util/ErrorMessage'
import {useStores} from '../../../state' import {useStores} from '../../../state'
import {ProfileViewModel} from '../../../state/models/profile-view' import {ProfileViewModel} from '../../../state/models/profile-view'
import {s, colors, gradients} from '../../lib/styles' import {s, colors, gradients} from '../../lib/styles'
import {enforceLen, MAX_DISPLAY_NAME, MAX_DESCRIPTION} from '../../lib/strings'
import * as Profile from '../../../third-party/api/src/client/types/app/bsky/actor/profile' import * as Profile from '../../../third-party/api/src/client/types/app/bsky/actor/profile'
export const snapPoints = ['80%'] export const snapPoints = ['80%']
@ -64,7 +65,7 @@ export function Component({profileView}: {profileView: ProfileViewModel}) {
style={styles.textInput} style={styles.textInput}
placeholder="e.g. Alice Roberts" placeholder="e.g. Alice Roberts"
value={displayName} value={displayName}
onChangeText={setDisplayName} onChangeText={v => setDisplayName(enforceLen(v, MAX_DISPLAY_NAME))}
/> />
</View> </View>
<View style={styles.group}> <View style={styles.group}>
@ -74,7 +75,7 @@ export function Component({profileView}: {profileView: ProfileViewModel}) {
placeholder="e.g. Artist, dog-lover, and memelord." placeholder="e.g. Artist, dog-lover, and memelord."
multiline multiline
value={description} value={description}
onChangeText={setDescription} onChangeText={v => setDescription(enforceLen(v, MAX_DESCRIPTION))}
/> />
</View> </View>
<TouchableOpacity style={s.mt10} onPress={onPressSave}> <TouchableOpacity style={s.mt10} onPress={onPressSave}>

View File

@ -1,6 +1,9 @@
import {AtUri} from '../../third-party/uri' import {AtUri} from '../../third-party/uri'
import {Entity} from '../../third-party/api/src/client/types/app/bsky/feed/post' import {Entity} from '../../third-party/api/src/client/types/app/bsky/feed/post'
export const MAX_DISPLAY_NAME = 64
export const MAX_DESCRIPTION = 256
export function pluralize(n: number, base: string, plural?: string): string { export function pluralize(n: number, base: string, plural?: string): string {
if (n === 1) { if (n === 1) {
return base return base
@ -85,3 +88,11 @@ export function createFullHandle(name: string, domain: string): string {
domain = domain.replace(/^[\.]+/, '') domain = domain.replace(/^[\.]+/, '')
return `${name}.${domain}` return `${name}.${domain}`
} }
export function enforceLen(str: string, len: number): string {
str = str || ''
if (str.length > len) {
return str.slice(0, len)
}
return str
}