Skip to content

Commit

Permalink
Merge pull request #24 from ATGardner/fix_worn_weight
Browse files Browse the repository at this point in the history
add only a single item's weight to the "Worn" weight
  • Loading branch information
maplethorpej committed Feb 21, 2020
2 parents 254162e + 7a58a3b commit 84a7732
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions frontend/src/lib/utils/weight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ export const getTotalWeight = (unit: WeightUnit, items: (PackItem | Item)[]): Ag
if (!weight_unit) return acc;

const conversionValue = converter(weight).from(unitDict[weight_unit]).to(unitDict[unit]);
const quantityWeight = parseFloat(conversionValue) * quantity;
const convertedWeight = parseFloat(conversionValue);

if (Category.exclude_weight || isWorn) {
return { ...acc, exclude: acc.exclude + quantityWeight };
if (Category.exclude_weight) {
return { ...acc, exclude: acc.exclude + convertedWeight * quantity };
}

return { ...acc, include: acc.include + quantityWeight };
if (isWorn) {
return { ...acc, include: acc.include + convertedWeight * (quantity - 1), exclude: acc.exclude + convertedWeight };
}

return { ...acc, include: acc.include + convertedWeight * quantity };
}

const { include, exclude } = items.reduce(reducer, { include: 0, exclude: 0 });
Expand Down Expand Up @@ -74,4 +78,4 @@ export const getWeightByCategory = (unit: WeightUnit, items: (PackItem | Item)[]
color: colors[i]
}
}).sort((a, b) => b.total.value - a.total.value);
};
};

0 comments on commit 84a7732

Please sign in to comment.