mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-21 22:46:32 +00:00
fix(client): stop shared items counting towards the recipient bag weight
An item shared through the sharing tier is visible to its recipients but carried by its owner. The bag totals filtered on bag_id alone, so every recipient saw the owner's weight added to their own load — which is exactly the situation that tier exists for (one person brings the first-aid kit). Filtering by owner_id, as the issue suggests, would have broken more than it fixed: owner_id is stamped on every item including Common ones, so the group pool would have shrunk to "only what I entered myself" even on trips where nobody shares anything. The predicate keeps the Common pool intact and drops only private items owned by someone else. Closes #1767
This commit is contained in:
@@ -7,7 +7,7 @@ import { avatarSrc } from '../../../../utils/avatarSrc'
|
||||
import type { PackingBag, PackingItem, TripMember } from '../../../../types'
|
||||
import type { TripPlanner } from '../MTripShell'
|
||||
import { formatWeight, packingItemWeight } from './listsModel'
|
||||
import { bagFillPct } from '../../../../components/Packing/packingListPanel.helpers'
|
||||
import { bagFillPct, countsTowardsMyLoad } from '../../../../components/Packing/packingListPanel.helpers'
|
||||
|
||||
export interface MBagsSheetProps {
|
||||
planner: TripPlanner
|
||||
@@ -17,6 +17,8 @@ export interface MBagsSheetProps {
|
||||
items: PackingItem[]
|
||||
tripMembers: TripMember[]
|
||||
canEdit: boolean
|
||||
/** Who is looking — decides whose load the weights describe (#1767). */
|
||||
currentUserId?: number | null
|
||||
onCreateBag: (name: string) => void
|
||||
onUpdateBag: (bagId: number, data: PackingUpdateBagRequest) => void
|
||||
onDeleteBag: (bagId: number) => void
|
||||
@@ -29,17 +31,20 @@ export interface MBagsSheetProps {
|
||||
* is the caller's business — this sheet just renders whatever bags it's given.
|
||||
*/
|
||||
export default function MBagsSheet({
|
||||
planner, open, onClose, bags, items, tripMembers, canEdit, onCreateBag, onUpdateBag, onDeleteBag, onSetBagMembers,
|
||||
planner, open, onClose, bags, items, tripMembers, canEdit, currentUserId, onCreateBag, onUpdateBag, onDeleteBag, onSetBagMembers,
|
||||
}: MBagsSheetProps) {
|
||||
const { t } = planner
|
||||
const [addingBag, setAddingBag] = useState(false)
|
||||
const [newBagName, setNewBagName] = useState('')
|
||||
|
||||
const unassigned = items.filter(i => !i.bag_id)
|
||||
// These numbers describe what you are carrying. An item someone shared with you stays
|
||||
// in your list, but they are the one bringing it, so it is not your weight (#1767).
|
||||
const myItems = items.filter(i => countsTowardsMyLoad(i, currentUserId))
|
||||
const unassigned = myItems.filter(i => !i.bag_id)
|
||||
const unassignedWeight = unassigned.reduce((s, i) => s + packingItemWeight(i), 0)
|
||||
const totalWeight = items.reduce((s, i) => s + packingItemWeight(i), 0)
|
||||
const totalWeight = myItems.reduce((s, i) => s + packingItemWeight(i), 0)
|
||||
// Reference for bags without a limit of their own — computed once instead of per bag.
|
||||
const heaviestBagWeight = Math.max(...bags.map(b => items.filter(i => i.bag_id === b.id).reduce((s, i) => s + packingItemWeight(i), 0)), 1)
|
||||
const heaviestBagWeight = Math.max(...bags.map(b => myItems.filter(i => i.bag_id === b.id).reduce((s, i) => s + packingItemWeight(i), 0)), 1)
|
||||
|
||||
const submitNewBag = () => {
|
||||
if (!newBagName.trim()) return
|
||||
@@ -54,7 +59,7 @@ export default function MBagsSheet({
|
||||
|
||||
<div className="min-h-0 flex-1 overflow-y-auto px-[18px] pb-[6px] pt-1">
|
||||
{bags.map(bag => {
|
||||
const bagItems = items.filter(i => i.bag_id === bag.id)
|
||||
const bagItems = myItems.filter(i => i.bag_id === bag.id)
|
||||
const bagWeight = bagItems.reduce((s, i) => s + packingItemWeight(i), 0)
|
||||
const pct = bagFillPct(bagWeight, bag.weight_limit_grams, heaviestBagWeight)
|
||||
return (
|
||||
|
||||
@@ -472,6 +472,7 @@ export default function MPackingListTab({ planner }: { planner: TripPlanner }) {
|
||||
items={items}
|
||||
tripMembers={tripMembers}
|
||||
canEdit={canEdit}
|
||||
currentUserId={currentUserId}
|
||||
onCreateBag={createBag}
|
||||
onUpdateBag={updateBag}
|
||||
onDeleteBag={deleteBag}
|
||||
|
||||
Reference in New Issue
Block a user