@jetthai/cuora 1.0.192 → 1.0.193-2

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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.193-2](https://github.com/jetthai/cuora-module/compare/v1.0.193-1...v1.0.193-2) (2022-11-02)
6
+
7
+ ### [1.0.193-1](https://github.com/jetthai/cuora-module/compare/v1.0.193...v1.0.193-1) (2022-11-01)
8
+
9
+ ### [1.0.193](https://github.com/jetthai/cuora-module/compare/v1.0.192...v1.0.193) (2022-10-26)
10
+
5
11
  ### [1.0.192](https://github.com/jetthai/cuora-module/compare/v1.0.191...v1.0.192) (2022-10-26)
6
12
 
7
13
  ### [1.0.191](https://github.com/jetthai/cuora-module/compare/v1.0.184-3...v1.0.191) (2022-10-26)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.192",
3
+ "version": "1.0.193-2",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
package/src/api/game.js CHANGED
@@ -10,12 +10,13 @@ export default {
10
10
  logoutGame: ({ uid_site, provider_id }) => ({ url: 'game/logout', method: 'get', params: { uid_site, provider_id } }),
11
11
 
12
12
  getGameTags: ({ q }) => ({ url: 'game/search', method: 'get', params: { q } }),
13
+ getGameSearchHome: () => ({ url: 'game/search/home', method: 'get' }),
13
14
  getGameSearchList: ({ id, index, q, click, clickDefault }) => ({
14
15
  url: 'game/search/list',
15
16
  method: 'get',
16
17
  params: { id, index, q, click, clickDefault },
17
18
  }),
18
- setGameSearchTrace: ({ traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault }) => ({
19
+ setGameSearchTrace: ({ traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch }) => ({
19
20
  url: 'game/search/trace',
20
21
  method: 'post',
21
22
  params: {
@@ -27,6 +28,9 @@ export default {
27
28
  query,
28
29
  click,
29
30
  clickDefault,
31
+ isYouMayLike,
32
+ isRecentlyGame,
33
+ isRecentlySearch
30
34
  },
31
35
  }),
32
36
  gameHistory: ({ requestTimestamp, lang, provider, type }) => ({
@@ -20,7 +20,7 @@ export default function (request) {
20
20
  src: 'fetchActivityList',
21
21
  onDone: {
22
22
  target: 'pending',
23
- actions: ['setActivityList', 'setTournamentList'],
23
+ actions: ['setActivityList', 'setActivityUnread', 'setTournamentList'],
24
24
  },
25
25
  onError: {
26
26
  target: 'pending',
@@ -45,10 +45,31 @@ export default function (request) {
45
45
  }
46
46
  }),
47
47
  setActivityList: assign((context, event) => {
48
+ const noRedActivity = [2, 4, 13, 20, 91, 92]
49
+ let list = event.data
50
+ list.forEach(activity => {
51
+ if (noRedActivity.includes(activity.activityType)) {
52
+ activity.unread = false
53
+ } else {
54
+ activity.unread = true
55
+ }
56
+ })
48
57
  return {
49
- activityList: event.data,
58
+ activityList: list,
50
59
  }
51
60
  }),
61
+ setActivityUnread: assign((context, event) => {
62
+ const { activityList = [] } = context
63
+ activityList.forEach(item => {
64
+ const storageUnread = localStorage.getItem(`activity_${item.activityNo}`)
65
+ if (storageUnread) {
66
+ item.unread = JSON.parse(storageUnread)
67
+ }
68
+ })
69
+ return {
70
+ activityList
71
+ }
72
+ })
52
73
  },
53
74
  delays: {
54
75
  TIMEOUT: (context, event) => {
@@ -81,7 +81,6 @@ export default function (request) {
81
81
  {
82
82
  actions: {
83
83
  setActivityNo: assign((context, event) => {
84
- console.log('Event:', event.data)
85
84
  return {
86
85
  activityNo: event.data,
87
86
  }
@@ -0,0 +1,353 @@
1
+ import { createMachine, assign, send } from 'xstate'
2
+ import game from '../api/game.js'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'game_search_v2',
8
+ initial: 'preset',
9
+ context: {
10
+ keyword: '',
11
+ tagId: null,
12
+ mainTagList: [],
13
+ tagList: [],
14
+ gameList: [],
15
+ recentlySearch: [],
16
+ recentlyGame: [],
17
+ youMayLike: [],
18
+ // 以下變數為數據分析用
19
+ selectedType: null,
20
+ tagIndex: null,
21
+ click: null,
22
+ clickDefault: null,
23
+ traceId: null,
24
+ isYouMayLike: null,
25
+ isRecentlyGame: null,
26
+ isRecentlySearch: null,
27
+ gameCode: null,
28
+ },
29
+ states: {
30
+ preset: {
31
+ invoke: {
32
+ src: 'fetchTags',
33
+ onDone: {
34
+ target: 'loading',
35
+ actions: 'setMainTagList',
36
+ },
37
+ onError: {
38
+ target: 'fail',
39
+ },
40
+ },
41
+ },
42
+ loading: {
43
+ invoke: {
44
+ src: 'fetchInitialData',
45
+ onDone: {
46
+ target: 'idle',
47
+ actions: 'setInitialData',
48
+ },
49
+ onError: {
50
+ target: '#game_search_v2.fail',
51
+ },
52
+ },
53
+ },
54
+ idle: {
55
+ on: {
56
+ SET_MAIN_TAG_ID: {
57
+ target: 'setGameList',
58
+ actions: ['setMainTagId', 'setTraceData']
59
+ },
60
+ PLAY_GAME: {
61
+ target: 'sendingTrace',
62
+ actions: 'setGameCode',
63
+ },
64
+ START_SEARCH: {
65
+ target: 'searching',
66
+ actions: 'clearKeyword',
67
+ },
68
+ CLEAR_MAIN_TAG: {
69
+ actions: 'clearMainTag',
70
+ }
71
+ },
72
+ },
73
+ setGameList: {
74
+ always: [
75
+ {
76
+ target: 'idle',
77
+ actions: 'setGames',
78
+ cond: 'isRecentlyYouMayLike'
79
+ },
80
+ {
81
+ target: 'fetchGameList',
82
+ }
83
+ ]
84
+ },
85
+ fetchGameList: {
86
+ invoke: {
87
+ src: 'fetchGames',
88
+ onDone: {
89
+ target: 'idle',
90
+ actions: 'setGames',
91
+ },
92
+ onError: {
93
+ target: '#game_search_v2.fail',
94
+ },
95
+ },
96
+ },
97
+ searching: {
98
+ initial: 'searchIdle',
99
+ states: {
100
+ searchIdle: {
101
+ on: {
102
+ SET_TAG_ID: {
103
+ target: '#game_search_v2.fetchGameList',
104
+ actions: ['setTagId', 'setTraceData']
105
+ },
106
+ PRESS_ENTER: [
107
+ {
108
+ actions: send((context, event) => ({
109
+ type: 'SET_TAG_ID',
110
+ data: {
111
+ tagId: context.tagList[0]?.id,
112
+ traceData: {
113
+ isYouMayLike: null,
114
+ isRecentlyGame: null,
115
+ isRecentlySearch: null
116
+ }
117
+ }
118
+ })),
119
+ cond: 'hasTagList',
120
+ },
121
+ {
122
+ target: '#game_search_v2.sendingTrace',
123
+ actions: 'clearExceptKeyword',
124
+ },
125
+ ],
126
+ SET_KEYWORD: {
127
+ target: 'debouncing',
128
+ actions: 'setKeyword',
129
+ },
130
+ STOP_SEARCH: {
131
+ target: '#game_search_v2.idle',
132
+ actions: 'clearKeywords'
133
+ },
134
+ },
135
+ },
136
+ debouncing: {
137
+ on: {
138
+ SET_KEYWORD: {
139
+ target: 'debouncing',
140
+ actions: 'setKeyword',
141
+ },
142
+ },
143
+ after: {
144
+ 500: {
145
+ target: 'fetching',
146
+ },
147
+ },
148
+ },
149
+ fetching: {
150
+ invoke: {
151
+ src: 'fetchTags',
152
+ onDone: {
153
+ target: 'searchIdle',
154
+ actions: 'setTagList',
155
+ },
156
+ onError: {
157
+ target: '#game_search_v2.fail',
158
+ },
159
+ },
160
+ },
161
+ },
162
+ },
163
+ sendingTrace: {
164
+ invoke: {
165
+ src: 'sendTrace',
166
+ onDone: {
167
+ target: 'idle',
168
+ },
169
+ onError: {
170
+ target: 'fail',
171
+ },
172
+ },
173
+ },
174
+ fail: {},
175
+ },
176
+ },
177
+ {
178
+ actions: {
179
+ setMainTagList: assign((context, event) => {
180
+ return {
181
+ mainTagList: event.data,
182
+ }
183
+ }),
184
+ setInitialData: assign((context, event) => {
185
+ const { recentlySearch = [], recentlyGame = [], youMayLike = [] } = event.data
186
+ let tagId = null
187
+ let gameList = []
188
+ if (recentlyGame?.length > 0) {
189
+ gameList = recentlyGame
190
+ } else if (youMayLike?.length > 0) {
191
+ gameList = youMayLike
192
+ }
193
+ return {
194
+ recentlySearch: recentlySearch.filter(item => item.id && item.i18n),
195
+ recentlyGame,
196
+ youMayLike,
197
+ gameList,
198
+ tagId
199
+ }
200
+ }),
201
+ setMainTagId: assign((context, event) => {
202
+ const { tagId } = event.data
203
+ const { mainTagList } = context
204
+ const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
205
+ return {
206
+ keyword: '',
207
+ tagId,
208
+ tagIndex,
209
+ click: 1,
210
+ clickDefault: null,
211
+ }
212
+ }),
213
+ clearMainTag: assign((context, event) => {
214
+ return {
215
+ tagId: null,
216
+ }
217
+ }),
218
+ setTagId: assign((context, event) => {
219
+ const { tagId, clickTagType } = event.data
220
+ const { mainTagList, tagList, recentlySearch } = context
221
+ if (clickTagType === 'RECENTLY SEARCH') {
222
+ const tagIndex = recentlySearch.findIndex((tag) => tag.id === tagId)
223
+ return {
224
+ tagId,
225
+ tagIndex,
226
+ click: 1,
227
+ clickDefault: null,
228
+ }
229
+ } else if (clickTagType === 'POPULAR KEYWORDS' || tagList.length <= 0) {
230
+ const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
231
+ return {
232
+ tagId,
233
+ tagIndex,
234
+ click: null,
235
+ clickDefault: 1,
236
+ }
237
+ } else {
238
+ const tagIndex = tagList.findIndex((tag) => tag.id === tagId)
239
+ return {
240
+ tagId,
241
+ tagIndex,
242
+ click: 1,
243
+ clickDefault: null,
244
+ }
245
+ }
246
+ }),
247
+ setGames: assign((context, event) => {
248
+ if (event?.data) {
249
+ const { traceId, result } = event.data
250
+ return {
251
+ traceId,
252
+ gameList: result,
253
+ }
254
+ } else {
255
+ const { tagId, recentlyGame, youMayLike } = context
256
+ let gameList = []
257
+ if (tagId === 'RECENTLY') {
258
+ gameList = recentlyGame
259
+ } else if (tagId === 'YOU MAY LIKE') {
260
+ gameList = youMayLike
261
+ }
262
+ return {
263
+ traceId: null,
264
+ gameList,
265
+ }
266
+ }
267
+ }),
268
+ setTraceData: assign((context, event) => {
269
+ const { isYouMayLike, isRecentlyGame, isRecentlySearch } = event.data?.traceData
270
+ return {
271
+ isYouMayLike,
272
+ isRecentlyGame,
273
+ isRecentlySearch,
274
+ }
275
+ }),
276
+ setKeyword: assign((context, event) => {
277
+ return {
278
+ keyword: event.data,
279
+ }
280
+ }),
281
+ clearKeywords: assign((context, event) => {
282
+ return {
283
+ keyword: '',
284
+ }
285
+ }),
286
+ setTagList: assign((context, event) => {
287
+ return {
288
+ tagList: event.data,
289
+ }
290
+ }),
291
+ setGameCode: assign((context, event) => {
292
+ const { gameList } = context
293
+ const gameCode = event.data
294
+ const gameCodeIndex = gameList.findIndex((game) => game === gameCode)
295
+ return {
296
+ gameCode,
297
+ gameCodeIndex,
298
+ }
299
+ }),
300
+ clearExceptKeyword: assign((context, event) => {
301
+ return {
302
+ gameList: [],
303
+ traceId: null,
304
+ tagId: null,
305
+ tagIndex: null,
306
+ gameCode: null,
307
+ gameCodeIndex: null,
308
+ isYouMayLike: null,
309
+ isRecentlyGame: null,
310
+ isRecentlySearch: null,
311
+ query: context.keyword,
312
+ click: null,
313
+ clickDefault: null,
314
+ }
315
+ }),
316
+ },
317
+ guards: {
318
+ isRecentlyYouMayLike: (context, event) => {
319
+ const { tagId } = context
320
+ return tagId === 'RECENTLY' || tagId === 'YOU MAY LIKE'
321
+ },
322
+ hasTagList: (context, event) => {
323
+ const { tagList } = context
324
+ return tagList?.length > 0
325
+ },
326
+ },
327
+ services: {
328
+ fetchTags: async (context, event) => {
329
+ const { keyword } = context
330
+ const { result } = await request.send(game.getGameTags({ q: keyword }))
331
+ return result
332
+ },
333
+ fetchInitialData: async (context, event) => {
334
+ const data = await request.send(game.getGameSearchHome())
335
+ return data
336
+ },
337
+ fetchGames: async (context, event) => {
338
+ const { tagId, tagIndex, keyword, click, clickDefault } = context
339
+ const { traceId, result } = await request.send(game.getGameSearchList({ id: tagId, index: tagIndex, q: keyword, click, clickDefault }))
340
+ return { traceId, result }
341
+ },
342
+ sendTrace: async (context, event) => {
343
+ const { traceId, tagId, tagIndex, gameCode, gameCodeIndex, keyword: query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch } = context
344
+ let id = tagId
345
+ if (tagId === 'RECENTLY' || tagId === 'YOU MAY LIKE') {
346
+ id = null
347
+ }
348
+ return await request.send(game.setGameSearchTrace({ traceId, tagId: id, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch }))
349
+ },
350
+ },
351
+ }
352
+ )
353
+ }
@@ -9,6 +9,7 @@ import game_v2 from './game_v2.js'
9
9
  import game_favorite from './game_favorite.js'
10
10
  import game_favorite_v2 from './game_favorite_v2.js'
11
11
  import game_search from './game_search.js'
12
+ import game_search_v2 from './game_search_v2.js'
12
13
  import game_hot_new from './game_hot_new.js'
13
14
  import inbox from './inbox.js'
14
15
  import merge from './merge.js'
@@ -45,6 +46,7 @@ export default {
45
46
  game_favorite,
46
47
  game_favorite_v2,
47
48
  game_search,
49
+ game_search_v2,
48
50
  game_hot_new,
49
51
  inbox,
50
52
  merge,