@everymatrix/casino-game-page 1.33.5 → 1.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.html CHANGED
@@ -31,11 +31,12 @@
31
31
 
32
32
  <div class="webcomponent">
33
33
  <casino-game-page
34
- gameid="46985"
35
- userid="3884262"
36
- session="97770be8-7ab6-4985-adca-06da9dacadcd"
34
+ favorites="true"
35
+ gameid="41813"
36
+ userid="4506648"
37
+ session="aa4ab578-06dd-4019-b2e1-108f017e42b0"
37
38
  lang="en"
38
- endpoint="https://demo-api.stage.norway.everymatrix.com/v1"
39
+ endpoint="https://demo-api.stage.norway.everymatrix.com"
39
40
  playforfun="true"
40
41
  ></casino-game-page>
41
42
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-game-page",
3
- "version": "1.33.5",
3
+ "version": "1.34.1",
4
4
  "main": "dist/casino-game-page.js",
5
5
  "svelte": "src/index.ts",
6
6
  "scripts": {
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "bf9e67b030b6c15e53a4a29a3262be8d10cae33a"
38
+ "gitHead": "5ce0bbd8d4005bb9f6fbed830e8882a14e79712a"
39
39
  }
@@ -56,6 +56,8 @@
56
56
  let funMode:boolean = false;
57
57
  let anonymousFunMode:boolean = false;
58
58
  let isModal:boolean = true;
59
+ let favoredGamesCollection:Array<string> = [];
60
+ let receivedFavoriteResults:Object;
59
61
 
60
62
  let gameFrameContainer:HTMLElement;
61
63
  let gameInnerContainer:HTMLElement;
@@ -149,6 +151,7 @@
149
151
  isLoading = false;
150
152
  });
151
153
  window.postMessage({ type: 'RequestModalSize' }, window.location.href);
154
+ getFavoritesGames(session, userid)
152
155
  }
153
156
 
154
157
  const addEventsToDisplayedElements = () => {
@@ -178,7 +181,7 @@
178
181
 
179
182
  case 'LaunchGameFrame':
180
183
  openGameFrame(e.data.gameId, e.data.gameFunMode);
181
- break;
184
+ break;
182
185
 
183
186
  case 'ModalClosed':
184
187
  if (integratedgameframedesktop === 'true' || isMobile(userAgent)) {
@@ -232,17 +235,131 @@
232
235
  modalFrameWidth = e.data.modalContainerSize.modalWidth;
233
236
  modalFrameHeight = e.data.modalContainerSize.modalHeight;
234
237
  break;
238
+ }
239
+ }
235
240
 
