@everymatrix/casino-categories-slider 1.3.3 → 1.4.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-categories-slider",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "main": "dist/casino-categories-slider.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": "a3f9e9cbbb1c3537031608dfbcfd6293c7ec408b"
39
+ "gitHead": "be1fa07132bd9efec772e8532a8bc54c82eb1cb6"
40
40
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  <script lang="ts">
4
4
  import { onMount, tick } from "svelte";
5
- import { getDevice, checkSession, platformFavorite } from 'rvhelper';
5
+ import { getDevice, checkSession } from 'rvhelper';
6
6
 
7
7
  import type { CategoriesData, CategoriesItems } from './CasinoCategoriesSlider.types';
8
8
  import '@everymatrix/casino-slider';
@@ -30,11 +30,7 @@
30
30
  let identity:string = 'CasinoSliderData'
31
31
 
32
32
  // Player logged-in/logged-out status & session
33
- let sessionID:string = '';
34
- let isLoggedIn:boolean = false;
35
- let playerID:string = '';
36
33
  let activeIndex:number = 0;
37
- let deviceSegregationValue:string = '';
38
34
 
39
35
  let isLoading:boolean = true;
40
36
  let error:string;
@@ -42,190 +38,33 @@
42
38
  let categories:Array<CategoriesItems> = [];
43
39
  let hasErrors:boolean = false;
44
40
  let userAgent = window.navigator.userAgent;
45
- let favoritesTitle:HTMLElement;
46
41
  let customStylingContainer:HTMLElement;
47
- let reworkedFavoriteGamesCollection:any = {
48
- items: []
49
- };
42
+
50
43
  let numberOfFavoredGames:number;
51
- let favoritesAdded:boolean = false;
52
- let mostPlayedAdded:boolean = false;
53
- let lastPlayedAdded:boolean = false;
54
- let favoritesLoaded:boolean = false;
55
- let mostPlayedLoaded:boolean = false;
56
- let lastPlayedLoaded:boolean = false;
57
- let categoriesLoaded:boolean = false;
44
+ let myGamesAdded:boolean = false;
58
45
  let isLoadingMostPlayed:boolean = false;
59
46
  let isLoadingLastPlayed:boolean = false;
60
47
  let confirmCategoryParse:boolean = false;
61
48
 
62
49
  $: numberOfFavoredGames = 0;
63
50
 
