feat: implement sorting functionality for skins using default windows sorting algotythm
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
const specialOrder = "'-!#$%&(),;@[]^_`{}~+=";
|
||||
|
||||
const priority = Object.fromEntries([...specialOrder].map((c, i) => [c, i]));
|
||||
|
||||
const osuSkinsCollator = new Intl.Collator(undefined, {
|
||||
numeric: true,
|
||||
sensitivity: 'base',
|
||||
});
|
||||
|
||||
export const sortSkins = (skins: { name: string, author: string | undefined, modified: number}[]) =>
|
||||
skins.sort((a, b) => {
|
||||
const pa = priority[a.name[0]];
|
||||
const pb = priority[b.name[0]];
|
||||
|
||||
if (pa !== undefined || pb !== undefined) {
|
||||
if (pa === undefined) return 1;
|
||||
if (pb === undefined) return -1;
|
||||
return pa - pb;
|
||||
}
|
||||
|
||||
return osuSkinsCollator.compare(a.name, b.name);
|
||||
});
|
||||
@@ -114,6 +114,7 @@
|
||||
import { sileo } from 'sileo';
|
||||
import Check from '@lucide/svelte/icons/check';
|
||||
import ScrollContainer from '@/components/ui/scroll-container/ScrollContainer.svelte';
|
||||
import { sortSkins } from '@/sort';
|
||||
|
||||
let selectedView = $state('home');
|
||||
let progress = $state(-1);
|
||||
@@ -1556,9 +1557,7 @@
|
||||
out:fly={{ duration: $reduceAnimations ? 0 : 400, y: -5, opacity: 0 }}
|
||||
>
|
||||
{#if $skins.length > 0}
|
||||
{@const skinsSorted = $skins.sort((a, b) =>
|
||||
a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' })
|
||||
)}
|
||||
{@const skinsSorted = sortSkins($skins)}
|
||||
<ScrollContainer
|
||||
class="flex flex-col max-h-[100vh] overflow-y-auto items-center gap-4 p-16 w-full"
|
||||
topOffset={35}
|
||||
|
||||
Reference in New Issue
Block a user