ui: add hook for problemset/download

pull/557/head
undefined 2 years ago
parent 949cdb2746
commit c859983e07
No known key found for this signature in database

@ -5,6 +5,7 @@ import Notification from 'vj/components/notification';
import {
api, createZipStream, gql, i18n, pipeStream, request,
} from 'vj/utils';
import { ctx } from '../../context';
let isBeforeUnloadTriggeredByLibrary = !window.isSecureContext;
function onBeforeUnload(e) {
@ -75,10 +76,17 @@ export default async function download(filename, targets) {
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') {
Notification.info(i18n('Downloading...'));
const targets = [];
try {
await ctx.serial('problemset/download', pids, name, targets);
for (const pid of pids) {
const pdoc = await api(gql`
problem(id: ${+pid}) {

@ -11,7 +11,7 @@ declare global {
UserContext: any;
UiContext: any;
Hydro: any;
externalModules: Record<string, string>;
externalModules: Record<string, string | (() => Promise<any>)>;
captureException?: (e: Error) => void;
}
}

Loading…
Cancel
Save