ui: add hook for problemset/download

This commit is contained in:
undefined committed 2023-04-11 14:14:10 +08:00
1 parent 949cdb2746
commit c859983e07
2 files changed
+9 -1

No files matched your search

@@ -5,6 +5,7 @@ import Notification from 'vj/components/notification';
import { import {
api, createZipStream, gql, i18n, pipeStream, request, api, createZipStream, gql, i18n, pipeStream, request,
} from 'vj/utils'; } from 'vj/utils';
import { ctx } from '../../context';
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext; let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
function onBeforeUnload(e) { function onBeforeUnload(e) {
@@ -75,10 +76,17 @@ export default async function download(filename, targets) {
window.removeEventListener('beforeunload', onBeforeUnload); window.removeEventListener('beforeunload', onBeforeUnload);
} }
declare module '../../api' {
interface EventMap {
'problemset/download': (pids: number[], name: string, targets: { filename: string; url?: string; content?: string }[]) => void;
}
}
export async function downloadProblemSet(pids, name = 'Export') { export async function downloadProblemSet(pids, name = 'Export') {
Notification.info(i18n('Downloading...')); Notification.info(i18n('Downloading...'));
const targets = []; const targets = [];
try { try {
await ctx.serial('problemset/download', pids, name, targets);
for (const pid of pids) { for (const pid of pids) {
const pdoc = await api(gql` const pdoc = await api(gql`
problem(id: ${+pid}) { problem(id: ${+pid}) {
+1 -1
View File
@@ -11,7 +11,7 @@ declare global {
UserContext: any; UserContext: any;
UiContext: any; UiContext: any;
Hydro: any; Hydro: any;
externalModules: Record<string, string>; externalModules: Record<string, string | (() => Promise<any>)>;
captureException?: (e: Error) => void; captureException?: (e: Error) => void;
} }
} }