2
2
<div >
3
3
<!-- Table -->
4
4
<div >
5
- <div v-if =" store.numberOfIngredients > 0" v-for =" ingr in store.ingredients" :key =" ingr.id" ref =" ingredientList" class =" table-row" >
5
+ <div v-if =" store.numberOfIngredients > 0" v-for =" ingr in store.ingredients" :key =" ingr.id"
6
+ ref =" ingredientList" class =" table-row" >
6
7
<TextField v-model =" ingr.name" placeholder =" Ингредиент" class =" cell-name" />
7
8
<OriginalAmount v-model =" ingr.originalAmount" placeholder =" 250" class =" cell-amount" />
8
9
<TextField v-model =" ingr.unit" placeholder =" гр" class =" cell-unit" />
17
18
<ArrowsUpDownIconMini />
18
19
</template >
19
20
</PButton >
20
- <PButton @click =" addIngredient" label =" Добавить" class =" btn-filled-primary" >
21
- <template #icon >
22
- <PlusCircleIconMini />
23
- </template >
24
- </PButton >
21
+ <div class =" table-orig-actions__right" >
22
+ <PButton @click =" addNumberOfPortions" :iconOnly =" true" class =" btn-filled-secondary" >
23
+ <template #icon >
24
+ <CircleStackIconMini />
25
+ </template >
26
+ </PButton >
27
+ <PButton @click =" addIngredient" label =" Добавить" class =" btn-filled-primary" >
28
+ <template #icon >
29
+ <PlusCircleIconMini />
30
+ </template >
31
+ </PButton >
32
+ </div >
25
33
</div >
26
34
</div >
27
35
</template >
@@ -32,22 +40,56 @@ import { useProportioCalculatorStore } from '@/stores/proportioCalculator'
32
40
import { useProportioNavStore } from ' @/stores/proportioNav'
33
41
import { nextTick , ref } from ' vue'
34
42
import OriginalAmount from ' @/components/OriginalAmount.vue'
43
+ import PButton from ' @/ui/PButton.vue'
35
44
36
45
const proportio = useProportioNavStore ()
37
46
const store = useProportioCalculatorStore ()
38
47
const ingredientList = ref (null )
39
48
49
+ function getLastIngredientElement () {
50
+ if (ingredientList .value .length > 0 ) {
51
+ let last = ingredientList .value [ingredientList .value .length - 1 ]
52
+ return last
53
+ }
54
+ return undefined
55
+ }
56
+
40
57
function addIngredient () {
41
58
store .add ()
42
59
nextTick (() => {
43
- if (ingredientList .value .length > 0 ) {
44
- let last = ingredientList .value [ingredientList .value .length - 1 ]
45
- let nameInputs = last .getElementsByClassName (' cell-name' )
46
- if (nameInputs .length > 0 ) {
47
- nameInputs[0 ].focus ()
48
- last .scrollIntoView ({ ' behavior' : ' smooth' })
49
- }
60
+ let last = getLastIngredientElement ()
61
+ if (! last) {
62
+ console .warn (" DOM error: last ingredient was not added" )
63
+ return undefined
64
+ }
65
+ let nameInputs = last .getElementsByClassName (' cell-name' )
66
+ if (nameInputs .length < 1 ) {
67
+ return undefined
50
68
}
69
+
70
+ // DRY
71
+ nameInputs[0 ].focus ()
72
+ last .scrollIntoView ({ ' behavior' : ' smooth' })
73
+ })
74
+ }
75
+
76
+ function addNumberOfPortions () {
77
+ store .add (" Число порций" )
78
+ nextTick (() => {
79
+ let last = getLastIngredientElement ()
80
+ if (! last) {
81
+ console .warn (" DOM error: number of portions was not added" )
82
+ return undefined
83
+ }
84
+
85
+ let amountInputs = last .getElementsByClassName (' cell-amount' )
86
+ if (amountInputs .length < 1 ) {
87
+ return undefined
88
+ }
89
+
90
+ // DRY
91
+ amountInputs[0 ].focus ()
92
+ last .scrollIntoView ({ ' behaviour' : ' smooth' })
51
93
})
52
94
}
53
95
</script >
@@ -59,4 +101,9 @@ function addIngredient() {
59
101
justify-content : space-between ;
60
102
margin-top : 16px ;
61
103
}
104
+
105
+ .table-orig-actions__right {
106
+ display : flex ;
107
+ gap : 12px ;
108
+ }
62
109
</style >
0 commit comments