Skip to content

Commit

Permalink
Allow users to select 'Custom' preset again (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkst authored Feb 19, 2024
1 parent 633b0f5 commit 71004bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
21 changes: 14 additions & 7 deletions frontend/src/components/compiler/CompilerOpts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,20 @@ export default function CompilerOpts({ platform, value, onChange, diffLabel, onD
}

const setPreset = (preset: api.Preset) => {
onChange({
compiler: preset.compiler,
compiler_flags: preset.compiler_flags,
diff_flags: preset.diff_flags,
libraries: preset.libraries,
preset: preset.id,
})
if (preset) {
onChange({
compiler: preset.compiler,
compiler_flags: preset.compiler_flags,
diff_flags: preset.diff_flags,
libraries: preset.libraries,
preset: preset.id,
})
} else {
// "Custom" preset selected
onChange({
preset: null,
})
}
}

const setLibraries = (libraries: Library[]) => {
Expand Down
12 changes: 4 additions & 8 deletions frontend/src/components/compiler/PresetSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import * as api from "@/lib/api"

import Select from "../Select2"

function presetsToOptions(presets: api.Preset[], addCustom: boolean): { [key: string]: string } {
function presetsToOptions(presets: api.Preset[]): { [key: string]: string } {
const options = {}

if (addCustom) {
options["Custom"] = "Custom"
}
options["Custom"] = "Custom"

for (const preset of presets) {
options[preset.name] = preset.name
Expand All @@ -33,12 +31,10 @@ export default function PresetSelect({ className, platform, presetId, setPreset,

return <Select
className={className}
options={presetsToOptions(serverPresets, !selectedPreset)}
options={presetsToOptions(serverPresets)}
value={selectedPreset?.name || "Custom"}
onChange={name => {
const preset = serverPresets.find(p => p.name === name)
if (preset)
setPreset(preset)
setPreset(serverPresets.find(p => p.name === name))
}}
/>
}

0 comments on commit 71004bb

Please sign in to comment.