Skip to content

Commit

Permalink
Sort languages in editor selector
Browse files Browse the repository at this point in the history
  • Loading branch information
x0k committed Aug 27, 2024
1 parent 07ac305 commit 87e4f35
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion apps/ppp/src/containers/test-editor/test-editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
const { pageLang, problemCategory, contentId, testCases, runtimes, children }: Props<Langs, Input, Output> = $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");
}
Expand Down
5 changes: 3 additions & 2 deletions apps/ppp/src/pages/editor/_editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
}
Expand Down Expand Up @@ -162,7 +163,7 @@
let descriptionDialogElement: HTMLDialogElement
let describedLanguage = $state(defaultLang);
let Description = $derived(RUNTIMES[describedLanguage].Description)
let Description = $derived(DESCRIPTIONS[describedLanguage])
</script>

<div class="h-screen flex flex-col overflow-hidden">
Expand Down
24 changes: 6 additions & 18 deletions apps/ppp/src/pages/editor/_runtimes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Component } from "svelte";
import type { CompilerFactory } from "compiler";
import { makeRemoteCompilerFactory } from "compiler/actor";

Expand All @@ -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';
Expand All @@ -27,53 +25,43 @@ import csProgram from './_program.cs?raw';
interface Runtime {
initialValue: string;
compilerFactory: CompilerFactory;
Description: Component;
}

export const RUNTIMES: Record<Language, Runtime> = {
[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],
},
};

0 comments on commit 87e4f35

Please sign in to comment.