From c859983e075aededaeb416c0fcf6f7d719ae7f71 Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 11 Apr 2023 14:14:10 +0800 Subject: [PATCH] ui: add hook for problemset/download --- packages/ui-default/components/zipDownloader/index.ts | 8 ++++++++ packages/ui-default/hydro.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/ui-default/components/zipDownloader/index.ts b/packages/ui-default/components/zipDownloader/index.ts index 0b7a0a19..7a7b642d 100644 --- a/packages/ui-default/components/zipDownloader/index.ts +++ b/packages/ui-default/components/zipDownloader/index.ts @@ -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}) { diff --git a/packages/ui-default/hydro.ts b/packages/ui-default/hydro.ts index 3bfcfcd4..d2a71228 100644 --- a/packages/ui-default/hydro.ts +++ b/packages/ui-default/hydro.ts @@ -11,7 +11,7 @@ declare global { UserContext: any; UiContext: any; Hydro: any; - externalModules: Record; + externalModules: Record Promise)>; captureException?: (e: Error) => void; } }