Skip to content

Commit

Permalink
Merge pull request #30 from Muetze42/development
Browse files Browse the repository at this point in the history
fix(shopping list): not working collection keys (umlauts)
  • Loading branch information
Muetze42 authored Mar 15, 2024
2 parents 4dbeb36 + 9d2c8d6 commit f8d52b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/ShoppingListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function data(Request $request): array
$ingredientName = $ingredients->pluck('name', 'id')->toArray();

$ingredients = $ingredients->mapWithKeys(fn (Ingredient $ingredient) => [$ingredient->name => [
'id' => $ingredient->getKey(),
'image' => $ingredient->asset()->image(),
'recipe_yields' => [],
]])->sortKeys(SORT_NATURAL | SORT_FLAG_CASE)->toArray();
Expand Down
16 changes: 8 additions & 8 deletions resources/js/Pages/ShoppingList/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ const calculated = computed(() => {
if (value && is_numeric(value)) {
itemValue += value
}
data_set(collection, ingredientName + '.' + unit, itemValue)
data_set(collection, ingredient.id + '.' + unit, itemValue)
}
}
let merged = {}
for (const [ingredientName, calculatedData] of Object.entries(collection)) {
merged[ingredientName] = ''
for (const [ingredientId, calculatedData] of Object.entries(collection)) {
merged[ingredientId] = ''
// noinspection JSCheckFunctionSignatures
for (let [unit, value] of Object.entries(calculatedData)) {
if (merged[ingredientName].length) {
merged[ingredientName] += ' + '
if (merged[ingredientId].length) {
merged[ingredientId] += ' + '
}
if (unit === 'g' && value >= 1000) {
unit = 'kg'
Expand All @@ -101,11 +101,11 @@ const calculated = computed(() => {
value = value / 1000
}
if (value > 0) {
merged[ingredientName] +=
merged[ingredientId] +=
new Intl.NumberFormat(page.props.locale + '-' + page.props.country.code).format(value) +
' '
}
merged[ingredientName] += unit
merged[ingredientId] += unit
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ onMounted(() => {
<tfoot :class="{ hidden: view === 'C' }">
<tr>
<td colspan="2" class="px-2 text-right font-medium">
{{ calculated[ingredientName] }}
{{ calculated[ingredient.id] }}
</td>
</tr>
</tfoot>
Expand Down

0 comments on commit f8d52b0

Please sign in to comment.