@jetthai/cuora 1.0.192 → 1.0.193-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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
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-1](https://github.com/jetthai/cuora-module/compare/v1.0.193...v1.0.193-1) (2022-11-01)
6
+
7
+ ### [1.0.193](https://github.com/jetthai/cuora-module/compare/v1.0.192...v1.0.193) (2022-10-26)
8
+
5
9
  ### [1.0.192](https://github.com/jetthai/cuora-module/compare/v1.0.191...v1.0.192) (2022-10-26)
6
10
 
7
11
  ### [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-1",
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 }) => ({
@@ -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,354 @@
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
+ },
133
+ },
134
+ },
135
+ debouncing: {
136
+ on: {
137
+ SET_KEYWORD: {
138
+ target: 'debouncing',
139
+ actions: 'setKeyword',
140
+ },
141
+ },
142
+ after: {
143
+ 500: {
144
+ target: 'fetching',
145
+ },
146
+ },
147
+ },
148
+ fetching: {
149
+ invoke: {
150
+ src: 'fetchTags',
151
+ onDone: {
152
+ target: 'searchIdle',
153
+ actions: 'setTagList',
154
+ },
155
+ onError: {
156
+ target: '#game_search_v2.fail',
157
+ },
158
+ },
159
+ },
160
+ },
161
+ },
162
+ sendingTrace: {
163
+ invoke: {
164
+ src: 'sendTrace',
165
+ onDone: {
166
+ target: 'idle',
167
+ },
168
+ onError: {
169
+ target: 'fail',
170
+ },
171
+ },
172
+ },
173
+ fail: {},
174
+ },
175
+ },
176
+ {
177
+ actions: {
178
+ setMainTagList: assign((context, event) => {
179
+ return {
180
+ mainTagList: event.data,
181
+ }
182
+ }),
183
+ setInitialData: assign((context, event) => {
184
+ const { recentlySearch = [], recentlyGame = [], youMayLike = [] } = event.data
185
+ let tagId = null
186
+ let gameList = []
187
+ if (recentlyGame?.length > 0) {
188
+ // tagId = 'RECENTLY'
189
+ gameList = recentlyGame
190
+ } else if (youMayLike?.length > 0) {
191
+ // tagId = 'YOU MAY LIKE'
192
+ gameList = youMayLike
193
+ }
194
+ return {
195
+ recentlySearch: recentlySearch.filter(item => item.id && item.i18n),
196
+ recentlyGame,
197
+ youMayLike,
198
+ gameList,
199
+ tagId
200
+ }
201
+ }),
202
+ setMainTagId: assign((context, event) => {
203
+ const { tagId } = event.data
204
+ const { mainTagList } = context
205
+ const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
206
+ return {
207
+ keyword: '',
208
+ tagId,
209
+ tagIndex,
210
+ click: 1,
211
+ clickDefault: null,
212
+ }
213
+ }),
214
+ clearMainTag: assign((context, event) => {
215
+ return {
216
+ tagId: null,
217
+ }
218
+ }),
219
+ setTagId: assign((context, event) => {
220
+ const { tagId, clickTagType, traceData } = event.data
221
+ const { mainTagList, tagList, recentlySearch } = context
222
+ if (clickTagType === 'RECENTLY SEARCH') {
223
+ const tagIndex = recentlySearch.findIndex((tag) => tag.id === tagId)
224
+ return {
225
+ tagId,
226
+ tagIndex,
227
+ click: 1,
228
+ clickDefault: null,
229
+ }
230
+ } else if (clickTagType === 'POPULAR KEYWORDS' || tagList.length <= 0) {
231
+ const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
232
+ return {
233
+ tagId,
234
+ tagIndex,
235
+ click: null,
236
+ clickDefault: 1,
237
+ }
238
+ } else {
239
+ const tagIndex = tagList.findIndex((tag) => tag.id === tagId)
240
+ return {
241
+ tagId,
242
+ tagIndex,
243
+ click: 1,
244
+ clickDefault: null,
245
+ }
246
+ }
247
+ }),
248
+ setGames: assign((context, event) => {
249
+ if (event?.data) {
250
+ const { traceId, result } = event.data
251
+ return {
252
+ traceId,
253
+ gameList: result,
254
+ }
255
+ } else {
256
+ const { tagId, recentlyGame, youMayLike } = context
257
+ let gameList = []
258
+ if (tagId === 'RECENTLY') {
259
+ gameList = recentlyGame
260
+ } else if (tagId === 'YOU MAY LIKE') {
261
+ gameList = youMayLike
262
+ }
263
+ return {
264
+ traceId: null,
265
+ gameList,
266
+ }
267
+ }
268
+ }),
269
+ setTraceData: assign((context, event) => {
270
+ const { isYouMayLike, isRecentlyGame, isRecentlySearch } = event.data?.traceData
271
+ return {
272
+ isYouMayLike,
273
+ isRecentlyGame,
274
+ isRecentlySearch,
275
+ }
276
+ }),
277
+ setKeyword: assign((context, event) => {
278
+ return {
279
+ keyword: event.data,
280
+ }
281
+ }),
282
+ clearKeyword: assign((context, event) => {
283
+ return {
284
+ keyword: '',
285
+ }
286
+ }),
287
+ setTagList: assign((context, event) => {
288
+ return {
289
+ tagList: event.data,
290
+ }
291
+ }),
292
+ setGameCode: assign((context, event) => {
293
+ const { gameList } = context
294
+ const gameCode = event.data
295
+ const gameCodeIndex = gameList.findIndex((game) => game === gameCode)
296
+ return {
297
+ gameCode,
298
+ gameCodeIndex,
299
+ }
300
+ }),
301
+ clearExceptKeyword: assign((context, event) => {
302
+ return {
303
+ gameList: [],
304
+ traceId: null,
305
+ tagId: null,
306
+ tagIndex: null,
307
+ gameCode: null,
308
+ gameCodeIndex: null,
309
+ isYouMayLike: null,
310
+ isRecentlyGame: null,
311
+ isRecentlySearch: null,
312
+ query: context.keyword,
313
+ click: null,
314
+ clickDefault: null,
315
+ }
316
+ }),
317
+ },
318
+ guards: {
319
+ isRecentlyYouMayLike: (context, event) => {
320
+ const { tagId } = context
321
+ return tagId === 'RECENTLY' || tagId === 'YOU MAY LIKE'
322
+ },
323
+ hasTagList: (context, event) => {
324
+ const { tagList } = context
325
+ return tagList?.length > 0
326
+ },
327
+ },
328
+ services: {
329
+ fetchTags: async (context, event) => {
330
+ const { keyword } = context
331
+ const { result } = await request.send(game.getGameTags({ q: keyword }))
332
+ return result
333
+ },
334
+ fetchInitialData: async (context, event) => {
335
+ const data = await request.send(game.getGameSearchHome())
336
+ return data
337
+ },
338
+ fetchGames: async (context, event) => {
339
+ const { tagId, tagIndex, keyword, click, clickDefault } = context
340
+ const { traceId, result } = await request.send(game.getGameSearchList({ id: tagId, index: tagIndex, q: keyword, click, clickDefault }))
341
+ return { traceId, result }
342
+ },
343
+ sendTrace: async (context, event) => {
344
+ const { traceId, tagId, tagIndex, gameCode, gameCodeIndex, keyword: query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch } = context
345
+ let id = tagId
346
+ if (tagId === 'RECENTLY' || tagId === 'YOU MAY LIKE') {
347
+ id = null
348
+ }
349
+ return await request.send(game.setGameSearchTrace({ traceId, tagId: id, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault, isYouMayLike, isRecentlyGame, isRecentlySearch }))
350
+ },
351
+ },
352
+ }
353
+ )
354
+ }
@@ -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,