119
119
<script lang="ts">
120
120
/* es-lint disabled*/
121
121
122
- import { defineComponent , inject , ref } from " vue" ;
122
+ import { defineComponent , inject , onBeforeMount , ref } from " vue" ;
123
123
import " @cometchat/uikit-elements" ;
124
124
import { fontHelper } from " @cometchat/uikit-resources" ;
125
125
import { CometChat } from " @cometchat/chat-sdk-javascript" ;
@@ -133,8 +133,15 @@ import {
133
133
} from " ../assets" ;
134
134
import { CometChatUIKit } from " @cometchat/chat-uikit-vue" ;
135
135
import { metaInfo } from " ../metaInfo" ;
136
+ import { users } from " ../sampleApp/sampledata" ;
136
137
let buttonImage = " assets/button-opc.png" ;
137
138
139
+ type User = {
140
+ name: string ;
141
+ uid: string ;
142
+ avatar: string ;
143
+ };
144
+
138
145
export default defineComponent ({
139
146
name: " LoginComponent" ,
140
147
components: {},
@@ -148,6 +155,7 @@ export default defineComponent({
148
155
let enteredUid! : string ;
149
156
let enteredName! : string ;
150
157
let inProgress = ref (false );
158
+ const usersArray = ref <User []>([]);
151
159
152
160
let avatarStyle: AvatarStyle = {
153
161
height: " 32px" ,
@@ -236,36 +244,25 @@ export default defineComponent({
236
244
router .push ({ path: " /signup" });
237
245
};
238
246
239
- const usersArray = [
240
- {
241
- name: " Iron Man" ,
242
- UID: " SUPERHERO1" ,
243
- uid: " superhero1" ,
244
- avatar:
245
- " https://data-us.cometchat.io/assets/images/avatars/ironman.png" ,
246
- },
247
- {
248
- name: " Captain America" ,
249
- UID: " SUPERHERO2" ,
250
- uid: " superhero2" ,
251
- avatar:
252
- " https://data-us.cometchat.io/assets/images/avatars/captainamerica.png" ,
253
- },
254
- {
255
- name: " Spiderman" ,
256
- UID: " SUPERHERO3" ,
257
- uid: " superhero3" ,
258
- avatar:
259
- " https://data-us.cometchat.io/assets/images/avatars/spiderman.png" ,
260
- },
261
- {
262
- name: " Wolvorine" ,
263
- UID: " SUPERHERO4" ,
264
- uid: " superhero4" ,
265
- avatar:
266
- " https://data-us.cometchat.io/assets/images/avatars/wolverine.png" ,
267
- },
268
- ];
247
+ async function fetchDefaultUsers() {
248
+ try {
249
+ const response = await fetch (
250
+ " https://assets.cometchat.io/sampleapp/sampledata.json"
251
+ );
252
+ const data = await response .json ();
253
+ usersArray .value = data .users ;
254
+ } catch (error ) {
255
+ console .log (
256
+ " fetching default users failed, using fallback data" ,
257
+ error
258
+ );
259
+ usersArray .value = users .users ;
260
+ }
261
+ }
262
+
263
+ onBeforeMount (() => {
264
+ fetchDefaultUsers ();
265
+ });
269
266
270
267
const styles: any = {
271
268
loginWrapperStyle : () => {
0 commit comments