Skip to content

Commit

Permalink
Leaderboard show all compared values for exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal committed Sep 13, 2023
1 parent 0e0ef2f commit 3a34971
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,24 @@
})) ?? [];
}
let valuesComparedInExcludeMode = [];
$: if (isBeingCompared && filterExcludeMode) {
let count = 0;
valuesComparedInExcludeMode = values
.filter((value) => {
if (!activeValues.includes(value.label) && count < 3) {
count++;
return true;
}
return false;
})
.map((value) => value.label);
}
// get all values that are selected but not visible.
// we'll put these at the bottom w/ a divider.
$: selectedValuesThatAreBelowTheFold = activeValues
?.concat(valuesComparedInExcludeMode)
?.filter((label) => {
return (
// the value is visible within the fold.
Expand Down Expand Up @@ -227,11 +242,16 @@
filterExcludeMode
);
$: defaultComparisonsPresentInAboveFold =
aboveTheFoldItems?.filter((item) => item.defaultComparedIndex >= 0)
?.length || 0;
$: belowTheFoldItems = prepareLeaderboardItemData(
selectedValuesThatAreBelowTheFold,
activeValues,
comparisonMap,
filterExcludeMode
filterExcludeMode,
defaultComparisonsPresentInAboveFold
);
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ export function prepareLeaderboardItemData(
values: { value: number; label: string | number }[],
selectedValues: (string | number)[],
comparisonMap: Map<string | number, number>,
excludeMode: boolean
excludeMode: boolean,
initalCount = 0
): LeaderboardItemData[] {
let count = 0;
let count = initalCount;

return values.map((v) => {
const selectedIndex = selectedValues.findIndex(
Expand All @@ -47,6 +48,7 @@ export function prepareLeaderboardItemData(

// Tag values which will be compared by default
let defaultComparedIndex = -1;

if (!excludeMode && count < 3 && !selectedValues.length) {
defaultComparedIndex = count;
count = count + 1;
Expand Down

0 comments on commit 3a34971

Please sign in to comment.