@jetthai/cuora 1.1.341-rank-1 → 1.1.341-rank-3

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.1.341-rank-3](https://github.com/jetthai/cuora-module/compare/v1.1.341-rank-2...v1.1.341-rank-3) (2025-03-10)
6
+
7
+ ### [1.1.341-rank-2](https://github.com/jetthai/cuora-module/compare/v1.1.341-rank-1...v1.1.341-rank-2) (2025-03-06)
8
+
5
9
  ### [1.1.341-rank-1](https://github.com/jetthai/cuora-module/compare/v1.1.341...v1.1.341-rank-1) (2025-03-05)
6
10
 
7
11
  ### [1.1.341](https://github.com/jetthai/cuora-module/compare/v1.1.340...v1.1.341) (2025-02-25)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.1.341-rank-1",
3
+ "version": "1.1.341-rank-3",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "type": "module",
@@ -18,4 +18,9 @@ export default {
18
18
  method: 'post',
19
19
  params: { activityNo, cycle, round },
20
20
  }),
21
+ getRankingGames: ({ activityNo }) => ({
22
+ url: 'hot-game/ranking',
23
+ method: 'get',
24
+ params: { activityNo },
25
+ }),
21
26
  }
@@ -2,12 +2,12 @@ import { createMachine, assign } from 'xstate'
2
2
  import ranking from '../api/ranking.js'
3
3
 
4
4
  export default function (request) {
5
- const rateMapping = ['DAILY', 'WEEKLY', 'MONTHLY']
5
+ const cycleMapping = ['DAILY', 'WEEKLY', 'MONTHLY']
6
6
 
7
7
  function roundProcess(rounds) {
8
8
  const roundArrays = rounds.map((round) => Array.from({ length: round }, (_, i) => i + 1))
9
9
  return roundArrays.reduce((acc, roundArray, index) => {
10
- acc[rateMapping[index]] = roundArray.reverse()
10
+ acc[cycleMapping[index]] = roundArray.reverse()
11
11
  return acc
12
12
  }, {})
13
13
  }
@@ -23,12 +23,13 @@ export default function (request) {
23
23
  currentRound: [],
24
24
  cycle: '',
25
25
  round: 0,
26
- // api detail 資料
27
26
  rule: '',
27
+ // api detail 資料
28
28
  description: '',
29
29
  descriptionUrl: [],
30
30
  // api detail 排名資料
31
31
  playerRanking: {},
32
+ gameRanking: [],
32
33
  topRanking: [],
33
34
  // 前端這邊用的選單資料 { cycle, round }
34
35
  options: {},
@@ -83,7 +84,7 @@ export default function (request) {
83
84
  invoke: {
84
85
  src: 'fetchRankingDetail',
85
86
  onDone: {
86
- target: 'idle',
87
+ target: 'getRankingGames',
87
88
  actions: 'setRanking',
88
89
  },
89
90
  onError: {
@@ -91,6 +92,18 @@ export default function (request) {
91
92
  },
92
93
  },
93
94
  },
95
+ getRankingGames: {
96
+ invoke: {
97
+ src: 'fetchRankingGames',
98
+ onDone: {
99
+ target: 'idle',
100
+ actions: 'setRankingGames',
101
+ },
102
+ onError: {
103
+ target: 'idle',
104
+ },
105
+ },
106
+ },
94
107
  },
95
108
  },
96
109
  {
@@ -103,22 +116,29 @@ export default function (request) {
103
116
  }),
104
117
  setRanking: assign((context, event) => {
105
118
  return {
106
- rule: event.data?.rule,
107
119
  description: event.data?.description,
108
120
  descriptionUrl: event.data?.descriptionUrl,
109
121
  topRanking: event.data?.topRanking || [],
110
122
  playerRanking: event.data?.playerRanking || {},
111
123
  }
112
124
  }),
125
+ setRankingGames: assign((context, event) => {
126
+ return {
127
+ gameRanking: event.data || [],
128
+ }
129
+ }),
113
130
  setRankingOptions: assign((context, event) => {
114
131
  const cycle = event.data?.cycle
115
132
  const currentRound = event.data?.currentRound || []
116
133
  // 取得結算週期選單列表
117
- const cycleOptions = rateMapping.slice(0, currentRound.length)
118
- // 如果是月結算,則加入全部選項
119
- if (cycle === 'MONTHLY') cycleOptions.push('ALL')
134
+ const cycleOptions = cycleMapping.slice(0, currentRound.length)
120
135
  // 取得每週期的歷史期數選單列表
121
136
  const roundOptions = roundProcess(currentRound)
137
+ // 如果是月結算,則加入全部選項
138
+ if (cycle === 'MONTHLY') {
139
+ cycleOptions.push('ALL')
140
+ roundOptions.ALL = roundOptions.MONTHLY
141
+ }
122
142
  return {
123
143
  options: { cycle: cycleOptions, round: roundOptions },
124
144
  round: currentRound[currentRound.length - 1],
@@ -130,7 +150,8 @@ export default function (request) {
130
150
  // 處理變更 cycle,如果沒有輸入或沒有變更就不更新
131
151
  if (event.data?.cycle && cycle !== event.data?.cycle) {
132
152
  const { currentRound } = context
133
- const cycleIndex = rateMapping.indexOf(event.data?.cycle)
153
+ const cycleForRound = event.data?.cycle === 'ALL' ? 'MONTHLY' : event.data?.cycle
154
+ const cycleIndex = cycleMapping.indexOf(cycleForRound)
134
155
  return { cycle: event.data?.cycle, round: currentRound[cycleIndex] }
135
156
  }
136
157
  if (event.data?.round && round !== event.data?.round) {
@@ -158,6 +179,11 @@ export default function (request) {
158
179
  const { data } = await request.send(ranking.getRankingDetail({ activityNo, cycle, round }))
159
180
  return data
160
181
  },
182
+ fetchRankingGames: async (context) => {
183
+ const { activityNo } = context
184
+ const { data } = await request.send(ranking.getRankingGames({ activityNo }))
185
+ return data
186
+ },
161
187
  },
162
188
  }
163
189
  )