Skip to content

Commit 5228f1b

Browse files
authored
Merge pull request #132 from MaaAssistantArknights/dev
2 parents 03e4390 + 2ba1717 commit 5228f1b

File tree

11 files changed

+75
-94
lines changed

11 files changed

+75
-94
lines changed

src/apis/arknights.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const useLevels = ({ suspense }: { suspense?: boolean } = {}) => {
3131

3232
const response = useSWR<LevelResponse>(url, {
3333
focusThrottleInterval: ONE_DAY,
34+
dedupingInterval: ONE_DAY,
3435
suspense,
3536
fetcher: async (input: string, init?: RequestInit) => {
3637
let res: LevelResponse

src/apis/rating.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import { Response } from 'models/network'
22
import { OpRatingType, Operation } from 'models/operation'
33
import { jsonRequest } from 'utils/fetcher'
44

5+
const ratingTypeMapping: Record<OpRatingType, string> = {
6+
0: 'None',
7+
1: 'Like',
8+
2: 'Dislike',
9+
}
10+
511
export const apiPostRating = (id: Operation['id'], rating: OpRatingType) => {
6-
return jsonRequest<
7-
Response<Pick<Operation, 'id' | 'ratingRatio' | 'ratingType'>>
8-
>('/copilot/rating', {
12+
return jsonRequest<Response<string>>('/copilot/rating', {
913
method: 'POST',
1014
json: {
1115
id,
12-
rating,
16+
rating: ratingTypeMapping[rating],
1317
},
1418
})
1519
}

src/components/editor/OperationEditor.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ export const StageNameInput: FC<{
155155
selectedItem={selectedLevel}
156156
onItemSelect={selectLevel}
157157
inputValueRenderer={(item) => `${item.catThree} ${item.name}`}
158-
popoverContentProps={{
159-
className: 'max-h-64 overflow-auto',
160-
}}
161158
noResults={<MenuItem disabled text="没有匹配的关卡" />}
162159
createNewItemFromQuery={(query) => createCustomLevel(query)}
163160
createNewItemRenderer={(query, active, handleClick) => (

src/components/editor/operator/EditorOperatorGroupSelect.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ export const EditorOperatorGroupSelect = ({
5757
selected={active}
5858
/>
5959
)}
60-
popoverContentProps={{
61-
className: 'max-h-64 overflow-auto',
62-
}}
6360
noResults={<MenuItem disabled text={`没有匹配的干员组`} />}
6461
inputProps={{
6562
placeholder: `干员组名`,

src/components/editor/source/SourceEditorHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export const SourceEditorHeader: FC<SourceEditorHeaderProps> = ({
3737
let title: string | undefined
3838
try {
3939
title = (JSON.parse(text) as CopilotDocV1.Operation).doc.title
40-
title = title.slice(0, 20)
4140
} catch (e) {
42-
// ignored
41+
console.warn(e)
4342
}
4443

4544
const blob = new Blob([text], {

src/components/viewer/OperationRating.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import clsx from 'clsx'
44
import { FC } from 'react'
55
import Rating from 'react-rating'
66

7-
import { OpRatingLevelString } from 'models/enums'
87
import { Operation } from 'models/operation'
8+
import { ratingLevelToString } from 'models/rating'
99

1010
export const OperationRating: FC<{
1111
operation: Pick<
@@ -67,7 +67,7 @@ export const OperationRating: FC<{
6767
? layout === 'vertical'
6868
? '还没有足够的评分'
6969
: '评分不足'
70-
: OpRatingLevelString[operation.ratingLevel]}
70+
: ratingLevelToString(operation.ratingLevel)}
7171
</div>
7272
</div>
7373
)

src/components/viewer/OperationViewer.tsx

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { requestDeleteOperation } from 'apis/copilotOperation'
1818
import { useOperation } from 'apis/query'
1919
import { apiPostRating } from 'apis/rating'
2020
import { useAtom } from 'jotai'
21-
import { merge } from 'lodash-es'
21+
import { noop } from 'lodash-es'
2222
import { ComponentType, FC, useMemo, useState } from 'react'
2323
import { Link } from 'react-router-dom'
2424

@@ -118,7 +118,6 @@ export const OperationViewer: ComponentType<{
118118
const levels = useLevels()?.data?.data || []
119119

120120
const [auth] = useAtom(authAtom)
121-
const authed = !!auth.token
122121

123122
// make eslint happy: we got Suspense out there
124123
if (!operation) return null
@@ -129,15 +128,12 @@ export const OperationViewer: ComponentType<{
129128
)
130129
}
131130

132-
const handleCopyShortCode = () => {
133-
if (!operation?.id) {
134-
AppToaster.show({
135-
message: '获取作业失败',
136-
intent: 'danger',
137-
})
138-
return
139-
}
131+
const operationDoc = useMemo(
132+
() => toCopilotOperation(operation),
133+
[operation],
134+
)
140135

136+
const handleCopyShortCode = () => {
141137
const shortCode = toShortCode(operation.id)
142138
navigator.clipboard.writeText(shortCode)
143139

@@ -148,22 +144,15 @@ export const OperationViewer: ComponentType<{
148144
}
149145

150146
const handleDownloadJSON = () => {
151-
const content = operation?.content
152-
if (!content) {
153-
AppToaster.show({
154-
message: '获取作业失败',
155-
intent: 'danger',
156-
})
157-
return
158-
}
159-
160-
const blob = new Blob([content], {
147+
// pretty print the JSON
148+
const json = JSON.stringify(operationDoc, null, 2)
149+
const blob = new Blob([json], {
161150
type: 'application/json',
162151
})
163152
const url = URL.createObjectURL(blob)
164153
const link = document.createElement('a')
165154
link.href = url
166-
link.download = `MAACopilot_作业${operation.id}.json`
155+
link.download = `MAACopilot_${operationDoc.doc.title}.json`
167156
link.click()
168157
URL.revokeObjectURL(url)
169158

@@ -174,35 +163,20 @@ export const OperationViewer: ComponentType<{
174163
}
175164

176165
const handleRating = async (decision: OpRatingType) => {
177-
if (!authed) {
178-
AppToaster.show({
179-
message: '请先登录',
180-
intent: 'warning',
181-
})
182-
return
166+
// cancel rating if already rated by the same type
167+
if (decision === operation.ratingType) {
168+
decision = OpRatingType.None
183169
}
184170

185-
mutate(async (val) => {
186-
try {
187-
return await wrapErrorMessage(
188-
(e: NetworkError) => `提交评分失败:${e.message}`,
189-
(async () => {
190-
const response = await apiPostRating(operationId, decision)
191-
192-
return merge(val, response)
193-
})(),
194-
)
195-
} catch (e) {
171+
wrapErrorMessage(
172+
(e: NetworkError) => `提交评分失败:${e.message}`,
173+
mutate(async (val) => {
174+
await apiPostRating(operationId, decision)
196175
return val
197-
}
198-
})
176+
}),
177+
).catch(noop)
199178
}
200179

201-
const operationDoc = useMemo(
202-
() => toCopilotOperation(operation),
203-
[operation],
204-
)
205-
206180
return (
207181
<OperationDrawer
208182
title={
@@ -274,24 +248,24 @@ export const OperationViewer: ComponentType<{
274248
<Button
275249
icon="thumbs-up"
276250
intent={
277-
operation?.ratingType === OpRatingType.Like
251+
operation.ratingType === OpRatingType.Like
278252
? 'success'
279253
: 'none'
280254
}
281255
className="mr-2"
282-
active={operation?.ratingType === OpRatingType.Like}
256+
active={operation.ratingType === OpRatingType.Like}
283257
onClick={() => handleRating(OpRatingType.Like)}
284258
/>
285259
</Tooltip2>
286260
<Tooltip2 content=" ヽ(。>д<)p" placement="bottom">
287261
<Button
288262
icon="thumbs-down"
289263
intent={
290-
operation?.ratingType === OpRatingType.Dislike
264+
operation.ratingType === OpRatingType.Dislike
291265
? 'danger'
292266
: 'none'
293267
}
294-
active={operation?.ratingType === OpRatingType.Dislike}
268+
active={operation.ratingType === OpRatingType.Dislike}
295269
onClick={() => handleRating(OpRatingType.Dislike)}
296270
/>
297271
</Tooltip2>

src/components/viewer/ViewerActions.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { FactItem } from 'components/FactItem'
99
import type { CopilotDocV1 } from 'models/copilot.schema'
1010
import { findActionType } from 'models/types'
1111

12+
import {
13+
findOperatorDirection,
14+
findOperatorSkillUsage,
15+
} from '../../models/operator'
1216
import { formatDuration } from '../../utils/times'
1317

1418
const actionKey = (action: CopilotDocV1.Action, index?: number) =>
@@ -67,7 +71,7 @@ export const ViewerActions: FC<{
6771
title="切换技能用法至"
6872
icon="swap-horizontal"
6973
>
70-
{action.skillUsage}
74+
{findOperatorSkillUsage(action.skillUsage).title}
7175
</FactItem>
7276
)}
7377

@@ -82,7 +86,9 @@ export const ViewerActions: FC<{
8286

8387
{'direction' in action && (
8488
<FactItem dense title="朝向" icon="compass">
85-
<span className="font-mono">{action.direction}</span>
89+
<span className="font-mono">
90+
{findOperatorDirection(action.direction).title}
91+
</span>
8692
</FactItem>
8793
)}
8894
</div>

src/models/enums.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/models/operation.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface Operation {
1313
views: number
1414
hotScore: number
1515
available: boolean
16-
ratingLevel: OpRatingLevel
16+
ratingLevel: number // integer in [0, 10]
1717
ratingRatio: number
1818
ratingType: OpRatingType
1919
isNotEnoughRating: boolean
@@ -31,22 +31,10 @@ export interface Level {
3131
height: number
3232
}
3333

34-
export enum OpRatingLevel {
35-
OverwhelminglyPositive = 'OverwhelminglyPositive',
36-
VeryPositive = 'VeryPositive',
37-
Positive = 'Positive',
38-
MostlyPositive = 'MostlyPositive',
39-
Mixed = 'Mixed',
40-
MostlyNegative = 'MostlyNegative',
41-
Negative = 'Negative',
42-
VeryNegative = 'VeryNegative',
43-
OverwhelminglyNegative = 'OverwhelminglyNegative',
44-
}
45-
4634
export enum OpRatingType {
47-
Like = 'Like',
48-
Dislike = 'Dislike',
49-
None = 'None',
35+
None = 0,
36+
Like = 1,
37+
Dislike = 2,
5038
}
5139

5240
export enum OpDifficulty {

0 commit comments

Comments
 (0)