@everymatrix/casino-search 1.1.6 → 1.2.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
@@ -95,6 +95,7 @@
95
95
  endpoint="https://demo-api.stage.norway.everymatrix.com/v1"
96
96
  datasource="RNG"
97
97
  lang="en"
98
+ showfavorites="true"
98
99
  ></casino-search>
99
100
  </body>
100
101
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-search",
3
- "version": "1.1.6",
3
+ "version": "1.2.1",
4
4
  "main": "index.js",
5
5
  "svelte": "src/index.ts",
6
6
  "scripts": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "6ad785980b67f3b54da658b8df9f60190a10ffcc"
39
+ "gitHead": "de8b2a024255bd2ed76c13501c5a6dc858263dcb"
40
40
  }
@@ -15,7 +15,9 @@
15
15
  export let clientstylingurl:string = '';
16
16
  export let integratedgameframedesktop:string = 'false';
17
17
  export let integratedgameframemobile:string = 'false';
18
+ export let gamepagemodalurl:string = 'true';
18
19
  export let translationUrl:string = '';
20
+ export let showfavorites:string = '';
19
21
 
20
22
  let userAgent:any = window.navigator.userAgent;
21
23
  let searchArray:Array<any> = [];
@@ -30,6 +32,11 @@
30
32
  let isLoading:boolean = false;
31
33
  let customStylingContainer:HTMLElement;
32
34
 
35
+ let isLoggedIn:boolean = false;
36
+ let sessionID:string;
37
+ let playerID:string;
38
+ let favoriteGamesIds: string[] = [];
39
+
33
40
  const setTranslationUrl = ():void => {
34
41
  let url:string = translationUrl;
35
42
 
@@ -51,6 +58,17 @@
51
58
  if (e.data && e.data.type == 'OpenGameFrame') {
52
59
  addSearchedItem(e.data.gameId);
53
60
  }
61
+
62
+ if (e.data && e.data.type == 'ShowGameModal') {
63
+ addSearchedItem(e.data.gameId);
64
+ }
65
+
66
+ if (e.data.type === 'UserSessionID') {
67
+ sessionID = e.data.session;
68
+ playerID = e.data.userid;
69
+ isLoggedIn = true;
70
+ }
71
+
54
72
  }
55
73
 
56
74
  const onFocus = ():void => {
@@ -82,7 +100,11 @@
82
100
  }
83
101
 
84
102
  Promise.all(promises).then((res:any):void => {
85
- searchArray = res;
103
+ searchArray = res.map((item) => {
104
+ item.isFavorite = checkFavorite(item.id);
105
+
106
+ return item;
107
+ });
86
108
  });
87
109
  }
88
110
  }
@@ -144,6 +166,37 @@
144
166
  }
145
167
  });
146
168
  }
169
+
170
+ const getFavoriteGames = ():void => {
171
+
172
+ const url:URL = new URL(`${endpoint}/player/${playerID}/favorites/`);
173
+
174
+ isLoading = true;
175
+
176
+ let options = {
177
+ method: "GET",
178
+ headers: {
179
+ 'X-SessionID': sessionID,
180
+ }
181
+ };
182
+
183
+ fetch(url.href, options)
184
+ .then((res:any) => res.json())
185
+ .then((favoriteGames:any) => {
186
+ isLoading = false;
187
+
188
+ favoriteGamesIds = favoriteGames.items.map(favoriteGame => favoriteGame.id);
189
+ });
190
+ }
191
+
192
+ const checkFavorite = (gameId:string):boolean => {
193
+ if (favoriteGamesIds.findIndex((favGameId:any) => favGameId == gameId) !== -1) {
194
+ return true;
195
+ } else {
196
+ return false;
197
+ }
198
+ }
199
+
147
200
 
148
201
  const addSearchedItem = (gameID:any):void => {
149
202
  searchedValues = getCookieValue(`searchedGamesWds_casino`);
@@ -226,7 +279,11 @@
226
279
  searchUrl.searchParams.append("filter", `name=${searchValue}`);
227
280
 
228
281
  getGames(searchUrl).then((searchData:any) => {
229
- searchArray = searchData.items.map((item) => item);
282
+ searchArray = searchData.items.map((item) => {
283
+ item.isFavorite = checkFavorite(item.id);
284
+
285
+ return item;
286
+ });
230
287
  });
231
288
  } else {
232
289
  if (!searchCancelled) {
@@ -244,11 +301,11 @@
244
301
 
245
302
  $: lang && setActiveLanguage();
246
303
  $: translationUrl && setTranslationUrl();
304
+ $: showfavorites && isLoggedIn && getFavoriteGames();
247
305
  $: clientstyling && customStylingContainer && setClientStyling();
248
306
  $: clientstylingurl && customStylingContainer && setClientStylingURL();
249
307
 
250
308
  </script>
251
-
252
309
  <div class="CasinoSearch" bind:this={customStylingContainer}>
253
310
  <div class="Search">
254
311
  <div class="SearchIcon">
@@ -286,6 +343,8 @@
286
343
  {#if searchCancelled === false}
287
344
  {#each searchArray as game}
288
345
  <casino-game-thumbnail
346
+ endpoint={endpoint}
347
+ favorites = {showfavorites}
289
348
  lang={lang}
290
349
  gamethumbnail={game.thumbnail}
291
350
  gamename={game.name}
@@ -297,11 +356,11 @@
297
356
  gamefunmode={game.hasFunMode}
298
357
  gamefavorite={game.isFavorite}
299
358
  livelobbyendpoint={game.details ? game.launchUrl : ''}
300
- endpoint={endpoint}
301
359
  {integratedgameframedesktop}
302
360
  {integratedgameframemobile}
303
361
  {clientstyling}
304
362
  {clientstylingurl}
363
+ {gamepagemodalurl}
305
364
  ></casino-game-thumbnail>
306
365
  {/each}
307
366
  {/if}