import React, {useState} from 'react' import Toast from '../util/Toast' import { ActivityIndicator, StyleSheet, Text, TextInput, TouchableOpacity, View, } from 'react-native' import LinearGradient from 'react-native-linear-gradient' import {ErrorMessage} from '../util/ErrorMessage' import {useStores} from '../../../state' import {s, colors, gradients} from '../../lib/styles' import {makeValidHandle, createFullHandle} from '../../lib/strings' import {AppBskyActorCreateScene} from '../../../third-party/api/index' export const snapPoints = ['70%'] export function Component({}: {}) { const store = useStores() const [error, setError] = useState('') const [isProcessing, setIsProcessing] = useState(false) const [handle, setHandle] = useState('') const [displayName, setDisplayName] = useState('') const [description, setDescription] = useState('') const onPressSave = async () => { setIsProcessing(true) if (error) { setError('') } try { if (!store.me.did) { return } const desc = await store.api.com.atproto.server.getAccountsConfig() const fullHandle = createFullHandle( handle, desc.data.availableUserDomains[0], ) // create scene actor const createSceneRes = await store.api.app.bsky.actor.createScene({ handle: fullHandle, }) // set the scene profile // TODO // follow the scene await store.api.app.bsky.graph.follow .create( { did: store.me.did, }, { subject: { did: createSceneRes.data.did, declarationCid: createSceneRes.data.declaration.cid, }, createdAt: new Date().toISOString(), }, ) .catch(e => console.error(e)) // an error here is not critical Toast.show('Scene created', { position: Toast.positions.TOP, }) store.shell.closeModal() store.nav.navigate(`/profile/${fullHandle}`) } catch (e: any) { if (e instanceof AppBskyActorCreateScene.InvalidHandleError) { setError( 'The handle can only contain letters, numbers, and dashes, and must start with a letter.', ) } else if (e instanceof AppBskyActorCreateScene.HandleNotAvailableError) { setError(`The handle "${handle}" is not available.`) } else { console.error(e) setError( 'Failed to create the scene. Check your internet connection and try again.', ) } setIsProcessing(false) } } return ( Create a scene Scenes are invite-only groups which aggregate what's popular with members. Scene Handle setHandle(makeValidHandle(str))} /> Scene Display Name Scene Description {error !== '' && ( )} {handle.length >= 2 && !isProcessing ? ( Create Scene ) : ( {isProcessing ? ( ) : ( Create Scene )} )} ) } const styles = StyleSheet.create({ title: { textAlign: 'center', fontWeight: 'bold', fontSize: 24, marginBottom: 12, }, description: { textAlign: 'center', fontSize: 17, paddingHorizontal: 22, color: colors.gray5, marginBottom: 10, }, inner: { padding: 14, }, group: { marginBottom: 10, }, label: { fontSize: 16, fontWeight: 'bold', paddingHorizontal: 4, paddingBottom: 4, }, textInput: { borderWidth: 1, borderColor: colors.gray3, borderRadius: 6, paddingHorizontal: 14, paddingVertical: 10, fontSize: 16, }, textArea: { borderWidth: 1, borderColor: colors.gray3, borderRadius: 6, paddingHorizontal: 12, paddingTop: 10, fontSize: 16, height: 100, textAlignVertical: 'top', }, errorContainer: { height: 80, }, btn: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', width: '100%', borderRadius: 32, padding: 14, marginBottom: 10, backgroundColor: colors.gray1, }, })