From 3edc425a52d5708a77f75614f494ea5dbe8bffb7 Mon Sep 17 00:00:00 2001 From: undefined Date: Sun, 10 Jul 2022 22:27:58 +0800 Subject: [PATCH] ui: fix icon display --- .eslintrc.yaml | 3 +++ packages/ui-default/.eslintrc.js | 2 ++ packages/ui-default/handler.ts | 29 ++++++++++++++--------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 3019a09e..390efc8c 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -17,6 +17,8 @@ ignorePatterns: - public/ - '*.spec.ts' rules: + '@typescript-eslint/no-shadow': 1 + function-call-argument-newline: 0 react/function-component-definition: 0 '@typescript-eslint/dot-notation': 0 @@ -106,6 +108,7 @@ rules: no-plusplus: 0 no-restricted-syntax: 0 no-return-await: 0 + no-shadow: 0 no-underscore-dangle: 0 prefer-destructuring: 0 function-paren-newline: 0 diff --git a/packages/ui-default/.eslintrc.js b/packages/ui-default/.eslintrc.js index 20983ca6..6306c4bf 100644 --- a/packages/ui-default/.eslintrc.js +++ b/packages/ui-default/.eslintrc.js @@ -53,6 +53,8 @@ module.exports = { '@typescript-eslint/no-implied-eval': 'off', '@typescript-eslint/no-throw-literal': 'off', '@typescript-eslint/return-await': 'off', + '@typescript-eslint/no-shadow': 'warn', + 'no-shadow': 'off', // FIXME A bug with eslint-parser 'template-curly-spacing': 'off', diff --git a/packages/ui-default/handler.ts b/packages/ui-default/handler.ts index cd96262b..eb833035 100644 --- a/packages/ui-default/handler.ts +++ b/packages/ui-default/handler.ts @@ -13,6 +13,7 @@ import problem from 'hydrooj/src/model/problem'; import * as setting from 'hydrooj/src/model/setting'; import esbuild from 'esbuild'; import { tmpdir } from 'os'; +import { UiContextBase } from 'hydrooj/src/service/layers/base'; import markdown from './backendlib/markdown'; declare module 'hydrooj/src/interface' { @@ -24,6 +25,13 @@ declare module 'hydrooj/src/interface' { 'ui-default.nav_logo_dark_2x': string; } } +declare module 'hydrooj/src/service/layers/base' { + interface UiContextBase { + nav_logo_dark: string; + nav_logo_dark_2x: string; + constantVersion: string; + } +} let constant = ''; let hash = ''; @@ -46,27 +54,18 @@ async function run() { if (build.errors.length) console.error(build.errors); if (build.warnings.length) console.warn(build.warnings); const pages = build.outputFiles.map((i) => i.text); - const payload = [...pages]; - const [logo, logo2x] = system.getMany([ - 'ui-default.nav_logo_dark', 'ui-default.nav_logo_dark_2x', - ]); - const res = []; - res.push(`window.LANGS=${JSON.stringify(setting.langs)};`); - if (logo) res.push(`UiContext.nav_logo_dark="${logo}";`); - if (logo2x) res.push(`UiContext.nav_logo_dark_2x="${logo2x}";`); - payload.unshift(res.join('\n')); + const payload = [`window.LANGS=${JSON.stringify(setting.langs)};`, ...pages]; const c = crypto.createHash('sha1'); c.update(JSON.stringify(payload)); const version = c.digest('hex'); constant = JSON.stringify(payload); - hash = version; + UiContextBase.constantVersion = hash = version; + + [UiContextBase.nav_logo_dark, UiContextBase.nav_logo_dark_2x] = system.getMany([ + 'ui-default.nav_logo_dark', 'ui-default.nav_logo_dark_2x', + ]); } -const versionHandler = (that) => { - that.UiContext.constantVersion = hash; -}; -bus.on('handler/after', versionHandler); -bus.on('handler/error', versionHandler); bus.on('app/started', run); bus.on('system/setting', run);