Skip to content

Commit b754c94

Browse files
committed
Now user details will be pulled from the static JSON data in sample app
1 parent 0a200ef commit b754c94

File tree

5 files changed

+72
-23
lines changed

5 files changed

+72
-23
lines changed

src/components/login/Login.tsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,35 @@ import { Style } from "./style";
99
import { Create } from "./Create";
1010
import { CometChatContext, CometChatUIKit } from "@cometchat/chat-uikit-react-native";
1111
import { AppStyle } from "../../AppStyle";
12-
12+
import {users} from '../../utils/usersList'
1313
export const Login = ({ navigation }) => {
1414

1515
const [isLoginInProgress, setLoginInProgress] = React.useState(false);
16+
const [usersList, setUsersList] = React.useState<any>([]);
1617

1718
const { theme } = useContext(CometChatContext);
1819

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+
1941
React.useEffect(() => {
2042
CometChatUIKit.getLoggedInUser()
2143
.then(user => {
@@ -64,25 +86,16 @@ export const Login = ({ navigation }) => {
6486
<Text style={{ color: theme.palette.getAccent(), textAlign: "center" }}>Login with one of our sample users</Text>
6587

6688
<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+
}
8699
</View>
87100

88101
<Text style={{ textAlign: "center" }}>or else login countinue with</Text>
@@ -97,7 +110,6 @@ export const Login = ({ navigation }) => {
97110
</View>
98111
<View style={{ alignItems: 'center' }}>
99112
<Create navigator={navigation} />
100-
{/* <Text>2023 CometChat Inc.</Text> */}
101113
</View>
102114
</View>
103115
</SafeAreaView>

src/components/login/style.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ export const Style = StyleSheet.create({
2222
backgroundColor: 'black',
2323
marginBottom: 8,
2424
padding: 16,
25-
width: "48%"
25+
width: "48%",
26+
justifyContent: "flex-start"
27+
2628
},
2729
ButtonText: {
28-
color: 'white'
30+
color: 'white',
31+
marginLeft: 10
2932
},
3033
CustomLoginButton: {
3134
backgroundColor: 'rgb(50,150,255)',

src/resources/cyclops.png

7.88 KB
Loading

src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ import CallRecording from './Calllogrecording.png';
4646
import CallLogs from './Calllogs.png';
4747
import CallParticipants from './callparticipants.png';
4848
import Scheduler from './schedule.png';
49+
import Cyclops from './cyclops.png'
4950

5051
export {
52+
Cyclops,
5153
Details,
5254
BanUser,
5355
Transfer,

src/utils/usersList.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {
2+
Ironman, Captainamerica,
3+
Spiderman, Wolverine,Cyclops
4+
} from "../resources";
5+
export const users = [
6+
{
7+
"uid": "superhero1",
8+
"name": "Iron Man",
9+
"avatar": Ironman
10+
},
11+
{
12+
"uid": "superhero2",
13+
"name": "Captain America",
14+
"avatar": Captainamerica
15+
},
16+
{
17+
"uid": "superhero3",
18+
"name": "Spiderman",
19+
"avatar": Spiderman
20+
},
21+
{
22+
"uid": "superhero4",
23+
"name": "Wolverine",
24+
"avatar": Wolverine
25+
},
26+
{
27+
"uid": "superhero5",
28+
"name": "Cyclops",
29+
"avatar": Cyclops
30+
}
31+
]
32+

0 commit comments

Comments
 (0)