Skip to content

Commit 13e422b

Browse files
committed
feat: set downloading filename with the operation's title instead of ID
Also removes the length limit of 20 when downloading in source editor.
1 parent be2c009 commit 13e422b

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

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/OperationViewer.tsx

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,12 @@ export const OperationViewer: ComponentType<{
128128
)
129129
}
130130

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

136+
const handleCopyShortCode = () => {
140137
const shortCode = toShortCode(operation.id)
141138
navigator.clipboard.writeText(shortCode)
142139

@@ -147,22 +144,15 @@ export const OperationViewer: ComponentType<{
147144
}
148145

149146
const handleDownloadJSON = () => {
150-
const content = operation?.content
151-
if (!content) {
152-
AppToaster.show({
153-
message: '获取作业失败',
154-
intent: 'danger',
155-
})
156-
return
157-
}
158-
159-
const blob = new Blob([content], {
147+
// pretty print the JSON
148+
const json = JSON.stringify(operationDoc, null, 2)
149+
const blob = new Blob([json], {
160150
type: 'application/json',
161151
})
162152
const url = URL.createObjectURL(blob)
163153
const link = document.createElement('a')
164154
link.href = url
165-
link.download = `MAACopilot_作业${operation.id}.json`
155+
link.download = `MAACopilot_${operationDoc.doc.title}.json`
166156
link.click()
167157
URL.revokeObjectURL(url)
168158

@@ -187,11 +177,6 @@ export const OperationViewer: ComponentType<{
187177
).catch(noop)
188178
}
189179

190-
const operationDoc = useMemo(
191-
() => toCopilotOperation(operation),
192-
[operation],
193-
)
194-
195180
return (
196181
<OperationDrawer
197182
title={

0 commit comments

Comments
 (0)