64
- const messageHandler = (e:any):void => {
65
- if (e.data) {
66
- switch(e.data.type) {
67
- case 'UpdateCategoryFavoriteGames':
68
- case 'ShowFavoriteSection':
69
- let platformSpecificFavoriteGames:any = {};
70
- platformSpecificFavoriteGames = platformFavorite(e.data.receivedFavoriteResults.items, numberOfFavoredGames);
71
- numberOfFavoredGames = platformSpecificFavoriteGames.length;
72
- break;
73
- }
74
- }
75
- }
76
-
77
- const getMostPlayedGames = ():Promise<boolean> => {
78
- if (mostplayed) {
79
- let url:URL = new URL(`${endpoint}/player/${userid}/games/most-played`);
80
-
81
- let device = getDevice(userAgent);
82
-
83
- if (device) {
84
- if (device === 'PC') {
85
- url.searchParams.append('device', 'Desktop');
86
- } else {
87
- url.searchParams.append('device', 'Mobile');
88
- }
89
- } else {
90
- url.searchParams.append('device', 'All');
91
- }
92
-
93
- url.searchParams.append('rounds', mostplayedrounds);
94
-
95
- return new Promise((resolve, reject) => {
96
- fetch(url.href)
97
- .then((res:any) => res.json())
98
- .then((data:any) => {
99
-
100
- data.items = data.items.filter((item):boolean => {
101
- let dataGameCode: boolean = true;
102
- if (item.gameCode == 'OddsMatrix2') {
103
- data.count--;
104
- dataGameCode = false;
105
- } return dataGameCode;
106
- });
107
-
108
- if (data.count == 0) {
109
- resolve(false);
110
- }
111
- resolve(true);
112
- }).catch((err:any) => {
113
- console.error('err', err);
114
- reject(false);
115
- });
116
- });
117
- }
118
- }
119
-
120
- const getLastPlayedGames = ():Promise<any> => {
121
- return new Promise((resolve, reject) => {
122
- if (lastplayed) {
123
- let url:URL = new URL(`${endpoint}/player/${userid}/games/last-played`);
124
-
125
- let device = getDevice(userAgent);
126
-
127
- if (device) {
128
- if (device === 'PC') {
129
- url.searchParams.append('device', 'Desktop');
130
- } else {
131
- url.searchParams.append('device', 'Mobile');
132
- }
133
- } else {
134
- url.searchParams.append('device', 'All');
135
- }
136
-
137
- url.searchParams.append('period', lastplayedperiod);
138
-
139
- fetch(url.href)
140
- .then((res:any) => res.json())
141
- .then((data:any) => {
142
-
143
- data.items = data.items.filter((item):boolean => {
144
- let dataGameCode: boolean = true;
145
- if (item.gameCode == 'OddsMatrix2') {
146
- data.count--;
147
- dataGameCode = false;
148
- } return dataGameCode;
149
- });
150
-
151
- if (data.count == 0) {
152
- resolve(false);
153
- }
154
- resolve(data);
155
- }).catch((err:any) => {
156
- console.error('err', err);
157
- reject(false);
158
- });
159
- }
160
- });
161
- }
162
51
 
