ui: speed up page load

This commit is contained in:
undefined committed 2023-03-13 04:25:44 +08:00
1 parent cb741b346c
commit 67279c3745
15 files changed
+80 -106

No files matched your search

@@ -1,6 +1,4 @@
import { $ } from '@hydrooj/ui-default';
const { AutoloadPage } = window.Hydro;
import { $, addPage, AutoloadPage } from '@hydrooj/ui-default';
let loaded = false;
async function load() {
@@ -64,18 +62,12 @@ const loader = (mode) => async (element) => {
});
};
const getEles = (types) => {
const eles = [];
for (const type of types) eles.push(...$(`div[data-${type}]`).get());
return eles;
};
const getEles = (types: string[]) => types.flatMap((type) => $(`div[data-${type}]`).get());
const page = new AutoloadPage('onlyoffice', async () => {
addPage(new AutoloadPage('onlyoffice', async () => {
const all = getEles(['doc', 'docx', 'cell', 'xls', 'xlsx', 'slide', 'ppt', 'pptx']);
if (all.length) await load();
getEles(['doc', 'docx']).forEach(loader('word'));
getEles(['cell', 'xls', 'xlsx']).forEach(loader('cell'));
getEles(['slide', 'ppt', 'pptx']).forEach(loader('slide'));
});
window.Hydro.extraPages.push(page);
}));