@everymatrix/casino-categories-slider 0.0.367 → 0.0.369

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.
@@ -1,309 +1,309 @@
1
- <svelte:options tag={null} />
2
-
3
- <script lang="ts">
4
- import { onMount, tick } from "svelte";
5
- import { getDevice, checkSession, platformFavorite } from 'rvhelper';
6
-
7
- import type { CategoriesData, CategoriesItems } from './CasinoCategoriesSlider.types';
8
-
9
- import '@everymatrix/casino-slider';
10
-
11
- export let endpoint:string = '';
12
- export let datasource:string = '';
13
- export let lang:string = ''; // Language
14
- export let userid:string = '';
15
- export let session:string = ''; // Value for sessionID
16
- export let mostplayed:string = ''; // True - add MostPlayed category in slider
17
- export let mostplayedrounds:string = '';
18
- export let favorites:string = ''; // True - add Favorites category in slider
19
- export let clientstyling:string = '';
20
- export let clientstylingurl:string = '';
21
- export let containermaxwidth:string = '';
22
- export let activecategory:string = '';
23
- export let actionevent:string = '';
24
- export let sessioncheck:string = '';
25
- export let showsubgroups:string = '';
26
-
27
- export let subgroups: string= '';
28
-
29
- let identity:string = 'CasinoSliderData'
30
-
31
- // Player logged-in/logged-out status & session
32
- let sessionID:string = '';
33
- let isLoggedIn:boolean = false;
34
- let playerID:string = '';
35
- let activeIndex:number = 0;
36
-
37
- let isLoading:boolean = true;
38
- let error:string;
39
-
40
- let categories:Array<CategoriesItems> = [];
41
- let hasErrors:boolean = false;
42
- let userAgent = window.navigator.userAgent;
43
- let favoritesTitle:HTMLElement;
44
- let customStylingContainer:HTMLElement;
45
- let reworkedFavoriteGamesCollection:any = {
46
- items: []
47
- };
48
- let numberOfFavoredGames:number;
49
- let favoritesAdded:boolean = false;
50
- let mostPlayedAdded:boolean = false;
51
- let favoritesLoaded:boolean = false;
52
- let mostPlayedLoaded:boolean = false;
53
- let categoriesLoaded:boolean = false;
54
- let isLoadingMostPlayed:boolean = false;
55
-
56
- $: numberOfFavoredGames = 0;
57
-
58
- const messageHandler = (e:any):void => {
59
- if (e.data) {
60
- switch(e.data.type) {
61
- case 'UpdateCategoryFavoriteGames':
62
- case 'ShowFavoriteSection':
63
- let platformSpecificFavoriteGames:any = {};
64
- platformSpecificFavoriteGames = platformFavorite(e.data.receivedFavoriteResults.items, numberOfFavoredGames);
65
- numberOfFavoredGames = platformSpecificFavoriteGames.length;
66
- break;
67
- }
68
- }
69
- }
70
-
71
- const getMostPlayedGames = ():Promise<boolean> => {
72
- if (mostplayed) {
73
- let url:URL = new URL(`${endpoint}/player/${userid}/games/most-played`);
74
-
75
- let device = getDevice(userAgent);
76
-
77
- if (device) {
78
- if (device === 'PC') {
79
- url.searchParams.append('device', 'Desktop');
80
- } else {
81
- url.searchParams.append('device', 'Mobile');
82
- }
83
- } else {
84
- url.searchParams.append('device', 'All');
85
- }
86
-
87
- url.searchParams.append('rounds', mostplayedrounds);
88
-
89
- return new Promise((resolve, reject) => {
90
- fetch(url.href)
91
- .then((res:any) => res.json())
92
- .then((data:any) => {
93
- if (data.count == 0) {
94
- resolve(false);
95
- }
96
- resolve(true);
97
- }).catch((err:any) => {
98
- console.error('err', err);
99
- reject(false);
100
- });
101
- });
102
- }
103
- }
104
-
105
- const addFavoritesCategory = ():void => {
106
- if (favoritesAdded == false && favorites == 'true') {
107
- categories.splice(1, 0, {
108
- // @ts-ignore
109
- id: 'FAVORITES',
110
- name: 'Favorites',
111
- href: '',
112
- games: [],
113
- });
114
- }
115
-
116
- favoritesAdded = true;
117
- favoritesLoaded = true;
118
- };
119
-
120
- const addMostPlayedCategory = ():void => {
121
- if (mostplayed) {
122
- isLoadingMostPlayed = true;
123
-
124
- getMostPlayedGames().then((display:boolean) => {
125
- if (mostPlayedAdded == false && mostplayed == 'true' && display) {
126
- categories.splice(2, 0, {
127
- // @ts-ignore
128
- id: 'MOSTPLAYED',
129
- name: 'Most Played',
130
- href: '',
131
- games: [],
132
- triggerFetch: false
133
- });
134
- }
135
-
136
- isLoadingMostPlayed = false;
137
- tick();
138
-
139
- mostPlayedAdded = true;
140
- mostPlayedLoaded = true;
141
- });
142
- }
143
- }
144
-
145
- const checkAttrs = ():boolean => {
146
- if (!endpoint) {
147
- error = "Endpoint is missing! Please provide a valid endpointURL.";
148
- hasErrors = true;
149
- isLoading = false;
150
-
151
- console.error(error);
152
- }
153
-
154
- if (!datasource) {
155
- error = "Datasource is missing! Please provide a valid datasource.";
156
- hasErrors = true;
157
- isLoading = false;
158
-
159
- console.error(error);
160
- }
161
-
162
- if (!lang || lang.length < 2) {
163
- error = "Language is missing! Please provide a valid language (alpha2code)";
164
- hasErrors = true;
165
- isLoading = false;
166
-
167
- console.error(error);
168
- }
169
-
170
- return hasErrors;
171
- }
172
-
173
- const checkIfLoaded = ():void => {
174
- isLoading = !favoritesLoaded && !mostPlayedLoaded && !categoriesLoaded;
175
- }
176
-
177
- const initialLoad = ():void => {
178
- if (!checkAttrs()) {
179
- let url:any = new URL(`${endpoint}/casino/groups/${datasource}`);
180
-
181
- url.searchParams.append('datasource', datasource);
182
- url.searchParams.append('platform', getDevice(userAgent));
183
- url.searchParams.append('language', lang);
184
-
185
- fetch(url)
186
- .then((res:any) => res.json())
187
- .then((data:CategoriesData) => {
188
- // filter type added to type
189
- let arr = data.items.filter((item:any) => {
190
- return item.games.total > 0;
191
- });
192
-
193
- categories = [];
194
- categories = categories.concat(arr);
195
-
196
- // @TODO Translation for lobby
197
- categories.unshift({
198
- // @ts-ignore
199
- id: 'LOBBY',
200
- name: 'Lobby',
201
- href: '',
202
- games: [],
203
- });
204
-
205
- isLoading = false;
206
-
207
- window.postMessage({ type: 'CategoriesLoadedForSlider' }, window.location.href);
208
- }, (err:any) => {
209
- hasErrors = true;
210
- console.error('There was an error while fetching the categories', err);
211
- }).catch((err:any) => {
212
- hasErrors = true;
213
- console.error('There was an error while fetching the categories', err);
214
- });
215
- }
216
- }
217
-
218
- const setActiveCategory = ():void => {
219
- activeIndex = categories.map((item) => item.id).indexOf(activecategory);
220
- }
221
-
222
- const setSession = ():void => {
223
- if (sessioncheck == 'true') {
224
- checkSession(endpoint, session).then((res:any) => {
225
- sessionID = res.Guid;
226
- playerID = res.UserID;
227
- isLoggedIn = true;
228
- }, (err:any) => {
229
- isLoggedIn = false;
230
- console.error('err on session', err);
231
- });
232
- } else {
233
- sessionID = session;
234
- }
235
- }
236
-
237
- const setClientStyling = ():void => {
238
- let sheet = document.createElement('style');
239
- sheet.innerHTML = clientstyling;
240
- customStylingContainer.appendChild(sheet);
241
- }
242
-
243
- const setClientStylingURL = ():void => {
244
- let cssFile:HTMLElement = document.createElement('style');
245
-
246
- let url = new URL(clientstylingurl);
247
-
248
- fetch(url.href)
249
- .then((res:any) => res.text())
250
- .then((data:any) => {
251
- cssFile.innerHTML = data
252
-
253
- setTimeout(() => { customStylingContainer.appendChild(cssFile); }, 1);
254
- });
255
- }
256
-
257
- const sendSliderData = (sliderData:any):void => {
258
- window.postMessage({ type: 'SliderData', identity, data: categories }, window.location.href);
259
- }
260
-
261
- onMount(() => {
262
- window.addEventListener('message', messageHandler, false);
263
-
264
- return () => {
265
- window.removeEventListener('message', messageHandler);
266
- }
267
- });
268
-
269
- $: endpoint && datasource && lang && initialLoad();
270
- $: !isLoading && activecategory && setActiveCategory();
271
- $: session && endpoint && setSession();
272
- $: session && favorites && !isLoading && addFavoritesCategory();
273
- $: session && endpoint && userid && mostplayed && addMostPlayedCategory();
274
- $: clientstyling && setClientStyling();
275
- $: clientstylingurl && setClientStylingURL();
276
- </script>
277
-
278
- <div bind:this={customStylingContainer} part="CustomStylingContainer">
279
- {#if isLoading || isLoadingMostPlayed}
280
- <div class="CasinoCategoriesLoading" part="CasinoCategoriesLoading"></div>
281
- {:else}
282
- {#if hasErrors}
283
- <p class="SearchLoading" part="SearchLoading">500 Error - Internal Server Error.</p>
284
- {:else}
285
- <div class="CasinoCategoriesContainer" part="CasinoCategoriesContainer">
286
- <casino-slider {identity} favoritesnumber={numberOfFavoredGames} use:sendSliderData {showsubgroups} {clientstyling} {clientstylingurl} {containermaxwidth} activeindex={activeIndex} {actionevent} />
287
- </div>
288
- {/if}
289
- {/if}
290
- </div>
291
-
292
- <style>
293
- :host {
294
- font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
295
- }
296
-
297
- .CasinoCategoriesLoading {
298
- height: 52px;
299
- }
300
-
301
- p {
302
- color: var(--emfe-w-color-white, #FFFFFF);
303
- text-align: center;
304
- }
305
-
306
- .CasinoCategoriesContainer {
307
- background: var(--emfe-w-color-black, #000000);
308
- }
309
- </style>
1
+ <svelte:options tag={null} />
2
+
3
+ <script lang="ts">
4
+ import { onMount, tick } from "svelte";
5
+ import { getDevice, checkSession, platformFavorite } from 'rvhelper';
6
+
7
+ import type { CategoriesData, CategoriesItems } from './CasinoCategoriesSlider.types';
8
+
9
+ import '@everymatrix/casino-slider';
10
+
11
+ export let endpoint:string = '';
12
+ export let datasource:string = '';
13
+ export let lang:string = ''; // Language
14
+ export let userid:string = '';
15
+ export let session:string = ''; // Value for sessionID
16
+ export let mostplayed:string = ''; // True - add MostPlayed category in slider
17
+ export let mostplayedrounds:string = '';
18
+ export let favorites:string = ''; // True - add Favorites category in slider
19
+ export let clientstyling:string = '';
20
+ export let clientstylingurl:string = '';
21
+ export let containermaxwidth:string = '';
22
+ export let activecategory:string = '';
23
+ export let actionevent:string = '';
24
+ export let sessioncheck:string = '';
25
+ export let showsubgroups:string = '';
26
+
27
+ export let subgroups: string= '';
28
+
29
+ let identity:string = 'CasinoSliderData'
30
+
31
+ // Player logged-in/logged-out status & session
32
+ let sessionID:string = '';
33
+ let isLoggedIn:boolean = false;
34
+ let playerID:string = '';
35
+ let activeIndex:number = 0;
36
+
37
+ let isLoading:boolean = true;
38
+ let error:string;
39
+
40
+ let categories:Array<CategoriesItems> = [];
41
+ let hasErrors:boolean = false;
42
+ let userAgent = window.navigator.userAgent;
43
+ let favoritesTitle:HTMLElement;
44
+ let customStylingContainer:HTMLElement;
45
+ let reworkedFavoriteGamesCollection:any = {
46
+ items: []
47
+ };
48
+ let numberOfFavoredGames:number;
49
+ let favoritesAdded:boolean = false;
50
+ let mostPlayedAdded:boolean = false;
51
+ let favoritesLoaded:boolean = false;
52
+ let mostPlayedLoaded:boolean = false;
53
+ let categoriesLoaded:boolean = false;
54
+ let isLoadingMostPlayed:boolean = false;
55
+
56
+ $: numberOfFavoredGames = 0;
57
+
58
+ const messageHandler = (e:any):void => {
59
+ if (e.data) {
60
+ switch(e.data.type) {
61
+ case 'UpdateCategoryFavoriteGames':
62
+ case 'ShowFavoriteSection':
63
+ let platformSpecificFavoriteGames:any = {};
64
+ platformSpecificFavoriteGames = platformFavorite(e.data.receivedFavoriteResults.items, numberOfFavoredGames);
65
+ numberOfFavoredGames = platformSpecificFavoriteGames.length;
66
+ break;
67
+ }
68
+ }
69
+ }
70
+
71
+ const getMostPlayedGames = ():Promise<boolean> => {
72
+ if (mostplayed) {
73
+ let url:URL = new URL(`${endpoint}/player/${userid}/games/most-played`);
74
+
75
+ let device = getDevice(userAgent);
76
+
77
+ if (device) {
78
+ if (device === 'PC') {
79
+ url.searchParams.append('device', 'Desktop');
80
+ } else {
81
+ url.searchParams.append('device', 'Mobile');
82
+ }
83
+ } else {
84
+ url.searchParams.append('device', 'All');
85
+ }
86
+
87
+ url.searchParams.append('rounds', mostplayedrounds);
88
+
89
+ return new Promise((resolve, reject) => {
90
+ fetch(url.href)
91
+ .then((res:any) => res.json())
92
+ .then((data:any) => {
93
+ if (data.count == 0) {
94
+ resolve(false);
95
+ }
96
+ resolve(true);
97
+ }).catch((err:any) => {
98
+ console.error('err', err);
99
+ reject(false);
100
+ });
101
+ });
102
+ }
103
+ }
104
+
105
+ const addFavoritesCategory = ():void => {
106
+ if (favoritesAdded == false && favorites == 'true') {
107
+ categories.splice(1, 0, {
108
+ // @ts-ignore
109
+ id: 'FAVORITES',
110
+ name: 'Favorites',
111
+ href: '',
112
+ games: [],
113
+ });
114
+ }
115
+
116
+ favoritesAdded = true;
117
+ favoritesLoaded = true;
118
+ };
119
+
120
+ const addMostPlayedCategory = ():void => {
121
+ if (mostplayed) {
122
+ isLoadingMostPlayed = true;
123
+
124
+ getMostPlayedGames().then((display:boolean) => {
125
+ if (mostPlayedAdded == false && mostplayed == 'true' && display) {
126
+ categories.splice(2, 0, {
127
+ // @ts-ignore
128
+ id: 'MOSTPLAYED',
129
+ name: 'Most Played',
130
+ href: '',
131
+ games: [],
132
+ triggerFetch: false
133
+ });
134
+ }
135
+
136
+ isLoadingMostPlayed = false;
137
+ tick();
138
+
139
+ mostPlayedAdded = true;
140
+ mostPlayedLoaded = true;
141
+ });
142
+ }
143
+ }
144
+
145
+ const checkAttrs = ():boolean => {
146
+ if (!endpoint) {
147
+ error = "Endpoint is missing! Please provide a valid endpointURL.";
148
+ hasErrors = true;
149
+ isLoading = false;
150
+
151
+ console.error(error);
152
+ }
153
+
154
+ if (!datasource) {
155
+ error = "Datasource is missing! Please provide a valid datasource.";
156
+ hasErrors = true;
157
+ isLoading = false;
158
+
159
+ console.error(error);
160
+ }
161
+
162
+ if (!lang || lang.length < 2) {
163
+ error = "Language is missing! Please provide a valid language (alpha2code)";
164
+ hasErrors = true;
165
+ isLoading = false;
166
+
167
+ console.error(error);
168
+ }
169
+
170
+ return hasErrors;
171
+ }
172
+
173
+ const checkIfLoaded = ():void => {
174
+ isLoading = !favoritesLoaded && !mostPlayedLoaded && !categoriesLoaded;
175
+ }
176
+
177
+ const initialLoad = ():void => {
178
+ if (!checkAttrs()) {
179
+ let url:any = new URL(`${endpoint}/casino/groups/${datasource}`);
180
+
181
+ url.searchParams.append('datasource', datasource);
182
+ url.searchParams.append('platform', getDevice(userAgent));
183
+ url.searchParams.append('language', lang);
184
+
185
+ fetch(url)
186
+ .then((res:any) => res.json())
187
+ .then((data:CategoriesData) => {
188
+ // filter type added to type
189
+ let arr = data.items.filter((item:any) => {
190
+ return item.games.total > 0;
191
+ });
192
+
193
+ categories = [];
194
+ categories = categories.concat(arr);
195
+
196
+ // @TODO Translation for lobby
197
+ categories.unshift({
198
+ // @ts-ignore
199
+ id: 'LOBBY',
200
+ name: 'Lobby',
201
+ href: '',
202
+ games: [],
203
+ });
204
+
205
+ isLoading = false;
206
+
207
+ window.postMessage({ type: 'CategoriesLoadedForSlider' }, window.location.href);
208
+ }, (err:any) => {
209
+ hasErrors = true;
210
+ console.error('There was an error while fetching the categories', err);
211
+ }).catch((err:any) => {
212
+ hasErrors = true;
213
+ console.error('There was an error while fetching the categories', err);
214
+ });
215
+ }
216
+ }
217
+
218
+ const setActiveCategory = ():void => {
219
+ activeIndex = categories.map((item) => item.id).indexOf(activecategory);
220
+ }
221
+
222
+ const setSession = ():void => {
223
+ if (sessioncheck == 'true') {
224
+ checkSession(endpoint, session).then((res:any) => {
225
+ sessionID = res.Guid;
226
+ playerID = res.UserID;
227
+ isLoggedIn = true;
228
+ }, (err:any) => {
229
+ isLoggedIn = false;
230
+ console.error('err on session', err);
231
+ });
232
+ } else {
233
+ sessionID = session;
234
+ }
235
+ }
236
+
237
+ const setClientStyling = ():void => {
238
+ let sheet = document.createElement('style');
239
+ sheet.innerHTML = clientstyling;
240
+ customStylingContainer.appendChild(sheet);
241
+ }
242
+
243
+ const setClientStylingURL = ():void => {
244
+ let cssFile:HTMLElement = document.createElement('style');
245
+
246
+ let url = new URL(clientstylingurl);
247
+
248
+ fetch(url.href)
249
+ .then((res:any) => res.text())
250
+ .then((data:any) => {
251
+ cssFile.innerHTML = data
252
+
253
+ setTimeout(() => { customStylingContainer.appendChild(cssFile); }, 1);
254
+ });
255
+ }
256
+
257
+ const sendSliderData = (sliderData:any):void => {
258
+ window.postMessage({ type: 'SliderData', identity, data: categories }, window.location.href);
259
+ }
260
+
261
+ onMount(() => {
262
+ window.addEventListener('message', messageHandler, false);
263
+
264
+ return () => {
265
+ window.removeEventListener('message', messageHandler);
266
+ }
267
+ });
268
+
269
+ $: endpoint && datasource && lang && initialLoad();
270
+ $: !isLoading && activecategory && setActiveCategory();
271
+ $: session && endpoint && setSession();
272
+ $: session && favorites && !isLoading && addFavoritesCategory();
273
+ $: session && endpoint && userid && mostplayed && addMostPlayedCategory();
274
+ $: clientstyling && setClientStyling();
275
+ $: clientstylingurl && setClientStylingURL();
276
+ </script>
277
+
278
+ <div bind:this={customStylingContainer} part="CustomStylingContainer">
279
+ {#if isLoading || isLoadingMostPlayed}
280
+ <div class="CasinoCategoriesLoading" part="CasinoCategoriesLoading"></div>
281
+ {:else}
282
+ {#if hasErrors}
283
+ <p class="SearchLoading" part="SearchLoading">500 Error - Internal Server Error.</p>
284
+ {:else}
285
+ <div class="CasinoCategoriesContainer" part="CasinoCategoriesContainer">
286
+ <casino-slider {identity} favoritesnumber={numberOfFavoredGames} use:sendSliderData {showsubgroups} {clientstyling} {clientstylingurl} {containermaxwidth} activeindex={activeIndex} {actionevent} />
287
+ </div>
288
+ {/if}
289
+ {/if}
290
+ </div>
291
+
292
+ <style>
293
+ :host {
294
+ font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
295
+ }
296
+
297
+ .CasinoCategoriesLoading {
298
+ height: 52px;
299
+ }
300
+
301
+ p {
302
+ color: var(--emfe-w-color-white, #FFFFFF);
303
+ text-align: center;
304
+ }
305
+
306
+ .CasinoCategoriesContainer {
307
+ background: var(--emfe-w-color-black, #000000);
308
+ }
309
+ </style>