@everymatrix/casino-tournaments-limited-controller 0.0.365 → 0.0.367

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,382 +1,382 @@
1
- <svelte:options tag={null} />
2
-
3
- <script lang="ts">
4
- import { onMount } from "svelte";
5
- import { formatDate } from './date'
6
- import icon from './icon'
7
-
8
- import {
9
- _fetch,
10
- matchStatusFromApiToView,
11
- } from "./util";
12
-
13
- import { setLocale, setLocaleWhenInit, _ } from './i18n'
14
-
15
- import {
16
- onMountMessageLifeCycle,
17
- updateEventSourceLifeCycle,
18
- composeEventSourceMessageHandler,
19
- postMessageTabLocaleTextUpdate,
20
- postMessageTabTotalUpdate,
21
- _postMessage,
22
- createEventSource,
23
- } from "./message";
24
-
25
- import '@everymatrix/casino-tournaments-tab'
26
-
27
- type State = 'Scheduled' | 'Ongoing' | 'Finished'
28
-
29
- export let endpoint: string = ''
30
- export let lang: string = 'en'
31
- export let session: string = ''
32
- export let state: State | undefined = undefined
33
- export let states: string = ''
34
- export let filter: string = ''
35
-
36
- let eventSource = undefined
37
- let svgSize: number = 0
38
- let href = icon
39
-
40
- type Tournament = {
41
- id: string
42
- nameOrTitle: string
43
- endTime: string
44
- state: string
45
- }
46
-
47
- type TournamentForRendering = {
48
- id: string,
49
- title: string,
50
- rank: string,
51
- enddate: string,
52
- prize: string,
53
- }
54
-
55
- type TournamentsMatrix = {
56
- [P in State]?: TournamentForRendering[]
57
- }
58
-
59
- let tournamentsMatrix: TournamentsMatrix = {}
60
-
61
- const eventSourceHandler = composeEventSourceMessageHandler({
62
- "PlayerLeaderBoardsUpdate": (data) => {
63
- let _tournamentsMatrix: TournamentsMatrix = {}
64
- __states.map(s => {
65
- if(!_tournamentsMatrix[s]){
66
- _tournamentsMatrix[s] = []
67
- }
68
- })
69
-
70
- data.items.map(_item => {
71
-
72
- const { id, nameOrTitle: title, endTime: enddate } = _item.tournament
73
-
74
- const tournamentComposed: TournamentForRendering = {
75
- id,
76
- title,
77
- rank: _item.leaderBoard && `#${_item.leaderBoard.rank}/${_item.endRank}`,
78
- enddate,
79
- prize: _item.leaderBoard && _item.leaderBoard.prizeName,
80
- }
81
-
82
- _tournamentsMatrix[matchStatusFromApiToView(_item.tournament.state)].push(tournamentComposed)
83
- })
84
-
85
- tournamentsMatrix = _tournamentsMatrix
86
-
87
- statesNeedSubscribe.map(s => {
88
- postMessageTabTotalUpdate(s, tournamentsMatrix[s].length)
89
- })
90
-
91
- },
92
- 'TournamentUpdate': (data) => {
93
- if(data.item){
94
- const tournament = data.item as Tournament
95
- let _state = matchStatusFromApiToView(tournament.state)
96
- tournamentsMatrix = {
97
- ...tournamentsMatrix,
98
- [_state]: tournamentsMatrix[_state].map(t => {
99
- if(t.id === tournament.id){
100
- return {
101
- ...t,
102
- title: tournament.nameOrTitle,
103
- enddate: tournament.endTime
104
- }
105
- }else{
106
- return t
107
- }
108
- })
109
- }
110
- }
111
- },
112
- })
113
-
114
- const subscribeApi = async (offset:number, limit:number) => {
115
-
116
- const source = `${endpoint}/tournaments`
117
- const url = new URL(source)
118
-
119
- url.searchParams.append('pagination', `offset=${offset},limit=${limit}`);
120
- url.searchParams.append('sortField', 'StartTime');
121
- url.searchParams.append('sortOrder', 'desc');
122
- url.searchParams.append('language', lang);
123
- url.searchParams.append('XSessionId', session);
124
-
125
-
126
- if(filter){
127
- url.searchParams.append('filter', filter);
128
- }
129
-
130
- eventSource = updateEventSourceLifeCycle(
131
- eventSource,
132
- createEventSource(`${source}/leaderboard/player/updates?${url.searchParams.toString()}`),
133
- eventSourceHandler
134
- )
135
- }
136
-
137
- // =============== define above, run below =============== \\
138
-
139
- setLocaleWhenInit()
140
-
141
- $: __state = state
142
- $: __states = states.split(',') as State[]
143
- $: statesNeedSubscribe = __states.filter(s => s !== 'Finished')
144
- $: list = tournamentsMatrix[__state]
145
-
146
- const init = () => {
147
- subscribeApi(0, 30)
148
-
149
- setLocale(lang)
150
-
151
- postMessageTabLocaleTextUpdate('Scheduled', $_('tournamentsLimitedController.Scheduled'))
152
- postMessageTabLocaleTextUpdate('Ongoing', $_('tournamentsLimitedController.Ongoing'))
153
- postMessageTabLocaleTextUpdate('Finished', `${$_(`tournamentsLimitedController.Finished`)} (${$_('tournamentsLimitedController.last')} 48h)`)
154
- }
155
-
156
- $: endpoint && filter && lang && session && init()
157
-
158
- onMount(() => {
159
- return () => {
160
- if(eventSource){
161
- eventSource.removeEventListener('message', eventSourceHandler);
162
- }
163
- }
164
- })
165
-
166
- onMountMessageLifeCycle({
167
- TournamentsTabSwitch: async (data) => __state = data.tab
168
- })
169
-
170
- </script>
171
-
172
- <div class="casino-tournaments-limited-controller">
173
-
174
- <div class="top-wrapper">
175
- <div class="svg" bind:clientWidth={svgSize}>
176
- <svg width={svgSize} height={svgSize} viewBox={`0 0 ${svgSize} ${svgSize}`} fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
177
- <rect width={svgSize} height={svgSize} fill="url(#pattern0)"/>
178
- <defs>
179
- <pattern id="pattern0" patternContentUnits="objectBoundingBox" width="1" height="1">
180
- <use xlink:href="#image0_2606_356" transform="scale(0.00195312)"/>
181
- </pattern>
182
- {#if href}
183
- <image
184
- id="image0_2606_356"
185
- width="512"
186
- height="512"
187
- xlink:href={href}
188
- />
189
- {/if}
190
- </defs>
191
- </svg>
192
- </div>
193
-
194
- <div class="text">
195
- {$_('tournamentsLimitedController.myTournaments')}
196
- </div>
197
-
198
- <div class="CloseButton" part="CloseButton"
199
- on:click='{
200
- ()=>window.postMessage({ type: 'OnCloseThumbnail' }, window.location.href)
201
- }'
202
- >X</div>
203
- </div>
204
-
205
- <section>
206
- <casino-tournaments-tab
207
- tabs={states}
208
- tab={state}
209
- />
210
-
211
- <div class='list header'>
212
- {#each [
213
- $_('tournamentsLimitedController.name'),
214
- $_('tournamentsLimitedController.rank'),
215
- $_('tournamentsLimitedController.enddate'),
216
- $_('tournamentsLimitedController.prize')
217
- ] as item}
218
- <div>{item}</div>
219
- {/each}
220
- </div>
221
-
222
- {#if list}
223
- {#each list as item, i}
224
-
225
- <div class='list'>
226
- {#if item}
227
- {#each Object.keys(item).filter(_key => _key !== 'id') as key, i}
228
-
229
- <div class={key}>
230
- {#if item[key]}
231
-
232
- {#if key === 'title'}
233
- <span on:click={() => {
234
- window.postMessage({
235
- type: 'MyTournamentFromNavClicked',
236
- tournamentId: item.id,
237
- showLeaderboard: true
238
- }, window.location.href)
239
- }}>
240
- {item.title}
241
- </span>
242
- {/if}
243
-
244
- {#if key === 'enddate'}
245
- {formatDate(item.enddate)}
246
- {/if}
247
- {/if}
248
-
249
- {#if key === 'rank'}
250
- <span class={item.prize ? "prize-active" : ''}>{item.rank || ' -'}</span>
251
- {/if}
252
-
253
- {#if key === 'prize'}
254
- <span class={item.prize ? "prize-active" : ''}>{item.prize || ' -'}</span>
255
- {/if}
256
- </div>
257
- {/each}
258
- {/if}
259
- </div>
260
- {/each}
261
- {/if}
262
- </section>
263
- </div>
264
-
265
- <style lang="scss">
266
- :host {
267
- font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
268
- }
269
-
270
- *,
271
- *::before,
272
- *::after {
273
- margin: 0;
274
- padding: 0;
275
- list-style: none;
276
- text-decoration: none;
277
- outline: none;
278
- box-sizing: border-box;
279
- }
280
-
281
- $vw_base: 320px;
282
- @function vw($px) {
283
- @return ($px / $vw_base) * 100vw;
284
- }
285
-
286
- .CloseButton {
287
- position: absolute;
288
- right: vw(5px);
289
- font-size: vw(11px);
290
- color: #FFFFFF;
291
- cursor: pointer
292
- }
293
-
294
- .casino-tournaments-limited-controller {
295
- background: #282828;
296
-
297
- .top-wrapper {
298
- padding: vw(6px);
299
- display: flex;
300
- background: #333333;
301
-
302
- .svg {
303
- & {
304
- width: vw(35px);
305
- height: vw(35px);
306
- }
307
- }
308
-
309
- .text {
310
- color: white;
311
- font-size: vw(16px);
312
- padding-left: vw(10px);
313
- font-weight: bold;
314
- line-height: vw(19px);
315
- padding-top: vw(7px);
316
- }
317
- }
318
-
319
- section {
320
- padding: 0 vw(12px);
321
-
322
- }
323
-
324
- .list {
325
-
326
- &.header {
327
- background: #1C1C1C;
328
- div {
329
- color: #F7F7F7;
330
- }
331
- }
332
-
333
- display: flex;
334
- align-items: center;
335
- font-size: vw(12px);
336
-
337
- @import url('https://rsms.me/inter/inter.css');
338
- div { font: initial; font-family: 'Inter', sans-serif; }
339
- @supports (font-variation-settings: normal) {
340
- div { font: initial; font-family: 'Inter var', sans-serif; }
341
- }
342
-
343
- div {
344
- display: flex;
345
- padding: vw(8px) vw(6.45px);
346
- // text-align: center;
347
- word-break: break-word;
348
- font-size: vw(12px) !important;
349
- color: #B5B5B5;
350
-
351
- &:nth-child(1) {
352
- flex: 0 0 25%;
353
- }
354
-
355
- &:nth-child(2) {
356
- flex: 0 0 25%;
357
- }
358
-
359
- &:nth-child(3) {
360
- flex: 0 0 25%;
361
- }
362
-
363
- &:nth-child(4) {
364
- flex: 0 0 25%;
365
- }
366
-
367
- &.title span {
368
- color: #FF8364;
369
- text-decoration-line: underline;
370
-
371
- &:active {
372
- opacity: 0.6;
373
- }
374
- }
375
-
376
- .prize-active {
377
- color: #FFD700;
378
- }
379
- }
380
- }
381
- }
382
- </style>
1
+ <svelte:options tag={null} />
2
+
3
+ <script lang="ts">
4
+ import { onMount } from "svelte";
5
+ import { formatDate } from './date'
6
+ import icon from './icon'
7
+
8
+ import {
9
+ _fetch,
10
+ matchStatusFromApiToView,
11
+ } from "./util";
12
+
13
+ import { setLocale, setLocaleWhenInit, _ } from './i18n'
14
+
15
+ import {
16
+ onMountMessageLifeCycle,
17
+ updateEventSourceLifeCycle,
18
+ composeEventSourceMessageHandler,
19
+ postMessageTabLocaleTextUpdate,
20
+ postMessageTabTotalUpdate,
21
+ _postMessage,
22
+ createEventSource,
23
+ } from "./message";
24
+
25
+ import '@everymatrix/casino-tournaments-tab'
26
+
27
+ type State = 'Scheduled' | 'Ongoing' | 'Finished'
28
+
29
+ export let endpoint: string = ''
30
+ export let lang: string = 'en'
31
+ export let session: string = ''
32
+ export let state: State | undefined = undefined
33
+ export let states: string = ''
34
+ export let filter: string = ''
35
+
36
+ let eventSource = undefined
37
+ let svgSize: number = 0
38
+ let href = icon
39
+
40
+ type Tournament = {
41
+ id: string
42
+ nameOrTitle: string
43
+ endTime: string
44
+ state: string
45
+ }
46
+
47
+ type TournamentForRendering = {
48
+ id: string,
49
+ title: string,
50
+ rank: string,
51
+ enddate: string,
52
+ prize: string,
53
+ }
54
+
55
+ type TournamentsMatrix = {
56
+ [P in State]?: TournamentForRendering[]
57
+ }
58
+
59
+ let tournamentsMatrix: TournamentsMatrix = {}
60
+
61
+ const eventSourceHandler = composeEventSourceMessageHandler({
62
+ "PlayerLeaderBoardsUpdate": (data) => {
63
+ let _tournamentsMatrix: TournamentsMatrix = {}
64
+ __states.map(s => {
65
+ if(!_tournamentsMatrix[s]){
66
+ _tournamentsMatrix[s] = []
67
+ }
68
+ })
69
+
70
+ data.items.map(_item => {
71
+
72
+ const { id, nameOrTitle: title, endTime: enddate } = _item.tournament
73
+
74
+ const tournamentComposed: TournamentForRendering = {
75
+ id,
76
+ title,
77
+ rank: _item.leaderBoard && `#${_item.leaderBoard.rank}/${_item.endRank}`,
78
+ enddate,
79
+ prize: _item.leaderBoard && _item.leaderBoard.prizeName,
80
+ }
81
+
82
+ _tournamentsMatrix[matchStatusFromApiToView(_item.tournament.state)].push(tournamentComposed)
83
+ })
84
+
85
+ tournamentsMatrix = _tournamentsMatrix
86
+
87
+ statesNeedSubscribe.map(s => {
88
+ postMessageTabTotalUpdate(s, tournamentsMatrix[s].length)
89
+ })
90
+
91
+ },
92
+ 'TournamentUpdate': (data) => {
93
+ if(data.item){
94
+ const tournament = data.item as Tournament
95
+ let _state = matchStatusFromApiToView(tournament.state)
96
+ tournamentsMatrix = {
97
+ ...tournamentsMatrix,
98
+ [_state]: tournamentsMatrix[_state].map(t => {
99
+ if(t.id === tournament.id){
100
+ return {
101
+ ...t,
102
+ title: tournament.nameOrTitle,
103
+ enddate: tournament.endTime
104
+ }
105
+ }else{
106
+ return t
107
+ }
108
+ })
109
+ }
110
+ }
111
+ },
112
+ })
113
+
114
+ const subscribeApi = async (offset:number, limit:number) => {
115
+
116
+ const source = `${endpoint}/tournaments`
117
+ const url = new URL(source)
118
+
119
+ url.searchParams.append('pagination', `offset=${offset},limit=${limit}`);
120
+ url.searchParams.append('sortField', 'StartTime');
121
+ url.searchParams.append('sortOrder', 'desc');
122
+ url.searchParams.append('language', lang);
123
+ url.searchParams.append('XSessionId', session);
124
+
125
+
126
+ if(filter){
127
+ url.searchParams.append('filter', filter);
128
+ }
129
+
130
+ eventSource = updateEventSourceLifeCycle(
131
+ eventSource,
132
+ createEventSource(`${source}/leaderboard/player/updates?${url.searchParams.toString()}`),
133
+ eventSourceHandler
134
+ )
135
+ }
136
+
137
+ // =============== define above, run below =============== \\
138
+
139
+ setLocaleWhenInit()
140
+
141
+ $: __state = state
142
+ $: __states = states.split(',') as State[]
143
+ $: statesNeedSubscribe = __states.filter(s => s !== 'Finished')
144
+ $: list = tournamentsMatrix[__state]
145
+
146
+ const init = () => {
147
+ subscribeApi(0, 30)
148
+
149
+ setLocale(lang)
150
+
151
+ postMessageTabLocaleTextUpdate('Scheduled', $_('tournamentsLimitedController.Scheduled'))
152
+ postMessageTabLocaleTextUpdate('Ongoing', $_('tournamentsLimitedController.Ongoing'))
153
+ postMessageTabLocaleTextUpdate('Finished', `${$_(`tournamentsLimitedController.Finished`)} (${$_('tournamentsLimitedController.last')} 48h)`)
154
+ }
155
+
156
+ $: endpoint && filter && lang && session && init()
157
+
158
+ onMount(() => {
159
+ return () => {
160
+ if(eventSource){
161
+ eventSource.removeEventListener('message', eventSourceHandler);
162
+ }
163
+ }
164
+ })
165
+
166
+ onMountMessageLifeCycle({
167
+ TournamentsTabSwitch: async (data) => __state = data.tab
168
+ })
169
+
170
+ </script>
171
+
172
+ <div class="casino-tournaments-limited-controller">
173
+
174
+ <div class="top-wrapper">
175
+ <div class="svg" bind:clientWidth={svgSize}>
176
+ <svg width={svgSize} height={svgSize} viewBox={`0 0 ${svgSize} ${svgSize}`} fill="none" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
177
+ <rect width={svgSize} height={svgSize} fill="url(#pattern0)"/>
178
+ <defs>
179
+ <pattern id="pattern0" patternContentUnits="objectBoundingBox" width="1" height="1">
180
+ <use xlink:href="#image0_2606_356" transform="scale(0.00195312)"/>
181
+ </pattern>
182
+ {#if href}
183
+ <image
184
+ id="image0_2606_356"
185
+ width="512"
186
+ height="512"
187
+ xlink:href={href}
188
+ />
189
+ {/if}
190
+ </defs>
191
+ </svg>
192
+ </div>
193
+
194
+ <div class="text">
195
+ {$_('tournamentsLimitedController.myTournaments')}
196
+ </div>
197
+
198
+ <div class="CloseButton" part="CloseButton"
199
+ on:click='{
200
+ ()=>window.postMessage({ type: 'OnCloseThumbnail' }, window.location.href)
201
+ }'
202
+ >X</div>
203
+ </div>
204
+
205
+ <section>
206
+ <casino-tournaments-tab
207
+ tabs={states}
208
+ tab={state}
209
+ />
210
+
211
+ <div class='list header'>
212
+ {#each [
213
+ $_('tournamentsLimitedController.name'),
214
+ $_('tournamentsLimitedController.rank'),
215
+ $_('tournamentsLimitedController.enddate'),
216
+ $_('tournamentsLimitedController.prize')
217
+ ] as item}
218
+ <div>{item}</div>
219
+ {/each}
220
+ </div>
221
+
222
+ {#if list}
223
+ {#each list as item, i}
224
+
225
+ <div class='list'>
226
+ {#if item}
227
+ {#each Object.keys(item).filter(_key => _key !== 'id') as key, i}
228
+
229
+ <div class={key}>
230
+ {#if item[key]}
231
+
232
+ {#if key === 'title'}
233
+ <span on:click={() => {
234
+ window.postMessage({
235
+ type: 'MyTournamentFromNavClicked',
236
+ tournamentId: item.id,
237
+ showLeaderboard: true
238
+ }, window.location.href)
239
+ }}>
240
+ {item.title}
241
+ </span>
242
+ {/if}
243
+
244
+ {#if key === 'enddate'}
245
+ {formatDate(item.enddate)}
246
+ {/if}
247
+ {/if}
248
+
249
+ {#if key === 'rank'}
250
+ <span class={item.prize ? "prize-active" : ''}>{item.rank || ' -'}</span>
251
+ {/if}
252
+
253
+ {#if key === 'prize'}
254
+ <span class={item.prize ? "prize-active" : ''}>{item.prize || ' -'}</span>
255
+ {/if}
256
+ </div>
257
+ {/each}
258
+ {/if}
259
+ </div>
260
+ {/each}
261
+ {/if}
262
+ </section>
263
+ </div>
264
+
265
+ <style lang="scss">
266
+ :host {
267
+ font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
268
+ }
269
+
270
+ *,
271
+ *::before,
272
+ *::after {
273
+ margin: 0;
274
+ padding: 0;
275
+ list-style: none;
276
+ text-decoration: none;
277
+ outline: none;
278
+ box-sizing: border-box;
279
+ }
280
+
281
+ $vw_base: 320px;
282
+ @function vw($px) {
283
+ @return ($px / $vw_base) * 100vw;
284
+ }
285
+
286
+ .CloseButton {
287
+ position: absolute;
288
+ right: vw(5px);
289
+ font-size: vw(11px);
290
+ color: #FFFFFF;
291
+ cursor: pointer
292
+ }
293
+
294
+ .casino-tournaments-limited-controller {
295
+ background: #282828;
296
+
297
+ .top-wrapper {
298
+ padding: vw(6px);
299
+ display: flex;
300
+ background: #333333;
301
+
302
+ .svg {
303
+ & {
304
+ width: vw(35px);
305
+ height: vw(35px);
306
+ }
307
+ }
308
+
309
+ .text {
310
+ color: white;
311
+ font-size: vw(16px);
312
+ padding-left: vw(10px);
313
+ font-weight: bold;
314
+ line-height: vw(19px);
315
+ padding-top: vw(7px);
316
+ }
317
+ }
318
+
319
+ section {
320
+ padding: 0 vw(12px);
321
+
322
+ }
323
+
324
+ .list {
325
+
326
+ &.header {
327
+ background: #1C1C1C;
328
+ div {
329
+ color: #F7F7F7;
330
+ }
331
+ }
332
+
333
+ display: flex;
334
+ align-items: center;
335
+ font-size: vw(12px);
336
+
337
+ @import url('https://rsms.me/inter/inter.css');
338
+ div { font: initial; font-family: 'Inter', sans-serif; }
339
+ @supports (font-variation-settings: normal) {
340
+ div { font: initial; font-family: 'Inter var', sans-serif; }
341
+ }
342
+
343
+ div {
344
+ display: flex;
345
+ padding: vw(8px) vw(6.45px);
346
+ // text-align: center;
347
+ word-break: break-word;
348
+ font-size: vw(12px) !important;
349
+ color: #B5B5B5;
350
+
351
+ &:nth-child(1) {
352
+ flex: 0 0 25%;
353
+ }
354
+
355
+ &:nth-child(2) {
356
+ flex: 0 0 25%;
357
+ }
358
+
359
+ &:nth-child(3) {
360
+ flex: 0 0 25%;
361
+ }
362
+
363
+ &:nth-child(4) {
364
+ flex: 0 0 25%;
365
+ }
366
+
367
+ &.title span {
368
+ color: #FF8364;
369
+ text-decoration-line: underline;
370
+
371
+ &:active {
372
+ opacity: 0.6;
373
+ }
374
+ }
375
+
376
+ .prize-active {
377
+ color: #FFD700;
378
+ }
379
+ }
380
+ }
381
+ }
382
+ </style>