From f78d2a8a95206d81fccfa8f79fbcfaea4dd7b6c5 Mon Sep 17 00:00:00 2001 From: Alex Norman Date: Wed, 3 Jul 2024 11:18:03 -0700 Subject: [PATCH] update preset sort when initial changes --- src/models/instance.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/models/instance.ts b/src/models/instance.ts index ac6c5dcf..84653d31 100644 --- a/src/models/instance.ts +++ b/src/models/instance.ts @@ -25,6 +25,16 @@ export type InstanceStateProps = { const collator = new Intl.Collator("en-US"); +function sortPresets(left: PresetRecord, right: PresetRecord) : number { + if (left.initial) { + return -1; + } + if (right.initial) { + return 1; + } + return collator.compare(left.name, right.name); +} + export class InstanceStateRecord extends ImmuRecord({ index: 0, @@ -112,13 +122,7 @@ export class InstanceStateRecord extends ImmuRecord({ const pr = PresetRecord.fromDescription(name, name === initial, name === latest); map.set(pr.id, pr); } - }).sort((left: PresetRecord, right: PresetRecord) => { - if (left.initial) - {return -1;} - if (right.initial) - {return 1;} - return collator.compare(left.name, right.name); - }); + }).sort(sortPresets); } public setPresetLatest(latest: string): InstanceStateRecord { @@ -126,7 +130,7 @@ export class InstanceStateRecord extends ImmuRecord({ } public setPresetInitial(initial: string): InstanceStateRecord { - return this.set("presets", this.presets.map(preset => preset.setInitial(preset.name === initial))).set("presetInitial", initial); + return this.set("presetInitial", initial).set("presets", this.presets.map(preset => preset.setInitial(preset.name === initial)).sort(sortPresets)); } public updatePresets(entries: OSCQueryRNBOInstancePresetEntries): InstanceStateRecord {