Skip to content

Commit 1fbf3dd

Browse files
Copilotbhollis
andcommitted
Fix is:owned filter implementation following code review feedback
Co-authored-by: bhollis <[email protected]>
1 parent 6a6368f commit 1fbf3dd

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/app/search/items/item-filter-types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { D2ManifestDefinitions } from 'app/destiny2/d2-definitions';
33
import { DimLanguage } from 'app/i18n';
44
import { TagValue } from 'app/inventory/dim-item-info';
55
import { DimItem } from 'app/inventory/item-types';
6-
import { OwnedItemsInfo } from 'app/inventory/selectors';
76
import { DimStore } from 'app/inventory/store-types';
87
import { Loadout } from 'app/loadout/loadout-types';
98
import { LoadoutsByItem } from 'app/loadout/selectors';
@@ -32,7 +31,6 @@ export interface FilterContext {
3231
language: DimLanguage;
3332
customStats: Settings['customStats'];
3433
d2Definitions: D2ManifestDefinitions | undefined;
35-
ownedItemsInfo: OwnedItemsInfo;
3634
}
3735

3836
/**

src/app/search/items/item-search-filter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getNotesSelector,
1414
getTagSelector,
1515
newItemsSelector,
16-
ownedItemsSelector,
1716
sortedStoresSelector,
1817
} from 'app/inventory/selectors';
1918
import { DimStore } from 'app/inventory/store-types';
@@ -141,7 +140,6 @@ const filterContextSelector = createSelector(
141140
languageSelector,
142141
customStatsSelector,
143142
d2ManifestSelector,
144-
ownedItemsSelector,
145143
makeFilterContext,
146144
);
147145

@@ -158,7 +156,6 @@ function makeFilterContext(
158156
language: DimLanguage,
159157
customStats: Settings['customStats'],
160158
d2Definitions: D2ManifestDefinitions | undefined,
161-
ownedItemsInfo: import('app/inventory/selectors').OwnedItemsInfo,
162159
): FilterContext {
163160
return {
164161
stores,
@@ -173,7 +170,6 @@ function makeFilterContext(
173170
customStats,
174171
wishListsByHash,
175172
d2Definitions,
176-
ownedItemsInfo,
177173
};
178174
}
179175

src/app/search/items/search-filters/simple.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,33 @@ const simpleFilters: ItemFilterDefinition[] = [
9797
},
9898
{
9999
keywords: 'owned',
100-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
101-
description: 'Filter.Owned' as any,
100+
description: tl('Filter.Owned'),
102101
filter:
103-
({ ownedItemsInfo, currentStore }) =>
102+
({ allItems, currentStore }) =>
104103
(item) => {
104+
// Build ownership info from allItems, similar to ownedItemsSelector
105+
const storeSpecificBuckets = [BucketHashes.Emblems, BucketHashes.Quests];
106+
const accountWideOwned = new Set<number>();
107+
const storeSpecificOwned: { [owner: string]: Set<number> } = {};
108+
109+
for (const ownedItem of allItems) {
110+
if (storeSpecificBuckets.includes(ownedItem.bucket.hash)) {
111+
if (!storeSpecificOwned[ownedItem.owner]) {
112+
storeSpecificOwned[ownedItem.owner] = new Set();
113+
}
114+
storeSpecificOwned[ownedItem.owner].add(ownedItem.hash);
115+
} else {
116+
accountWideOwned.add(ownedItem.hash);
117+
}
118+
}
119+
105120
// Check if item is owned globally (account-wide)
106-
if (ownedItemsInfo.accountWideOwned.has(item.hash)) {
121+
if (accountWideOwned.has(item.hash)) {
107122
return true;
108123
}
109124
// Check if item is owned by the current store (for store-specific items like emblems/quests)
110-
if (currentStore && ownedItemsInfo.storeSpecificOwned[currentStore.id]) {
111-
return ownedItemsInfo.storeSpecificOwned[currentStore.id].has(item.hash);
125+
if (currentStore && storeSpecificOwned[currentStore.id]) {
126+
return storeSpecificOwned[currentStore.id].has(item.hash);
112127
}
113128
return false;
114129
},

0 commit comments

Comments
 (0)