From dbf51849d5f0ce8ccd4ba8a37df7723b5122d042 Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 25 May 2021 12:42:38 +0800 Subject: [PATCH] ui: download problem fix --- package.json | 4 ++-- .../components/zipDownloader/index.js | 18 +++++++++--------- packages/ui-default/misc/typography.styl | 8 +++++--- packages/ui-default/pages/problem_main.page.js | 6 ++++++ .../ui-default/templates/problem_main.html | 2 +- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 0a01a7a6..46b10636 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ "jest": "node build/jest", "typedoc": "cross-env NODE_OPTIONS=--max_old_space_size=8192 typedoc", "debug:all": "node --async-stack-traces --trace-deprecation --enable-source-maps build/start --debug --template", - "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps node_modules/.bin/hydrooj --debug --template", + "debug": "node --async-stack-traces --trace-deprecation --enable-source-maps node_modules/hydrooj/bin/hydrooj --debug --template", "start:all": "node build/start", - "start": "node node_modules/.bin/hydrooj", + "start": "node_modules/.bin/hydrooj", "clean": "zsh -c \"rm -rf tsconfig.build.tsbuildinfo ./packages/*/tsconfig.tsbuildinfo ./packages/*/dist ./.coverage\"" }, "version": "1.0.0", diff --git a/packages/ui-default/components/zipDownloader/index.js b/packages/ui-default/components/zipDownloader/index.js index ffb8ba37..4d93774e 100644 --- a/packages/ui-default/components/zipDownloader/index.js +++ b/packages/ui-default/components/zipDownloader/index.js @@ -1,4 +1,5 @@ import { dump } from 'js-yaml'; +import * as streamsaver from 'streamsaver'; import { createZipStream } from 'vj/utils/zip'; import pipeStream from 'vj/utils/pipeStream'; import i18n from 'vj/utils/i18n'; @@ -13,14 +14,13 @@ function onBeforeUnload(e) { } e.returnValue = ''; } +if (window.location.protocol === 'https:' + || window.location.protocol === 'chrome-extension:' + || window.location.hostname === 'localhost') { + streamsaver.mitm = '/streamsaver/mitm.html'; +} export default async function download(name, targets) { - const streamsaver = await import('streamsaver'); - if (window.location.protocol === 'https:' - || window.location.protocol === 'chrome-extension:' - || window.location.hostname === 'localhost') { - streamsaver.mitm = '/streamsaver/mitm.html'; - } if (!window.WritableStream) { window.WritableStream = (await import('web-streams-polyfill/dist/ponyfill.es6')).WritableStream; streamsaver.WritableStream = window.WritableStream; @@ -66,19 +66,19 @@ export async function downloadProblemSet(pids) { const targets = []; for (const pid of pids) { const { pdoc } = await request.get(`/d/${UiContext.domainId}/p/${pid}`); - targets.push({ filename: `/d/${UiContext.domainId}/p/${pid}/problem.yaml`, content: dump(pdoc) }); + targets.push({ filename: `${pid}/problem.yaml`, content: dump(pdoc) }); let { links } = await request.post( `/d/${UiContext.domainId}/p/${pid}/files`, { operation: 'get_links', files: pdoc.data.map((i) => i.name), type: 'testdata' } ); for (const filename of Object.keys(links)) { - targets.push({ filename: `/d/${UiContext.domainId}/p/${pid}/testdata/${filename}`, url: links[filename] }); + targets.push({ filename: `${pid}/testdata/${filename}`, url: links[filename] }); } ({ links } = await request.post(`/d/${UiContext.domainId}/p/${pid}/files`, { operation: 'get_links', files: pdoc.additional_file.map((i) => i.name), type: 'additional_file', })); for (const filename of Object.keys(links)) { - targets.push({ filename: `/d/${UiContext.domainId}/p/${pid}/additional_file/${filename}`, url: links[filename] }); + targets.push({ filename: `${pid}/additional_file/${filename}`, url: links[filename] }); } } await download('Export.zip', targets); diff --git a/packages/ui-default/misc/typography.styl b/packages/ui-default/misc/typography.styl index a133ab01..71d4520b 100644 --- a/packages/ui-default/misc/typography.styl +++ b/packages/ui-default/misc/typography.styl @@ -254,16 +254,18 @@ small, figcaption &:not(.user-profile-name) color: $primary-color -.typo p, .typo dl, .typo form, .typo hr, .typo table +.typo dl, .typo form, .typo hr, .typo table padding-top: 0.3em padding-bottom: 0.3em .typo li, .typo ol - padding-top: 0.2em - padding-bottom: 0.2em + padding-top: 0.1em + padding-bottom: 0.1em line-height: 1.25 .typo p + padding-top: 0.17em + padding-bottom: 0.17em line-height: 1.5 font-size: inherit diff --git a/packages/ui-default/pages/problem_main.page.js b/packages/ui-default/pages/problem_main.page.js index ce34da83..b236f637 100644 --- a/packages/ui-default/pages/problem_main.page.js +++ b/packages/ui-default/pages/problem_main.page.js @@ -226,6 +226,12 @@ const page = new NamedPage(['problem_main', 'problem_category'], () => { ev.preventDefault(); updateSelection(); }); + $(document).on('click', 'a.pager__item', (ev) => { + ev.preventDefault(); + pjax.request({ url: $(ev.currentTarget).attr('href') }).then(() => { + window.scrollTo(0, 0); + }); + }); }); export default page; diff --git a/packages/ui-default/templates/problem_main.html b/packages/ui-default/templates/problem_main.html index d434e83d..5cb9b79d 100644 --- a/packages/ui-default/templates/problem_main.html +++ b/packages/ui-default/templates/problem_main.html @@ -37,7 +37,7 @@ {{ _('Unhide Selected') }} - + {{ _('Download Selected') }}