fix(inventory): refactor renderInventory() to match other render functions

Root cause: renderInventory() signature mismatch - was expecting parameters
but called without any, resulting in empty/broken rendering.

Changes:
- Rename renderInventory(inventory, options) → generateInventoryHTML() (internal)
- Create new renderInventory() with no parameters (like renderUserStats, etc.)
- New function gets container from state, data from settings, updates DOM directly
- Import getInventoryRenderOptions() to get current tab/collapse state
- Keep updateInventoryDisplay() for use by inventoryActions module

Now matches the pattern used by all other render modules, fixing the bug where
inventory section appeared empty in the panel.
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-10-17 15:46:13 +11:00
parent 2566d97dfb
commit abd3ade30e
+29 -6
View File
@@ -3,7 +3,8 @@
* Handles UI rendering for inventory v2 system * Handles UI rendering for inventory v2 system
*/ */
import { extensionSettings } from '../../core/state.js'; import { extensionSettings, $inventoryContainer } from '../../core/state.js';
import { getInventoryRenderOptions } from '../interaction/inventoryActions.js';
// Type imports // Type imports
/** @typedef {import('../../types/inventory.js').InventoryV2} InventoryV2 */ /** @typedef {import('../../types/inventory.js').InventoryV2} InventoryV2 */
@@ -141,14 +142,14 @@ export function renderAssetsView(assets) {
} }
/** /**
* Main inventory rendering function * Generates inventory HTML (internal helper)
* @param {InventoryV2} inventory - Inventory data to render * @param {InventoryV2} inventory - Inventory data to render
* @param {Object} options - Rendering options * @param {Object} options - Rendering options
* @param {string} options.activeSubTab - Currently active sub-tab ('onPerson', 'stored', 'assets') * @param {string} options.activeSubTab - Currently active sub-tab ('onPerson', 'stored', 'assets')
* @param {string[]} options.collapsedLocations - Collapsed storage locations * @param {string[]} options.collapsedLocations - Collapsed storage locations
* @returns {string} Complete HTML for inventory tab content * @returns {string} Complete HTML for inventory tab content
*/ */
export function renderInventory(inventory, options = {}) { function generateInventoryHTML(inventory, options = {}) {
const { const {
activeSubTab = 'onPerson', activeSubTab = 'onPerson',
collapsedLocations = [] collapsedLocations = []
@@ -205,9 +206,9 @@ export function renderInventory(inventory, options = {}) {
} }
/** /**
* Updates the inventory display in the DOM * Updates the inventory display in the DOM (used by inventoryActions)
* @param {string} containerId - ID of container element to update * @param {string} containerId - ID of container element to update
* @param {Object} options - Rendering options (passed to renderInventory) * @param {Object} options - Rendering options (passed to generateInventoryHTML)
*/ */
export function updateInventoryDisplay(containerId, options = {}) { export function updateInventoryDisplay(containerId, options = {}) {
const container = document.getElementById(containerId); const container = document.getElementById(containerId);
@@ -217,10 +218,32 @@ export function updateInventoryDisplay(containerId, options = {}) {
} }
const inventory = extensionSettings.userStats.inventory; const inventory = extensionSettings.userStats.inventory;
const html = renderInventory(inventory, options); const html = generateInventoryHTML(inventory, options);
container.innerHTML = html; container.innerHTML = html;
} }
/**
* Main inventory rendering function (matches pattern of other render functions)
* Gets data from state/settings and updates DOM directly.
* Call this after AI generation, character changes, or swipes.
*/
export function renderInventory() {
// Early return if container doesn't exist or section is hidden
if (!$inventoryContainer || !extensionSettings.showInventory) {
return;
}
// Get inventory data from settings
const inventory = extensionSettings.userStats.inventory;
// Get current render options (active tab, collapsed locations)
const options = getInventoryRenderOptions();
// Generate HTML and update DOM
const html = generateInventoryHTML(inventory, options);
$inventoryContainer.html(html);
}
/** /**
* Escapes HTML special characters to prevent XSS * Escapes HTML special characters to prevent XSS
* @param {string} text - Text to escape * @param {string} text - Text to escape