Skip to content

Commit f30ee37

Browse files
authored
Merge pull request #91 from leonbeon/pr-ingredient-units
Add option to show quantities next to ingredients in recipe text
2 parents 88757d7 + c857ce4 commit f30ee37

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

ui/src/App.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Recipe from "./Recipe.svelte";
99
import Logo from "./Logo.svelte";
1010
import ShoppingList from "./ShoppingList.svelte";
11+
import Preferences from "./Preferences.svelte";
1112
1213
import {fetchRecipes} from "./backend.js";
1314
import {fileTree, convertPathsIntoTree} from "./store.js";
@@ -37,12 +38,18 @@
3738
<NavItem>
3839
<NavLink href="/shopping-list">Shopping list</NavLink>
3940
</NavItem>
41+
42+
<NavItem>
43+
<NavLink href="/preferences">Preferences</NavLink>
44+
</NavItem>
4045
</Nav>
4146
</Navbar>
4247

4348
<div class="py-3">
4449
<Route path="shopping-list" component="{ShoppingList}" />
4550

51+
<Route path="preferences" component="{Preferences}" />
52+
4653
<Route path="recipe/*recipePath" let:params>
4754
<Recipe recipePath={params.recipePath} />
4855
</Route>

ui/src/Preferences.svelte

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script>
2+
import {ListGroup, ListGroupItem, TabContent, TabPane, Button} from "sveltestrap";
3+
4+
import {showQuantitiesNextToIngredients} from "./store.js";
5+
</script>
6+
7+
<TabContent>
8+
<TabPane tabId="preferences" tab="Preferences" active>
9+
<!-- add checkbox input to toggle showQuantitiesNextToIngredients store -->
10+
<label class="my-3" for="show-quantities-next-to-ingredients">
11+
<input type="checkbox" id="show-quantities-next-to-ingredients" bind:checked={$showQuantitiesNextToIngredients}>
12+
<span>Show quantities next to ingredients in recipes</span>
13+
</label>
14+
</TabPane>
15+
16+
17+
</TabContent>

ui/src/Step.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
export let step, ingredients, cookware, timers;
33
import {formatQuantity} from "./quantity";
4+
import {showQuantitiesNextToIngredients} from "./store.js"
45
56
function formatText(item) {
67
return item.value;
@@ -26,7 +27,11 @@ function itemsToString(items, ingredients, cookware, timers) {
2627
return items.map((item) => {
2728
switch(item.type) {
2829
case "ingredient":
29-
return formatIngredient(ingredients[item.index]);
30+
if ($showQuantitiesNextToIngredients) {
31+
return `${formatIngredient(ingredients[item.index])} <span class="text-muted">(${formatQuantity(ingredients[item.index].quantity)})</span>`;
32+
} else {
33+
return formatIngredient(ingredients[item.index]);
34+
}
3035
case "cookware":
3136
return formatCookware(cookware[item.index]);
3237
case "text":
@@ -43,7 +48,7 @@ function itemsToString(items, ingredients, cookware, timers) {
4348
<div class="card border-0">
4449
<div class="card-body">
4550
<h6 class="card-title">Step {step.number}</h6>
46-
<p class="card-text">{itemsToString(step.items, ingredients, cookware, timers)}</p>
51+
<p class="card-text">{@html itemsToString(step.items, ingredients, cookware, timers)}</p>
4752
</div>
4853
</div>
4954

ui/src/store.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ function createShoppingListPaths() {
4949
}
5050

5151
export const shoppingListPaths = createShoppingListPaths();
52+
53+
// Preference for showing quantities next to ingredients, default is false
54+
const showQuantitiesNextToIngredientsValue = localStorage.getItem("showQuantitiesNextToIngredients") || "false";
55+
export const showQuantitiesNextToIngredients = writable(JSON.parse(showQuantitiesNextToIngredientsValue));
56+
57+
// Subscribe method to update local storage
58+
showQuantitiesNextToIngredients.subscribe((val) => {
59+
localStorage.setItem("showQuantitiesNextToIngredients", JSON.stringify(val));
60+
})

0 commit comments

Comments
 (0)