236
- case 'UpdateCategoryFavoriteGames':
237
- if (e.data.receivedFavoriteResults) {
238
- favoriteGames = e.data.receivedFavoriteResults.items;
241
+ //Get favorites games list and update the favorites category
242
+ const getFavoritesGames = (sessionID:string, playerID:string) => {
243
+ let url = `${endpoint}/v1/player/${playerID}/favorites/`;
244
+
245
+ isLoading = true;
246
+ let options = {
247
+ method: "GET",
248
+ headers: {
249
+ 'X-SessionID': sessionID,
250
+ }
251
+ };
239
252
 
240
- if (game && game.id) {
241
- game.isFavored = checkFavorite(game.id);
242
- isFavLoading = false;
253
+ return new Promise((resolve, reject) => {
254
+ fetch(url, options)
255
+ .then((res:any) => res.json())
256
+ .then((updatedArray:any) => {
257
+ isLoading = false;
258
+ receivedFavoriteResults = updatedArray;
259
+
260
+ if (receivedFavoriteResults) {
261
+ updateCategoryFavoriteGames(receivedFavoriteResults);
262
+ favoredGamesCollection = [];
263
+
264
+ if (receivedFavoriteResults.items.length > 0) {
265
+ receivedFavoriteResults.items.forEach((fav:any) => {
266
+ favoredGamesCollection.push(fav.id);
267
+ });
268
+ }
269
+
270
+ } else {
271
+ receivedFavoriteResults = [];
272
+ return receivedFavoriteResults;
243
273
  }
274
+
275
+ resolve(receivedFavoriteResults);
276
+
277
+ }).catch((err:any) => {
278
+ console.error(err);
279
+
280
+ reject(err);
281
+ });
282
+ });
283
+ }
284
+
285
+ //Add / Remove favorites games
286
+ const toggleFavoriteGame = (id:any):void => {
287
+ if (game.isFavored) {
288
+ removeFavoredGame(`${endpoint}/v1/player/${userid}/favorites`, session, game.id);
289
+ } else {
290
+ addFavoredGame(`${endpoint}/v1/player/${userid}/favorites`, session, game.id);
291
+ }
292
+ }
293
+
294
+ let addFavoredGame = (url, sessionID, gameID) => {
295
+ // When adding new favored games, the api requires an array with all the current favored games due to the fact that it overwrites the old ones with the ones found in the body of the POST request
296
+
297
+ if (!favoredGamesCollection.includes(gameID)) {
298
+ favoredGamesCollection.push(gameID);
299
+ }
300
+
301
+ let data = {
302
+ items: favoredGamesCollection
303
+ };
304
+
305
+ let options = {
306
+ method: "POST",
307
+ headers: {
308
+ 'X-SessionID': sessionID,
309
+ 'Content-Type': 'application/json',
310
+ 'Accept': 'application/json',
311
+ },
312
+ body: JSON.stringify(data)
313
+ };
314
+
315
+ fetch(url, options)
316
+ .then((res:any) => res.json())
317
+ .then(() => {
318
+ window.postMessage({ type: `AddFavoriteThumbnail_${gameID}` }, window.location.href);
319
+ //Make a get for a new list to update the view
320
+
321
+ window.postMessage({ type: 'UpdateFavoredList', url, sessionID});
322
+ getFavoritesGames(session, userid)
323
+ })
324
+ .catch((err:any) => {
325
+ console.error('Err', err);
326
+ });
327
+ }
328
+
329
+ const removeFavoredGame = (url, sessionID, gameID) => {
330
+
331
+ let options = {
332
+ method: "DELETE",
333
+ headers: {
334
+ 'X-SessionID': sessionID,
244
335
  }
245
- break;
336
+ };
337
+
338
+ fetch(`${url}/${gameID}`, options)
339
+ .then((res:any) => res.json())
340
+ .then(() => {
341
+ window.postMessage({ type: `RemoveFavoriteThumbnail_${gameID}` }, window.location.href);
342
+ //Make a get for a new list to update the view
343
+ window.postMessage({ type: 'UpdateFavoredList', url, sessionID});
344
+ getFavoritesGames(session, userid)
345
+ });
346
+
347
+ if (favoredGamesCollection.includes(gameID)) {
348
+ favoredGamesCollection = favoredGamesCollection.filter(x => {
349
+ return x != gameID;
350
+ });
351
+ }
352
+ }
353
+
354
+ //Add isFavored prop. for every favorite game
355
+ const updateCategoryFavoriteGames = (receivedFavoriteResults) => {
356
+ if (receivedFavoriteResults) {
357
+ favoriteGames = receivedFavoriteResults.items;
358
+
359
+ if (game && game.id) {
360
+ game.isFavored = checkFavorite(game.id);
361
+ isFavLoading = false;
362
+ }
246
363
  }
247
364
  }
248
365
 
@@ -254,17 +371,6 @@
254
371
  }
255
372
  }
256
373
 
257
- const toggleFavoriteGame = (id:any):void => {
258
- let triggerFactor = "gamepage";
259
- if (game.isFavored) {
260
- window.postMessage({ type: 'SetUnfavoredGame', id, triggerFactor }, window.location.href);
261
- game.isFavored = false;
262
- } else {
263
- window.postMessage({ type: 'SetFavoredGame', id, triggerFactor }, window.location.href);
264
- game.isFavored = true;
265
- }
266
- }
267
-
268
374
  const setGameData = (game, gameFunMode) => {
269
375
  anonymousFunMode = playforfun == 'true' ? game.hasAnonymousFunMode : false;
270
376
  funMode = playforfun == 'true' ? gameFunMode : false;
@@ -581,7 +687,7 @@
581
687
  window.addEventListener('resize', resizeHandler, false);
582
688
  window.addEventListener('message', messageHandler, false);
583
689
 
584
- return () => {
690
+ return () => {
585
691
  removeEventsToDisplayedElements();
586
692
  window.removeEventListener('resize', resizeHandler);
587
693
  window.removeEventListener('message', messageHandler);