Skip to content

Commit

Permalink
Update exclude mode comparison icon for leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal committed Sep 13, 2023
1 parent f028954 commit 118c6c7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@
$: aboveTheFoldItems = prepareLeaderboardItemData(
values.slice(0, slice),
activeValues,
comparisonMap
comparisonMap,
filterExcludeMode
);
$: belowTheFoldItems = prepareLeaderboardItemData(
selectedValuesThatAreBelowTheFold,
activeValues,
comparisonMap
comparisonMap,
filterExcludeMode
);
</script>

Expand All @@ -254,10 +256,9 @@
{#if values}
<div class="rounded-b border-gray-200 surface text-gray-800">
<!-- place the leaderboard entries that are above the fold here -->
{#each aboveTheFoldItems as itemData, index (itemData.label)}
{#each aboveTheFoldItems as itemData (itemData.label)}
<LeaderboardListItem
{itemData}
{index}
{showContext}
{atLeastOneActive}
{isBeingCompared}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
export let selectionIndex: number;
export let excluded = false;
export let isBeingCompared = false;
export let atLeastOneActive = false;
export let index: number;
export let defaultComparedIndex: number;
$: selected = selectionIndex >= 0;
Expand All @@ -20,10 +19,10 @@
</script>

<div style:width="22px" class="grid place-items-center">
{#if selected && isBeingCompared}
{#if selected && !excluded && isBeingCompared}
<CheckCircle className={getColor(selectionIndex)} size="18px" />
{:else if isBeingCompared && !atLeastOneActive && index < 3}
<Circle className={getColor(index)} size="16px" />
{:else if isBeingCompared && defaultComparedIndex >= 0}
<Circle className={getColor(defaultComparedIndex)} size="16px" />
{:else if selected && !excluded}
<Check size="20px" />
{:else if selected && excluded}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
export let atLeastOneActive = false;
export let isBeingCompared = false;
export let index = -1;
export let formattedValue: string;
export let filterExcludeMode;
Expand Down Expand Up @@ -137,10 +136,9 @@
>
<LeaderboardItemFilterIcon
{isBeingCompared}
{index}
{atLeastOneActive}
{excluded}
selectionIndex={itemData.selectedIndex}
selectionIndex={itemData?.selectedIndex}
defaultComparedIndex={itemData?.defaultComparedIndex}
/>
<BarAndLabel
{color}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,39 @@ export type LeaderboardItemData = {
// or excluded; for that we need to know the leaderboard's
// include/exclude state
selectedIndex: number;
defaultComparedIndex: number;
};

export function prepareLeaderboardItemData(
values: { value: number; label: string | number }[],
selectedValues: (string | number)[],
comparisonMap: Map<string | number, number>
comparisonMap: Map<string | number, number>,
excludeMode: boolean
): LeaderboardItemData[] {
let count = 0;

return values.map((v) => {
const selectedIndex = selectedValues.findIndex(
(value) => value === v.label
);
const comparisonValue = comparisonMap.get(v.label);

// Tag values which will be compared by default
let defaultComparedIndex = -1;
if (!excludeMode && count < 3 && !selectedValues.length) {
defaultComparedIndex = count;
count = count + 1;
} else if (excludeMode && count < 3) {
if (selectedIndex === -1) {
defaultComparedIndex = count;
count += 1;
}
}
return {
...v,
selectedIndex,
comparisonValue,
defaultComparedIndex,
};
});
}
Expand Down

0 comments on commit 118c6c7

Please sign in to comment.