163
- const addFavoritesCategory = ():void => {
164
- if (favoritesAdded == false && favorites == 'true') {
52
+ const addMyGamesCategory = ():void => {
53
+ if (myGamesAdded == false && (favorites == 'true' || mostplayed == 'true' || lastplayed == 'true') ) {
165
54
  categories.splice(1, 0, {
166
55
  // @ts-ignore
167
- id: 'FAVORITES',
168
- name: 'Favorites',
56
+ id: 'MYGAMES',
57
+ name: 'My Games',
169
58
  href: '',
170
59
  games: [],
171
60
  });
172
61
  }
173
62
 
174
- favoritesAdded = true;
175
- favoritesLoaded = true;
176
- };
177
-
178
- const addMostPlayedCategory = ():void => {
179
- if (mostplayed) {
180
- isLoadingMostPlayed = true;
181
-
182
- getMostPlayedGames().then((display:boolean) => {
183
- if (mostPlayedAdded == false && mostplayed == 'true' && display) {
184
- categories.splice(2, 0, {
185
- // @ts-ignore
186
- id: 'MOSTPLAYED',
187
- name: 'Most Played',
188
- href: '',
189
- games: [],
190
- triggerFetch: false
191
- });
192
- }
193
-
194
- isLoadingMostPlayed = false;
195
- tick();
196
-
197
- mostPlayedAdded = true;
198
- mostPlayedLoaded = true;
199
- });
200
- }
201
- confirmCategoryParse = true;
202
- }
203
-
204
- const addLastPlayedCategory = ():void => {
205
- if (lastplayed == 'true') {
206
- isLoadingLastPlayed = true;
207
-
208
- getLastPlayedGames().then((display:boolean) => {
209
- if (lastPlayedAdded == false && lastplayed == 'true' && display) {
210
- categories.splice(3, 0, {
211
- // @ts-ignore
212
- id: 'LASTPLAYED',
213
- name: 'Last Played',
214
- href: '',
215
- games: [],
216
- triggerFetch: false
217
- });
218
- }
219
-
220
- isLoadingLastPlayed = false;
221
- tick();
222
-
223
- lastPlayedAdded = true;
224
- lastPlayedLoaded = true;
225
- });
226
- }
63
+ tick();
64
+ myGamesAdded = true;
227
65
  confirmCategoryParse = true;
228
- }
66
+ sendSliderData();
67
+ };
229
68
 
230
69
  const checkAttrs = ():boolean => {
231
70
  if (!endpoint) {
@@ -254,30 +93,14 @@
254
93
 
255
94
  return hasErrors;
256
95
  }
257
- const setDevice = ():void => {
258
- let device = getDevice(userAgent)
259
-
260
- if(device){
261
- if(device === 'PC'){
262
- deviceSegregationValue = 'dk';
263
- } else if(device === 'iPad' || device === 'iPhone') {
264
- deviceSegregationValue = 'ios';
265
- } else {
266
- deviceSegregationValue = 'mtWeb';
267
- }
268
- }
269
-
270
- }
271
96
 
272
97
  const initialLoad = ():void => {
273
- setDevice();
274
-
275
98
  if (!checkAttrs()) {
276
99
  let url:any = new URL(`${endpoint}/casino/groups/${datasource}`);
277
100
 
278
101
  url.searchParams.append('datasource', datasource);
279
102
  url.searchParams.append('language', lang);
280
- url.searchParams.append('device', deviceSegregationValue);
103
+ url.searchParams.append('platform', getDevice(userAgent));
281
104
 
282
105
  fetch(url)
283
106
  .then((res:any) => res.json())
@@ -286,7 +109,7 @@
286
109
  let arrayFilteredCategories = filteredcategories.split(',');
287
110
  // filter type added to type
288
111
  let arr = data.items.filter((item:any) => {
289
- let filtered;
112
+ let filtered = false;
290
113
  if( item.games.total > 0) {
291
114
  filtered = true;
292
115
  //exclude filtered categories
@@ -330,21 +153,6 @@
330
153
  activeIndex = categories.map((item) => item.id).indexOf(decodeURI(activecategory));
331
154
  }
332
155
 
333
- const setSession = ():void => {
334
- if (sessioncheck == 'true') {
335
- checkSession(endpoint, session).then((res:any) => {
336
- sessionID = res.Guid;
337
- playerID = res.UserID;
338
- isLoggedIn = true;
339
- }, (err:any) => {
340
- isLoggedIn = false;
341
- console.error('err on session', err);
342
- });
343
- } else {
344
- sessionID = session;
345
- }
346
- }
347
-
348
156
  const setClientStyling = ():void => {
349
157
  let sheet = document.createElement('style');
350
158
  sheet.innerHTML = clientstyling;
@@ -365,26 +173,16 @@
365
173
  });
366
174
  }
367
175
 
368
- const sendSliderData = (sliderData:any):void => {
176
+ const sendSliderData = ():void => {
369
177
  window.postMessage({ type: 'SliderData', identity, data: categories }, window.location.href);
370
178
  }
371
-
372
- onMount(() => {
373
- window.addEventListener('message', messageHandler, false);
374
-
375
- return () => {
376
- window.removeEventListener('message', messageHandler);
377
- }
378
- });
379
-
179
+
380
180
  $: endpoint && datasource && lang && initialLoad();
381
- $: session && endpoint && setSession();
382
- $: session && favorites && !isLoading && addFavoritesCategory();
383
- $: session && endpoint && !isLoading && lastplayed && addLastPlayedCategory();
384
- $: session && endpoint && !isLoading && userid && mostplayed && addMostPlayedCategory();
181
+ $: endpoint && session && (mostplayed || lastplayed || favorites) && !isLoading && addMyGamesCategory();
385
182
  $: !isLoading && activecategory && (session ? confirmCategoryParse : true) && setActiveCategory();
386
183
  $: clientstyling && customStylingContainer && setClientStyling();
387
184
  $: clientstylingurl && customStylingContainer && setClientStylingURL();
185
+
388
186
  </script>
389
187
 
390
188
  <div bind:this={customStylingContainer} part="CustomStylingContainer">