diff --git a/backend/models/list.model.v2.js b/backend/models/list.model.v2.js index 1b4173a..9809c82 100644 --- a/backend/models/list.model.v2.js +++ b/backend/models/list.model.v2.js @@ -18,14 +18,14 @@ exports.getHouseholdStoreList = async (householdId, storeId, includeHistory = tr hl.custom_image_mime_type as image_mime_type, ${includeHistory ? ` ( - SELECT ARRAY_AGG(DISTINCT u.name) + SELECT ARRAY_AGG(added_by_labels.user_label ORDER BY added_by_labels.user_label) FROM ( - SELECT DISTINCT hlh.added_by + SELECT DISTINCT + COALESCE(NULLIF(TRIM(u.display_name), ''), NULLIF(TRIM(u.name), ''), u.username) AS user_label FROM household_list_history hlh + JOIN users u ON hlh.added_by = u.id WHERE hlh.household_list_id = hl.id - ORDER BY hlh.added_by - ) hlh - JOIN users u ON hlh.added_by = u.id + ) added_by_labels ) as added_by_users, ` : 'NULL as added_by_users,'} hl.modified_on as last_added_on, @@ -74,14 +74,14 @@ exports.getItemByName = async (householdId, storeId, itemName) => { ENCODE(hl.custom_image, 'base64') as item_image, hl.custom_image_mime_type as image_mime_type, ( - SELECT ARRAY_AGG(DISTINCT u.name) + SELECT ARRAY_AGG(added_by_labels.user_label ORDER BY added_by_labels.user_label) FROM ( - SELECT DISTINCT hlh.added_by + SELECT DISTINCT + COALESCE(NULLIF(TRIM(u.display_name), ''), NULLIF(TRIM(u.name), ''), u.username) AS user_label FROM household_list_history hlh + JOIN users u ON hlh.added_by = u.id WHERE hlh.household_list_id = hl.id - ORDER BY hlh.added_by - ) hlh - JOIN users u ON hlh.added_by = u.id + ) added_by_labels ) as added_by_users, hl.modified_on as last_added_on, hic.item_type, @@ -289,14 +289,14 @@ exports.getRecentlyBoughtItems = async (householdId, storeId) => { ENCODE(hl.custom_image, 'base64') as item_image, hl.custom_image_mime_type as image_mime_type, ( - SELECT ARRAY_AGG(DISTINCT u.name) + SELECT ARRAY_AGG(added_by_labels.user_label ORDER BY added_by_labels.user_label) FROM ( - SELECT DISTINCT hlh.added_by + SELECT DISTINCT + COALESCE(NULLIF(TRIM(u.display_name), ''), NULLIF(TRIM(u.name), ''), u.username) AS user_label FROM household_list_history hlh + JOIN users u ON hlh.added_by = u.id WHERE hlh.household_list_id = hl.id - ORDER BY hlh.added_by - ) hlh - JOIN users u ON hlh.added_by = u.id + ) added_by_labels ) as added_by_users, hl.modified_on as last_added_on FROM household_lists hl diff --git a/frontend/src/components/items/GroceryListItem.jsx b/frontend/src/components/items/GroceryListItem.jsx index 0d86042..1d85504 100644 --- a/frontend/src/components/items/GroceryListItem.jsx +++ b/frontend/src/components/items/GroceryListItem.jsx @@ -97,6 +97,11 @@ function GroceryListItem({ item, onClick, onImageAdded, onLongPress, allItems = const imageUrl = item.item_image && item.image_mime_type ? `data:${item.image_mime_type};base64,${item.item_image}` : null; + const addedByUsers = Array.isArray(item.added_by_users) + ? item.added_by_users.filter( + (name) => typeof name === "string" && name.trim().length > 0 + ) + : []; const getTimeAgo = (dateString) => { if (!dateString) return null; @@ -146,10 +151,10 @@ function GroceryListItem({ item, onClick, onImageAdded, onLongPress, allItems =
{item.item_name}
- {item.added_by_users && item.added_by_users.length > 0 && ( + {addedByUsers.length > 0 && (
{item.last_added_on && `${getTimeAgo(item.last_added_on)} -- `} - {item.added_by_users.join(" • ")} + {addedByUsers.join(" | ")}
)}