From 87e4f3559d20e6c1be98512166082eddb114045c Mon Sep 17 00:00:00 2001 From: Krasilnikov Roman Date: Tue, 27 Aug 2024 22:41:05 +0300 Subject: [PATCH] Sort languages in editor selector --- .../containers/test-editor/test-editor.svelte | 2 +- apps/ppp/src/pages/editor/_editor.svelte | 5 ++-- apps/ppp/src/pages/editor/_runtimes.ts | 24 +++++-------------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/apps/ppp/src/containers/test-editor/test-editor.svelte b/apps/ppp/src/containers/test-editor/test-editor.svelte index 11a1a84..d51bb90 100644 --- a/apps/ppp/src/containers/test-editor/test-editor.svelte +++ b/apps/ppp/src/containers/test-editor/test-editor.svelte @@ -29,7 +29,7 @@ const { pageLang, problemCategory, contentId, testCases, runtimes, children }: Props = $props(); const t = useTranslations(pageLang); - const languages = Object.keys(runtimes) as Langs[]; + const languages = Object.keys(runtimes).sort() as Langs[]; if (languages.length === 0) { throw new Error("No test runner factories provided"); } diff --git a/apps/ppp/src/pages/editor/_editor.svelte b/apps/ppp/src/pages/editor/_editor.svelte index fbeed31..21d4994 100644 --- a/apps/ppp/src/pages/editor/_editor.svelte +++ b/apps/ppp/src/pages/editor/_editor.svelte @@ -14,6 +14,7 @@ import { Label, type Lang } from '@/i18n'; import { createSyncStorage } from "@/adapters/storage"; import { MONACO_LANGUAGE_ID } from "@/adapters/monaco"; + import { DESCRIPTIONS } from '@/adapters/runtime/descriptions' import Dropdown from '@/components/dropdown.svelte'; import { Editor, @@ -35,7 +36,7 @@ const { lang: pageLang }: Props = $props(); - const languages = Object.keys(RUNTIMES) as Language[]; + const languages = Object.keys(RUNTIMES).sort() as Language[]; if (languages.length === 0) { throw new Error("No test runner factories provided"); } @@ -162,7 +163,7 @@ let descriptionDialogElement: HTMLDialogElement let describedLanguage = $state(defaultLang); - let Description = $derived(RUNTIMES[describedLanguage].Description) + let Description = $derived(DESCRIPTIONS[describedLanguage])
diff --git a/apps/ppp/src/pages/editor/_runtimes.ts b/apps/ppp/src/pages/editor/_runtimes.ts index 1858754..5cab9d1 100644 --- a/apps/ppp/src/pages/editor/_runtimes.ts +++ b/apps/ppp/src/pages/editor/_runtimes.ts @@ -1,4 +1,3 @@ -import type { Component } from "svelte"; import type { CompilerFactory } from "compiler"; import { makeRemoteCompilerFactory } from "compiler/actor"; @@ -12,7 +11,6 @@ import RustWorker from "@/adapters/runtime/rust/worker?worker"; import GleamWorker from "@/adapters/runtime/gleam/worker?worker"; import JavaWorker from "@/adapters/runtime/java/worker?worker"; import { makeDotnetCompiler } from '@/adapters/runtime/dotnet/compiler-factory' -import { DESCRIPTIONS } from "@/adapters/runtime/descriptions"; import phpProgram from './_program.php?raw'; import tsProgram from './_program.ts?raw'; @@ -27,53 +25,43 @@ import csProgram from './_program.cs?raw'; interface Runtime { initialValue: string; compilerFactory: CompilerFactory; - Description: Component; } export const RUNTIMES: Record = { - [Language.PHP]: { - initialValue: phpProgram, - compilerFactory: makeRemoteCompilerFactory(PhpWorker), - Description: DESCRIPTIONS[Language.PHP], + [Language.JavaScript]: { + initialValue: jsProgram, + compilerFactory: makeRemoteCompilerFactory(JsWorker), }, [Language.TypeScript]: { initialValue: tsProgram, compilerFactory: makeRemoteCompilerFactory(TsWorker), - Description: DESCRIPTIONS[Language.TypeScript], }, [Language.Python]: { initialValue: pythonProgram, compilerFactory: makeRemoteCompilerFactory(PythonWorker), - Description: DESCRIPTIONS[Language.Python], }, - [Language.JavaScript]: { - initialValue: jsProgram, - compilerFactory: makeRemoteCompilerFactory(JsWorker), - Description: DESCRIPTIONS[Language.JavaScript], + [Language.PHP]: { + initialValue: phpProgram, + compilerFactory: makeRemoteCompilerFactory(PhpWorker), }, [Language.Go]: { initialValue: goProgram, compilerFactory: makeRemoteCompilerFactory(GoWorker), - Description: DESCRIPTIONS[Language.Go], }, [Language.Rust]: { initialValue: rustProgram, compilerFactory: makeRemoteCompilerFactory(RustWorker), - Description: DESCRIPTIONS[Language.Rust], }, [Language.Gleam]: { initialValue: gleamProgram, compilerFactory: makeRemoteCompilerFactory(GleamWorker), - Description: DESCRIPTIONS[Language.Gleam], }, [Language.CSharp]: { initialValue: csProgram, compilerFactory: makeDotnetCompiler, - Description: DESCRIPTIONS[Language.CSharp], }, [Language.Java]: { initialValue: javaProgram, compilerFactory: makeRemoteCompilerFactory(JavaWorker), - Description: DESCRIPTIONS[Language.Java], }, };