1+ import { ConnectionDetails , fetchToken } from '@/hooks/useConnectionDetails' ;
12import { useRouter } from 'expo-router' ;
2- import { StyleSheet , Button , View } from 'react-native' ;
3+ import { useEffect , useState } from 'react' ;
4+ import {
5+ StyleSheet ,
6+ View ,
7+ Image ,
8+ Text ,
9+ TouchableOpacity ,
10+ ActivityIndicator ,
11+ } from 'react-native' ;
312
413export default function StartScreen ( ) {
514 const router = useRouter ( ) ;
615
16+ let [ isConnecting , setConnecting ] = useState ( false ) ;
17+ let [ connectionDetails , setConnectionDetails ] = useState <
18+ ConnectionDetails | undefined
19+ > ( undefined ) ;
20+
21+ // Fetch token when we're connecting.
22+ useEffect ( ( ) => {
23+ if ( isConnecting ) {
24+ fetchToken ( ) . then ( ( details ) => {
25+ console . log ( details ) ;
26+ setConnectionDetails ( details ) ;
27+ if ( ! details ) {
28+ setConnecting ( false ) ;
29+ }
30+ } ) ;
31+ }
32+ } , [ isConnecting ] ) ;
33+
34+ // Navigate to Assistant screen when we have the connection details.
35+ useEffect ( ( ) => {
36+ if ( isConnecting && connectionDetails ) {
37+ setConnecting ( false ) ;
38+ setConnectionDetails ( undefined ) ;
39+ router . navigate ( '../assistant' ) ;
40+ }
41+ } , [ isConnecting , router , connectionDetails ] ) ;
42+
43+ let connectText : string ;
44+
45+ if ( isConnecting ) {
46+ connectText = 'Connecting' ;
47+ } else {
48+ connectText = 'Start Voice Assistant' ;
49+ }
50+
751 return (
852 < View style = { styles . container } >
9- < Button
10- onPress = { ( ) => router . navigate ( '../assistant' ) }
11- title = "Start Voice Assistant"
53+ < Image
54+ style = { styles . logo }
55+ source = { require ( '../../assets/images/start-logo.png' ) }
1256 />
57+ < Text style = { styles . text } > Chat live with your voice AI agent</ Text >
58+
59+ < TouchableOpacity
60+ onPress = { ( ) => {
61+ setConnecting ( true ) ;
62+ } }
63+ style = { styles . button }
64+ activeOpacity = { 0.7 }
65+ disabled = { isConnecting } // Disable button while loading
66+ >
67+ { isConnecting ? (
68+ < ActivityIndicator
69+ size = "small"
70+ color = "#ffffff"
71+ style = { styles . activityIndicator }
72+ />
73+ ) : undefined }
74+
75+ < Text style = { styles . buttonText } > { connectText } </ Text >
76+ </ TouchableOpacity >
1377 </ View >
1478 ) ;
1579}
@@ -20,4 +84,29 @@ const styles = StyleSheet.create({
2084 alignItems : 'center' ,
2185 justifyContent : 'center' ,
2286 } ,
87+ logo : {
88+ width : 59 ,
89+ height : 56 ,
90+ marginBottom : 16 ,
91+ } ,
92+ text : {
93+ color : '#ffffff' ,
94+ marginBottom : 24 ,
95+ } ,
96+ activityIndicator : {
97+ marginEnd : 8 ,
98+ } ,
99+ button : {
100+ flexDirection : 'row' ,
101+ backgroundColor : '#002CF2' ,
102+ paddingVertical : 12 ,
103+ paddingHorizontal : 12 ,
104+ borderRadius : 24 ,
105+ alignItems : 'center' ,
106+ justifyContent : 'center' ,
107+ minWidth : 200 , // Ensure button has a minimum width when loading
108+ } ,
109+ buttonText : {
110+ color : '#ffffff' ,
111+ } ,
23112} ) ;
0 commit comments