Sort proto messages and files, fix export state when a configuration is modified

This commit is contained in:
2024-09-04 19:01:12 +09:30
parent db9e63bac4
commit e3024bdfae
2 changed files with 11 additions and 2 deletions

View File

@@ -36,6 +36,8 @@ interface FileNode {
level: number;
}
const collator = new Intl.Collator(undefined, { numeric: true });
@Component({
selector: 'app-file-tree',
standalone: true,
@@ -201,7 +203,7 @@ export class FileTreeComponent implements OnInit, OnDestroy {
}
private sortFiles = (a: { name?: string }, b: { name?: string }) =>
new Intl.Collator(undefined, { numeric: true }).compare(a.name!, b.name!);
collator.compare(a.name!, b.name!);
private recursiveSort(files: FileOrFolder[]) {
for (const file of files) {

View File

@@ -25,6 +25,8 @@ import { DefinitionEditorComponent } from './definition-editor/definition-editor
declare const __TAURI__: any;
const collator = new Intl.Collator(undefined, { numeric: true });
@Component({
selector: 'app-proto-definition-selector',
standalone: true,
@@ -195,7 +197,7 @@ export class ProtoDefinitionSelectorComponent {
}
const parsed = JSON.parse(fileContents) as ProtoMessage[];
this.allProtoFiles.set(
parsed.sort((a, b) => a.name.localeCompare(b.name))
parsed.sort((a, b) => collator.compare(a.name, b.name))
);
this.selectedDefinition.set(this.allProtoFiles());
this.currentFiles.set([]);
@@ -210,6 +212,9 @@ export class ProtoDefinitionSelectorComponent {
]);
}
}
this.currentFiles.update((currentFiles) =>
[...currentFiles].sort(collator.compare)
);
} catch (err) {
console.error(err);
this.snackBar.open(
@@ -242,6 +247,8 @@ export class ProtoDefinitionSelectorComponent {
})
.afterClosed()
.subscribe(() => {
// Force signals to update since state is mutated in place
this.allProtoFiles.update((files) => files.slice());
if (
protoMessage ===
this.messageSelector()?.selectedOptions.selected[0]?.value