Refactor: move sensitiveSort to extrasidebar folder
This commit is contained in:
parent
92c953cdcd
commit
245eb3c102
2 changed files with 26 additions and 1 deletions
|
|
@ -22,12 +22,12 @@ import {
|
||||||
import {
|
import {
|
||||||
classNames,
|
classNames,
|
||||||
removeCountFromString,
|
removeCountFromString,
|
||||||
sensitiveSort,
|
|
||||||
} from "../../../../utils/utils";
|
} from "../../../../utils/utils";
|
||||||
import DisclosureComponent from "../DisclosureComponent";
|
import DisclosureComponent from "../DisclosureComponent";
|
||||||
import ParentDisclosureComponent from "../ParentDisclosureComponent";
|
import ParentDisclosureComponent from "../ParentDisclosureComponent";
|
||||||
import SidebarDraggableComponent from "./sideBarDraggableComponent";
|
import SidebarDraggableComponent from "./sideBarDraggableComponent";
|
||||||
import { sortKeys } from "./utils";
|
import { sortKeys } from "./utils";
|
||||||
|
import sensitiveSort from "./utils/sensitive-sort";
|
||||||
|
|
||||||
export default function ExtraSidebar(): JSX.Element {
|
export default function ExtraSidebar(): JSX.Element {
|
||||||
const data = useTypesStore((state) => state.data);
|
const data = useTypesStore((state) => state.data);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
export default function sensitiveSort(a: string, b: string): number {
|
||||||
|
// Extract the name and number from each string using regular expressions
|
||||||
|
const regex = /(.+) \((\w+)\)/;
|
||||||
|
const matchA = a.match(regex);
|
||||||
|
const matchB = b.match(regex);
|
||||||
|
|
||||||
|
if (matchA && matchB) {
|
||||||
|
// Compare the names alphabetically
|
||||||
|
const nameA = matchA[1];
|
||||||
|
const nameB = matchB[1];
|
||||||
|
if (nameA !== nameB) {
|
||||||
|
return nameA.localeCompare(nameB);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the names are the same, compare the numbers numerically
|
||||||
|
const numberA = parseInt(matchA[2]);
|
||||||
|
const numberB = parseInt(matchB[2]);
|
||||||
|
return numberA - numberB;
|
||||||
|
} else {
|
||||||
|
// Handle cases where one or both strings do not match the expected pattern
|
||||||
|
// Simple strings are treated as pure alphabetical comparisons
|
||||||
|
return a.localeCompare(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue