From 0349a51b0f2cd04c93f25201de22866d3e76fd70 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 13 Nov 2024 01:52:28 +0800 Subject: [PATCH] resolver: make ci happy --- .../{resolver.tsx => resolver.page..tsx} | 16 +++- .../onsite-toolkit/frontend/resolver.page.ts | 81 ------------------- .../onsite-toolkit/templates/resolver.html | 30 ------- 3 files changed, 13 insertions(+), 114 deletions(-) rename packages/onsite-toolkit/frontend/{resolver.tsx => resolver.page..tsx} (94%) delete mode 100644 packages/onsite-toolkit/frontend/resolver.page.ts diff --git a/packages/onsite-toolkit/frontend/resolver.tsx b/packages/onsite-toolkit/frontend/resolver.page..tsx similarity index 94% rename from packages/onsite-toolkit/frontend/resolver.tsx rename to packages/onsite-toolkit/frontend/resolver.page..tsx index e3aab67d4..3affec267 100644 --- a/packages/onsite-toolkit/frontend/resolver.tsx +++ b/packages/onsite-toolkit/frontend/resolver.page..tsx @@ -1,7 +1,9 @@ /* eslint-disable no-await-in-loop */ import { animated, easings, useSprings } from '@react-spring/web'; import useKey from 'react-use/lib/useKey'; -import { React, ReactDOM } from '@hydrooj/ui-default'; +import { + addPage, NamedPage, React, ReactDOM, +} from '@hydrooj/ui-default'; import { ResolverInput } from '../interface'; async function scrollTo(offset) { @@ -228,6 +230,7 @@ export function start(data: ResolverInput, options: DisplaySettings) { }, i) => { const team = teams[i]; const teamInfo = data.teams.find((idx) => idx.id === team.id); + if (!teams[i]) return Team {i} not found; if (!teamInfo) return Team info for id {team.id} not found; return
{data.problems.map((v) => { - const uncover = team?.id === selectedTeam && selectedProblem === v.id; + const uncover = team.id === selectedTeam && selectedProblem === v.id; const problemStatus = team.problems.find((idx) => idx.id === v.id); - return + return {submissions(problemStatus)} ; })} @@ -268,3 +271,10 @@ export function start(data: ResolverInput, options: DisplaySettings) { } ReactDOM.createRoot(document.getElementById('rank-list')!).render(); } + +addPage(new NamedPage(['resolver'], () => { + start(UiContext.payload, { + showAvatar: true, + showSchool: true, + }); +})); diff --git a/packages/onsite-toolkit/frontend/resolver.page.ts b/packages/onsite-toolkit/frontend/resolver.page.ts deleted file mode 100644 index 7d50134a3..000000000 --- a/packages/onsite-toolkit/frontend/resolver.page.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { addPage, NamedPage, request } from '@hydrooj/ui-default'; -import { ResolverInput } from '../interface'; -import { DisplaySettings, start } from './resolver'; - -function convertPayload(ghost: string, lock: number): ResolverInput { - const lines = ghost.split('\n'); - - const problemCount = +(lines[2].split(' ')[1]); - const teamCount = +(lines[3].split(' ')[1]); - const submissionCount = +(lines[4].split(' ')[1]); - const data: ResolverInput = { - name: lines[0].split('"')[1].split('"')[0], - frozen: +lock || 1800, - teams: [], - submissions: [], - }; - for (let i = 5 + problemCount; i < 5 + problemCount + teamCount; i++) { - const team = lines[i].match(/@t (\d+),\d+,\d+,(.*)/); - if (!team) continue; - data.teams.push({ - id: team[2].split('-')[1], - name: team[2].split('-')[1], - institution: team[2].split('-')[0], - exclude: false, - }); - } - for (let i = 5 + problemCount + teamCount; i < 5 + problemCount + teamCount + submissionCount; i++) { - // @s 3,C,1,10066,AC - const line = lines[i].split(' ')[1].split(','); - data.submissions.push({ - team: line[0], - problem: line[1], - verdict: line[4] as 'AC' | 'RJ', - time: +(line[3]), - }); - } - return data; -} - -async function loadAndStart(input: string, lock = 0, options: DisplaySettings) { - let data; - try { - if (input.startsWith('@')) data = convertPayload(input, lock); - else data = JSON.parse(input); - } catch (e) { - console.log(`load data from url. [url=${input}]`); - const res = await request.get(input, {}, { - dataType: 'text', - }); - if (res.startsWith('@')) data = convertPayload(res, lock); - else data = JSON.parse(res); - } - start(data, options); -} - -addPage(new NamedPage(['resolver'], () => { - if (UiContext.payload) { - start(UiContext.payload, { - showAvatar: true, - showSchool: true, - }); - return; - } - const current = new URL(window.location.href); - const input = current.searchParams.get('input'); - if (input) { - loadAndStart(input, +(current.searchParams.get('lock') || 0), { - showAvatar: true, - showSchool: true, - }); - } - $('#load').on('click', () => { - const src = $('#input-data').val()?.toString()?.trim(); - if (src) { - loadAndStart(src, +($('[name="lock"]').val() || 0), { - showAvatar: $('#show-avatar').prop('checked') || false, - showSchool: $('#show-school').prop('checked') || false, - }); - } - }); -})); diff --git a/packages/onsite-toolkit/templates/resolver.html b/packages/onsite-toolkit/templates/resolver.html index c693f5649..9a0c437ec 100644 --- a/packages/onsite-toolkit/templates/resolver.html +++ b/packages/onsite-toolkit/templates/resolver.html @@ -12,34 +12,4 @@
-{% if not payload %} -
-
-
-
-
-

加载数据

-
-
-
-
- -
-
-
-
-
- -
-
-
-
-
-
-{% endif %} {% endblock %}