mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: add hook for problemset/download
This commit is contained in:
2 files changed
+9
-1
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user