mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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 {
|
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}) {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user