From 2fb9f75f35648250ab662f0674583a3aa1e8bd30 Mon Sep 17 00:00:00 2001 From: Mark Street <22226349+mkst@users.noreply.github.com> Date: Wed, 20 Mar 2024 20:42:11 +0000 Subject: [PATCH] Swap usePlatforms for usePresets/usePreset (#1139) * Swap usePlatforms for usePresets/usePreset * Don't emit warning if serverPresets is empty --- frontend/src/components/ScratchList.tsx | 9 ++---- .../src/components/compiler/PresetSelect.tsx | 4 +-- frontend/src/lib/api.ts | 29 ++++++++++++------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/ScratchList.tsx b/frontend/src/components/ScratchList.tsx index 60e5f0a6..0da4e3c4 100644 --- a/frontend/src/components/ScratchList.tsx +++ b/frontend/src/components/ScratchList.tsx @@ -82,9 +82,8 @@ export function getMatchPercentString(scratch: api.TerseScratch) { export function ScratchItem({ scratch, children } : { scratch: api.TerseScratch, children?: ReactNode }) { const compilersTranslation = useTranslation("compilers") const compilerName = compilersTranslation.t(scratch.compiler as any) - const serverPresets = api.usePlatforms()[scratch.platform].presets const matchPercentString = getMatchPercentString(scratch) - const preset = serverPresets.find(p => p.id === scratch.preset) + const preset = api.usePreset(scratch.preset) const presetName = preset?.name const presetOrCompiler = presetName ? @@ -124,9 +123,8 @@ export function ScratchItem({ scratch, children } : { scratch: api.TerseScratch, export function ScratchItemNoOwner({ scratch }: { scratch: api.TerseScratch }) { const compilersTranslation = useTranslation("compilers") const compilerName = compilersTranslation.t(scratch.compiler) - const serverPresets = api.usePlatforms()[scratch.platform].presets const matchPercentString = getMatchPercentString(scratch) - const preset = serverPresets.find(p => p.id === scratch.preset) + const preset = api.usePreset(scratch.preset) const presetName = preset?.name const presetOrCompiler = presetName ? @@ -159,9 +157,8 @@ export function ScratchItemNoOwner({ scratch }: { scratch: api.TerseScratch }) { export function ScratchItemPlatformList({ scratch }: { scratch: api.TerseScratch }) { const compilersTranslation = useTranslation("compilers") const compilerName = compilersTranslation.t(scratch.compiler) - const serverPresets = api.usePlatforms()[scratch.platform].presets const matchPercentString = getMatchPercentString(scratch) - const preset = serverPresets.find(p => p.id === scratch.preset) + const preset = api.usePreset(scratch.preset) const presetName = preset?.name const presetOrCompiler = presetName ? diff --git a/frontend/src/components/compiler/PresetSelect.tsx b/frontend/src/components/compiler/PresetSelect.tsx index 19b51266..0578220d 100644 --- a/frontend/src/components/compiler/PresetSelect.tsx +++ b/frontend/src/components/compiler/PresetSelect.tsx @@ -22,11 +22,11 @@ export default function PresetSelect({ className, platform, presetId, setPreset, serverPresets?: api.Preset[] }) { if (!serverPresets) - serverPresets = api.usePlatforms()[platform].presets + serverPresets = api.usePresets(platform) const selectedPreset = serverPresets.find(p => p.id === presetId) - if (!selectedPreset && presetId !== undefined && presetId !== null) + if (serverPresets.length > 0 && typeof presetId === "number" && !selectedPreset) console.warn(`Scratch.preset == '${presetId}' but no preset with that id was found.`) return