Skip to content

Commit 88550a3

Browse files
authored
Better Sorting for many lists with Representations (#257)
1 parent 83e1c93 commit 88550a3

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

src/lib/components/voting/RollCallVotingChair.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
2929
let members = committee?.members
3030
.filter((member) => member.present && member.representation?.type === 'DELEGATION')
31-
.sort((a, b) =>
32-
sortTranslatedCountries(a.representation!.alpha3Code!, b.representation!.alpha3Code!)
33-
);
31+
.sort((a, b) => sortTranslatedCountries(a.representation!, b.representation!));
3432
3533
let majorityAmount = $derived.by(() => {
3634
switch (majority) {

src/lib/utils/nationTranslationHelper.svelte.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,12 @@ export const getTranslatedCountryNameFromAlpha3Code = (alpha3Code?: string | nul
315315
return 'N/A';
316316
};
317317

318-
export const sortTranslatedCountries = (alpha3CodeA: string, alpha3CodeB: string) => {
319-
return getTranslatedCountryNameFromAlpha3Code(alpha3CodeA).localeCompare(
320-
getTranslatedCountryNameFromAlpha3Code(alpha3CodeB)
318+
export const sortTranslatedCountries = (
319+
a: { alpha3Code?: string | null; name?: string | null; [key: string]: any },
320+
b: { alpha3Code?: string | null; name?: string | null; [key: string]: any }
321+
) => {
322+
if (!a.alpha3Code || !a.name || !b.alpha3Code || !b.name) return 0;
323+
return (a.name ?? getTranslatedCountryNameFromAlpha3Code(a.alpha3Code)).localeCompare(
324+
b.name ?? getTranslatedCountryNameFromAlpha3Code(b.alpha3Code)
321325
);
322326
};

src/routes/app/[conferenceId]/[committeeId]/(chairs)/presence/+page.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
let countries = $derived(
3333
committee?.members
3434
.filter((member) => member.representation?.type === 'DELEGATION')
35-
.sort((a, b) =>
36-
sortTranslatedCountries(a.representation!.alpha3Code!, b.representation!.alpha3Code!)
37-
) ?? []
35+
.sort((a, b) => sortTranslatedCountries(a.representation!, b.representation!)) ?? []
3836
);
3937
4038
let nsas = $derived(

src/routes/app/[conferenceId]/[committeeId]/(presentation)/+page.svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@
174174
committeeId={data.committeeId}
175175
members={committee.members
176176
.filter((x) => x.representation?.type === 'DELEGATION')
177-
.sort((a, b) =>
178-
sortTranslatedCountries(a.representation!.alpha3Code!, b.representation!.alpha3Code!)
179-
)}
177+
.sort((a, b) => sortTranslatedCountries(a.representation!, b.representation!))}
180178
/>
181179

182180
<ShowOfHandsVotingPresentation committeeSettings={$committeeSettings} />

0 commit comments

Comments
 (0)