@@ -9,13 +9,35 @@ import { Style } from "./style";
9
9
import { Create } from "./Create" ;
10
10
import { CometChatContext , CometChatUIKit } from "@cometchat/chat-uikit-react-native" ;
11
11
import { AppStyle } from "../../AppStyle" ;
12
-
12
+ import { users } from '../../utils/usersList'
13
13
export const Login = ( { navigation } ) => {
14
14
15
15
const [ isLoginInProgress , setLoginInProgress ] = React . useState ( false ) ;
16
+ const [ usersList , setUsersList ] = React . useState < any > ( [ ] ) ;
16
17
17
18
const { theme } = useContext ( CometChatContext ) ;
18
19
20
+ React . useEffect ( ( ) => {
21
+ fetch ( "https://assets.cometchat.io/sampleapp/sampledata.json" )
22
+ . then ( ( response ) => {
23
+ console . log ( response . status ) ;
24
+ if ( response . status === 200 ) return response . json ( ) ;
25
+ else {
26
+ setUsersList ( users ) ;
27
+ return { } ;
28
+ }
29
+ } )
30
+ . then ( ( res : any ) => {
31
+ if ( res . users )
32
+ setUsersList ( ( ) =>
33
+ res . users . map ( ( item : any ) => ( {
34
+ ...item ,
35
+ avatar : { uri : item . avatar } ,
36
+ } ) )
37
+ ) ;
38
+ } ) ;
39
+ } , [ ] ) ;
40
+
19
41
React . useEffect ( ( ) => {
20
42
CometChatUIKit . getLoggedInUser ( )
21
43
. then ( user => {
@@ -64,25 +86,16 @@ export const Login = ({ navigation }) => {
64
86
< Text style = { { color : theme . palette . getAccent ( ) , textAlign : "center" } } > Login with one of our sample users</ Text >
65
87
66
88
< View style = { { flexDirection : 'row' , justifyContent : "space-between" , marginVertical : 15 , flexWrap : "wrap" } } >
67
- < RoudedButton style = { Style . LoginButton } onPress = { ( ) => makeLogin ( "superhero1" ) } >
68
- < Image style = { Style . ButtonImage } source = { Ironman } />
69
- < Text style = { Style . ButtonText } > SUPERHERO 1</ Text >
70
- </ RoudedButton >
71
-
72
- < RoudedButton style = { Style . LoginButton } onPress = { ( ) => makeLogin ( "superhero2" ) } >
73
- < Image style = { Style . ButtonImage } source = { Captainamerica } />
74
- < Text style = { Style . ButtonText } > SUPERHERO 2</ Text >
75
- </ RoudedButton >
76
-
77
- < RoudedButton style = { Style . LoginButton } onPress = { ( ) => makeLogin ( "superhero3" ) } >
78
- < Image style = { Style . ButtonImage } source = { Spiderman } />
79
- < Text style = { Style . ButtonText } > SUPERHERO 3</ Text >
80
- </ RoudedButton >
81
-
82
- < RoudedButton style = { Style . LoginButton } onPress = { ( ) => makeLogin ( "superhero4" ) } >
83
- < Image style = { Style . ButtonImage } source = { Wolverine } />
84
- < Text style = { Style . ButtonText } > SUPERHERO 4</ Text >
85
- </ RoudedButton >
89
+ { Boolean ( usersList . length ) &&
90
+ usersList . map ( ( user :any ) => {
91
+ return (
92
+ < RoudedButton style = { Style . LoginButton } onPress = { ( ) => makeLogin ( user . uid ) } >
93
+ < Image style = { Style . ButtonImage } source = { user . avatar } />
94
+ < Text style = { Style . ButtonText } > { user . name } </ Text >
95
+ </ RoudedButton >
96
+ )
97
+ } )
98
+ }
86
99
</ View >
87
100
88
101
< Text style = { { textAlign : "center" } } > or else login countinue with</ Text >
@@ -97,7 +110,6 @@ export const Login = ({ navigation }) => {
97
110
</ View >
98
111
< View style = { { alignItems : 'center' } } >
99
112
< Create navigator = { navigation } />
100
- { /* <Text>2023 CometChat Inc.</Text> */ }
101
113
</ View >
102
114
</ View >
103
115
</ SafeAreaView >
0 commit comments