Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use first sorted item in Compare view as 'firstCompareItem' rather than first unsorted item #10693

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

* Exotic class item perks will now show up in Compare suggestions
* Compare view's suggestion buttons will now use the leftmost item's perks instead of an arbitrary item if the initial compare item is removed

## 8.34.0 <span class="changelog-date">(2024-08-25)</span>

Expand Down
53 changes: 31 additions & 22 deletions src/app/compare/Compare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,34 @@ export default function Compare({ session }: { session: CompareSession }) {
setSortBetterFirst(sortedHash === newSortedHash ? !sortBetterFirst : true);
};

// If the session was started with a specific item, this is it
const initialItem = session.initialItemId
? compareItems.find((i) => i.id === session.initialItemId)
: undefined;
const firstCompareItem = compareItems[0];
// The example item is the one we'll use for generating suggestion buttons
const exampleItem = initialItem || firstCompareItem;

const items = useMemo(() => {
const sortedComparisonItems = useMemo(() => {
const comparator = sortCompareItemsComparator(
sortedHash,
sortBetterFirst,
doCompareBaseStats,
allStats,
session.initialItemId,
);
const sortedComparisonItems = compareItems.toSorted(comparator);
return (
return compareItems.toSorted(comparator);
}, [
sortedHash,
sortBetterFirst,
doCompareBaseStats,
allStats,
session.initialItemId,
compareItems,
]);

// If the session was started with a specific item, this is it
const initialItem = session.initialItemId
? compareItems.find((i) => i.id === session.initialItemId)
: undefined;
const firstCompareItem = sortedComparisonItems[0];
// The example item is the one we'll use for generating suggestion buttons
const exampleItem = initialItem || firstCompareItem;

const items = useMemo(
() => (
<CompareItems
items={sortedComparisonItems}
allStats={allStats}
Expand All @@ -186,17 +196,16 @@ export default function Compare({ session }: { session: CompareSession }) {
doCompareBaseStats={doCompareBaseStats}
initialItemId={session.initialItemId}
/>
);
}, [
allStats,
compareItems,
doCompareBaseStats,
onPlugClicked,
remove,
session.initialItemId,
sortBetterFirst,
sortedHash,
]);
),
[
sortedComparisonItems,
allStats,
doCompareBaseStats,
onPlugClicked,
remove,
session.initialItemId,
],
);

const header = (
<div className={styles.options}>
Expand Down
Loading