@jetthai/cuora 1.1.126 → 1.1.127

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,8 @@
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.1.127](https://github.com/jetthai/cuora-module/compare/v1.1.126...v1.1.127) (2023-06-28)
6
+
5
7
  ### [1.1.126](https://github.com/jetthai/cuora-module/compare/v1.1.125...v1.1.126) (2023-06-20)
6
8
 
7
9
  ### [1.1.125](https://github.com/jetthai/cuora-module/compare/v1.1.124...v1.1.125) (2023-06-20)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.126",
3
+ "version": "1.1.127",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -4,9 +4,10 @@ import game from '../api/game.js'
4
4
  export default function (request) {
5
5
  return createMachine(
6
6
  {
7
- id: 'game_search',
7
+ id: 'game_search_cash',
8
8
  initial: 'preset',
9
9
  context: {
10
+ initialized: false,
10
11
  keyword: '',
11
12
  tagId: null,
12
13
  mainTagList: [],
@@ -18,92 +19,60 @@ export default function (request) {
18
19
  clickDefault: null,
19
20
  traceId: null,
20
21
  gameCode: null,
22
+ lang: 'en_US',
23
+
24
+ // v2
25
+ recentlySearch: [],
26
+ recentlyGame: [],
27
+ youMayLike: [],
28
+ selectedType: null,
29
+ isYouMayLike: null,
30
+ isRecentlyGame: null,
31
+ isRecentlySearch: null,
21
32
  },
22
33
  states: {
23
34
  preset: {
35
+ exit: 'setInitialized',
24
36
  invoke: {
25
- src: 'fetchTags',
37
+ src: 'fetchInitialData',
26
38
  onDone: {
27
- target: 'loading',
28
- actions: ['setMainTagList', 'setInitialTagId'],
39
+ target: 'idle',
40
+ actions: 'setInitialData',
29
41
  },
30
42
  onError: {
31
43
  target: 'fail',
32
44
  },
33
45
  },
34
46
  },
35
- loading: {
47
+ idle: {},
48
+ debouncing: {
49
+ after: {
50
+ 500: {
51
+ target: 'fetchingTagsByKeyword',
52
+ },
53
+ },
54
+ },
55
+ fetchingTagsByKeyword: {
36
56
  invoke: {
37
- src: 'fetchGames',
57
+ src: 'fetchTags',
38
58
  onDone: {
39
59
  target: 'idle',
40
- actions: 'setGames',
60
+ actions: 'setTagList',
41
61
  },
42
62
  onError: {
43
- target: '#game_search.fail',
44
- },
45
- },
46
- },
47
- idle: {
48
- on: {
49
- SET_MAIN_TAG_ID: {
50
- target: 'loading',
51
- actions: 'setMainTagId',
52
- },
53
- PLAY_GAME: {
54
- target: 'sendingTrace',
55
- actions: 'setGameCode',
56
- },
57
- START_SEARCH: {
58
- target: 'searching',
59
- actions: 'clearKeyword',
63
+ target: 'fail',
60
64
  },
61
65
  },
62
66
  },
63
- searching: {
64
- initial: 'debouncing',
65
- states: {
66
- debouncing: {
67
- after: {
68
- 500: {
69
- target: 'fetchingTagsByKeyword',
70
- },
71
- },
72
- },
73
- fetchingTagsByKeyword: {
74
- invoke: {
75
- src: 'fetchTags',
76
- onDone: {
77
- actions: 'setTagList',
78
- },
79
- onError: {
80
- target: '#game_search.fail',
81
- },
82
- },
83
- },
84
- },
85
- on: {
86
- SET_TAG_ID: {
87
- target: 'loading',
88
- actions: 'setTagId',
89
- },
90
- PRESS_ENTER: [
91
- {
92
- actions: send((context, event) => ({ type: 'SET_TAG_ID', data: context.tagList[0].id })),
93
- cond: 'hasTagList',
94
- },
95
- {
96
- target: 'sendingTrace',
97
- actions: 'clearExceptKeyword',
98
- },
99
- ],
100
- SET_KEYWORD: {
101
- target: 'searching.debouncing',
102
- actions: 'setKeyword',
67
+ fetchingGames: {
68
+ invoke: {
69
+ src: 'fetchGames',
70
+ onDone: {
71
+ target: 'idle',
72
+ actions: ['setGames'],
103
73
  },
104
- STOP_SEARCH: {
105
- target: 'loading',
106
- actions: 'setInitialTagId',
74
+ onError: {
75
+ target: 'idle',
107
76
  },
108
77
  },
109
78
  },
@@ -120,20 +89,46 @@ export default function (request) {
120
89
  },
121
90
  fail: {},
122
91
  },
92
+ on: {
93
+ SET_KEYWORD: {
94
+ target: '.debouncing',
95
+ actions: ['setKeyword', 'setLang'],
96
+ cond: 'isInitialized',
97
+ },
98
+ CLEAR_KEYWORD: {
99
+ target: '.debouncing',
100
+ actions: 'clearKeyword',
101
+ },
102
+ SET_TAG_ID: {
103
+ target: 'fetchingGames',
104
+ actions: 'setTagId',
105
+ },
106
+ PRESS_ENTER: {
107
+ target: 'fetchingTagsByKeyword',
108
+ },
109
+ },
123
110
  },
124
111
  {
125
112
  actions: {
113
+ setInitialized: assign((context, event) => {
114
+ return {
115
+ initialized: true,
116
+ }
117
+ }),
126
118
  setMainTagList: assign((context, event) => {
127
119
  return {
128
120
  mainTagList: event.data,
129
121
  }
130
122
  }),
131
- setInitialTagId: assign((context, event) => {
132
- const { mainTagList } = context
123
+ setInitialData: assign((context, event) => {
124
+ const { home, tag } = event.data
125
+ const { recentlySearch = [], recentlyGame = [], youMayLike = [] } = home
126
+
133
127
  return {
134
- tagId: mainTagList[0].id,
135
- tagIndex: 0,
136
- keyword: '',
128
+ mainTagList: tag?.result || [],
129
+ recentlySearch: recentlySearch.filter((item) => item.id && item.i18n),
130
+ recentlyGame,
131
+ youMayLike,
137
132
  }
138
133
  }),
139
134
  setMainTagId: assign((context, event) => {
@@ -144,13 +139,13 @@ export default function (request) {
144
139
  keyword: '',
145
140
  tagId,
146
141
  tagIndex,
147
- click: null,
142
+ click: 1,
148
143
  clickDefault: null,
149
144
  }
150
145
  }),
151
146
  setTagId: assign((context, event) => {
152
- const tagId = event.data
153
- const { mainTagList, tagList } = context
147
+ const { tagId, traceData, clickTagType } = event.data
148
+ const { mainTagList, tagList, lang } = context
154
149
  if (tagList.length === 0) {
155
150
  const tagIndex = mainTagList.findIndex((tag) => tag.id === tagId)
156
151
  return {
@@ -178,7 +173,12 @@ export default function (request) {
178
173
  }),
179
174
  setKeyword: assign((context, event) => {
180
175
  return {
181
- keyword: event.data,
176
+ keyword: event.data.keyword,
177
+ }
178
+ }),
179
+ setLang: assign((context, event) => {
180
+ return {
181
+ lang: event.data.lang,
182
182
  }
183
183
  }),
184
184
  clearKeyword: assign((context, event) => {
@@ -200,20 +200,6 @@ export default function (request) {
200
200
  gameCodeIndex,
201
201
  }
202
202
  }),
203
- clearExceptKeyword: assign((context, event) => {
204
- return {
205
- gameList: [],
206
- //
207
- traceId: null,
208
- tagId: null,
209
- tagIndex: null,
210
- gameCode: null,
211
- gameCodeIndex: null,
212
- query: context.keyword,
213
- click: null,
214
- clickDefault: null,
215
- }
216
- }),
217
203
  },
218
204
  guards: {
219
205
  hasMainTags: (context, event) => {
@@ -222,21 +208,56 @@ export default function (request) {
222
208
  hasTagList: (context, event) => {
223
209
  return context.tagList.length > 0
224
210
  },
211
+ isInitialized: (context, event) => {
212
+ return context.initialized
213
+ },
225
214
  },
226
215
  services: {
227
216
  fetchTags: async (context, event) => {
228
- const { keyword } = context
229
- const { result } = await request.send(game.getGameTags({ q: keyword }))
217
+ const { keyword, lang } = context
218
+ const { result } = await request.send(game.getGameTags({ q: keyword, lang }))
230
219
  return result
231
220
  },
221
+ fetchInitialData: async (context, event) => {
222
+ const { keyword, lang } = context
223
+ const [home, tag] = await Promise.all([
224
+ request.send(game.getGameSearchHome()),
225
+ request.send(
226
+ game.getGameTags({
227
+ q: keyword,
228
+ lang,
229
+ })
230
+ ),
231
+ ])
232
+ return { home, tag }
233
+ },
232
234
  fetchGames: async (context, event) => {
233
235
  const { tagId, tagIndex, keyword, click, clickDefault } = context
234
- const { traceId, result } = await request.send(game.getGameSearchList({ id: tagId, index: tagIndex, q: keyword, click, clickDefault }))
236
+ const { traceId, result } = await request.send(
237
+ game.getGameSearchList({
238
+ id: tagId,
239
+ index: tagIndex,
240
+ q: keyword,
241
+ click,
242
+ clickDefault,
243
+ })
244
+ )
235
245
  return { traceId, result }
236
246
  },
237
247
  sendTrace: async (context, event) => {
238
248
  const { traceId, tagId, tagIndex, gameCode, gameCodeIndex, keyword: query, click, clickDefault } = context
239
- return await request.send(game.setGameSearchTrace({ traceId, tagId, tagIndex, gameCode, gameCodeIndex, query, click, clickDefault }))
249
+ return await request.send(
250
+ game.setGameSearchTrace({
251
+ traceId,
252
+ tagId,
253
+ tagIndex,
254
+ gameCode,
255
+ gameCodeIndex,
256
+ query,
257
+ click,
258
+ clickDefault,
259
+ })
260
+ )
240
261
  },
241
262
  },
242
263
  }
@@ -5,7 +5,7 @@ import common from './common.js'
5
5
  import error from './error.js'
6
6
  import game_v2_1 from './game_v2_1.js'
7
7
  import game_favorite_v2 from './game_favorite_v2.js'
8
- import game_search from './game_search.js'
8
+ import game_search_cash from './game_search_cash.js'
9
9
  import game_search_v2 from './game_search_v2.js'
10
10
  import game_hot_new from './game_hot_new.js'
11
11
  import inbox from './inbox.js'
@@ -40,7 +40,7 @@ export default {
40
40
  common,
41
41
  error,
42
42
  game_favorite_v2,
43
- game_search,
43
+ game_search_cash,
44
44
  game_search_v2,
45
45
  game_hot_new,
46
46
  inbox,