mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-27 21:55:15 -05:00
Add an option to sort by public or private builds on a user's own builds page (#1814)
* Revise weapon pool sorting: alternate kits compare equal * Fix linting errors * Added public/private build sorting option to user builds page
This commit is contained in:
@@ -714,6 +714,8 @@ export const BUILD_SORT_IDENTIFIERS = [
|
||||
"HEADGEAR_ID",
|
||||
"CLOTHES_ID",
|
||||
"SHOES_ID",
|
||||
"PUBLIC_BUILD",
|
||||
"PRIVATE_BUILD",
|
||||
] as const;
|
||||
|
||||
export type BuildSort = (typeof BUILD_SORT_IDENTIFIERS)[number];
|
||||
|
||||
@@ -349,4 +349,71 @@ BuildSorting("sorts by ALPHABETICAL_TITLE and UPDATED_AT (reverse)", () => {
|
||||
assert.equal(sortedBuilds[0].id, 3);
|
||||
});
|
||||
|
||||
BuildSorting("sorts by PUBLIC_BUILD", () => {
|
||||
const builds = [
|
||||
mockBuild({ id: 1, private: 1 }),
|
||||
mockBuild({ id: 2, private: 1 }),
|
||||
mockBuild({ id: 3, private: 0 }),
|
||||
];
|
||||
|
||||
const sortedBuilds = sortBuilds({
|
||||
builds,
|
||||
buildSorting: ["PUBLIC_BUILD"],
|
||||
weaponPool: [],
|
||||
});
|
||||
|
||||
assert.equal(sortedBuilds[0].id, 3);
|
||||
assert.equal(sortedBuilds[1].id, 1);
|
||||
assert.equal(sortedBuilds[2].id, 2);
|
||||
});
|
||||
|
||||
BuildSorting("sorts by PRIVATE_BUILD", () => {
|
||||
const builds = [
|
||||
mockBuild({ id: 1, private: 0 }),
|
||||
mockBuild({ id: 2, private: 1 }),
|
||||
mockBuild({ id: 3, private: 1 }),
|
||||
];
|
||||
|
||||
const sortedBuilds = sortBuilds({
|
||||
builds,
|
||||
buildSorting: ["PRIVATE_BUILD"],
|
||||
weaponPool: [],
|
||||
});
|
||||
|
||||
assert.equal(sortedBuilds[0].id, 2);
|
||||
assert.equal(sortedBuilds[1].id, 3);
|
||||
assert.equal(sortedBuilds[2].id, 1);
|
||||
});
|
||||
|
||||
BuildSorting("sorts by both PUBLIC_BUILD and PRIVATE_BUILD", () => {
|
||||
const builds = [
|
||||
mockBuild({ id: 1, private: 1 }),
|
||||
mockBuild({ id: 2, private: 0 }),
|
||||
mockBuild({ id: 3, private: 1 }),
|
||||
mockBuild({ id: 4, private: 0 }),
|
||||
];
|
||||
|
||||
const sortedBuilds1 = sortBuilds({
|
||||
builds,
|
||||
buildSorting: ["PUBLIC_BUILD", "PRIVATE_BUILD"],
|
||||
weaponPool: [],
|
||||
});
|
||||
|
||||
assert.equal(sortedBuilds1[0].id, 2);
|
||||
assert.equal(sortedBuilds1[1].id, 4);
|
||||
assert.equal(sortedBuilds1[2].id, 1);
|
||||
assert.equal(sortedBuilds1[3].id, 3);
|
||||
|
||||
const sortedBuilds2 = sortBuilds({
|
||||
builds,
|
||||
buildSorting: ["PRIVATE_BUILD", "PUBLIC_BUILD"],
|
||||
weaponPool: [],
|
||||
});
|
||||
|
||||
assert.equal(sortedBuilds2[0].id, 1);
|
||||
assert.equal(sortedBuilds2[1].id, 3);
|
||||
assert.equal(sortedBuilds2[2].id, 2);
|
||||
assert.equal(sortedBuilds2[3].id, 4);
|
||||
});
|
||||
|
||||
BuildSorting.run();
|
||||
|
||||
@@ -69,6 +69,29 @@ export function sortBuilds({
|
||||
|
||||
return aLowestWeaponIdx - bLowestWeaponIdx;
|
||||
},
|
||||
PUBLIC_BUILD: (a, b) => {
|
||||
const aIsPublic = a?.private === 0;
|
||||
const bIsPublic = b?.private === 0;
|
||||
if (aIsPublic && !bIsPublic) {
|
||||
return -1;
|
||||
}
|
||||
if (!aIsPublic && bIsPublic) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
PRIVATE_BUILD: (a, b) => {
|
||||
const aIsPrivate = a?.private === 1;
|
||||
const bIsPrivate = b?.private === 1;
|
||||
|
||||
if (aIsPrivate && !bIsPrivate) {
|
||||
return -1;
|
||||
}
|
||||
if (!aIsPrivate && bIsPrivate) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
};
|
||||
|
||||
return builds.slice().sort((a, b) => {
|
||||
|
||||
@@ -77,5 +77,7 @@
|
||||
"builds.sorting.MODE": "Mode",
|
||||
"builds.sorting.HEADGEAR_ID": "Headgear in-game order",
|
||||
"builds.sorting.CLOTHES_ID": "Clothing in-game order",
|
||||
"builds.sorting.SHOES_ID": "Shoes in-game order"
|
||||
"builds.sorting.SHOES_ID": "Shoes in-game order",
|
||||
"builds.sorting.PUBLIC_BUILD": "Public build",
|
||||
"builds.sorting.PRIVATE_BUILD": "Private build"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user