Skip to content
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
4 changes: 3 additions & 1 deletion webview-ui/src/components/marketplace/MarketplaceView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function MarketplaceView({ stateManager, onDone }: MarketplaceViewProps)

// Listen for state changes to know when initial data arrives
const unsubscribe = manager.onStateChange((newState) => {
if (newState.allItems.length > 0 && !hasReceivedInitialState) {
// Mark as received initial state when we get any state update
// This prevents infinite loops and ensures proper state handling
if (!hasReceivedInitialState && (newState.allItems.length > 0 || newState.displayItems !== undefined)) {
setHasReceivedInitialState(true)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export class MarketplaceViewStateManager {
// Only create new arrays if they exist and have items
const allItems = this.state.allItems.length ? [...this.state.allItems] : []
// Ensure displayItems is always an array, never undefined
const displayItems = this.state.displayItems ? [...this.state.displayItems] : []
// If displayItems is undefined or null, fall back to allItems
const displayItems = this.state.displayItems ? [...this.state.displayItems] : [...allItems]
const tags = this.state.filters.tags.length ? [...this.state.filters.tags] : []

// Create minimal new state object
Expand Down Expand Up @@ -170,11 +171,20 @@ export class MarketplaceViewStateManager {
break
}

// Calculate display items based on current filters
let newDisplayItems: MarketplaceItem[]
if (this.isFilterActive()) {
newDisplayItems = this.filterItems([...items])
} else {
// No filters active - show all items
newDisplayItems = [...items]
}

// Update allItems as source of truth
this.state = {
...this.state,
allItems: [...items],
displayItems: this.isFilterActive() ? this.filterItems([...items]) : [...items],
displayItems: newDisplayItems,
isFetching: false,
}

Expand Down Expand Up @@ -309,7 +319,17 @@ export class MarketplaceViewStateManager {
// Always use the marketplace items from the extension when they're provided
// This ensures fresh data is always displayed
const items = [...marketplaceItems]
const newDisplayItems = this.isFilterActive() ? this.filterItems(items) : items

// Calculate display items based on current filters
// If no filters are active, show all items
// If filters are active, apply filtering
let newDisplayItems: MarketplaceItem[]
if (this.isFilterActive()) {
newDisplayItems = this.filterItems(items)
} else {
// No filters active - show all items
newDisplayItems = items
}

// Update state in a single operation
this.state = {
Expand Down
Loading
Loading