Skip to content

Commit 71cd716

Browse files
authored
Merge pull request #79 from stepanzh/78-add-fast-add-of-number-of-portions
feat: fast adding of number of portions
2 parents 30aa999 + cedd26c commit 71cd716

File tree

2 files changed

+64
-13
lines changed

2 files changed

+64
-13
lines changed

src/components/OriginalTable.vue

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<div>
33
<!-- Table -->
44
<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">
67
<TextField v-model="ingr.name" placeholder="Ингредиент" class="cell-name" />
78
<OriginalAmount v-model="ingr.originalAmount" placeholder="250" class="cell-amount" />
89
<TextField v-model="ingr.unit" placeholder="гр" class="cell-unit" />
@@ -17,11 +18,18 @@
1718
<ArrowsUpDownIconMini />
1819
</template>
1920
</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>
2533
</div>
2634
</div>
2735
</template>
@@ -32,22 +40,56 @@ import { useProportioCalculatorStore } from '@/stores/proportioCalculator'
3240
import { useProportioNavStore } from '@/stores/proportioNav'
3341
import { nextTick, ref } from 'vue'
3442
import OriginalAmount from '@/components/OriginalAmount.vue'
43+
import PButton from '@/ui/PButton.vue'
3544
3645
const proportio = useProportioNavStore()
3746
const store = useProportioCalculatorStore()
3847
const ingredientList = ref(null)
3948
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+
4057
function addIngredient() {
4158
store.add()
4259
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
5068
}
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' })
5193
})
5294
}
5395
</script>
@@ -59,4 +101,9 @@ function addIngredient() {
59101
justify-content: space-between;
60102
margin-top: 16px;
61103
}
104+
105+
.table-orig-actions__right {
106+
display: flex;
107+
gap: 12px;
108+
}
62109
</style>

src/ui/icons.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Bars3IconOutline.__name = getVariableName({ Bars3IconOutline })
2424
import { CalculatorIcon as CalculatorIconMini } from '@heroicons/vue/16/solid'
2525
CalculatorIconMini.__name = getVariableName({ CalculatorIconMini })
2626

27+
import { CircleStackIcon as CircleStackIconMini } from '@heroicons/vue/16/solid'
28+
CircleStackIconMini.__name = getVariableName({ CircleStackIconMini })
29+
2730
import { CheckCircleIcon as CheckCircleIconMini } from '@heroicons/vue/16/solid'
2831
CheckCircleIconMini.__name = getVariableName({ CheckCircleIconMini })
2932

@@ -73,6 +76,7 @@ export default [
7376
ArrowsUpDownIconMini,
7477
Bars3IconOutline,
7578
CalculatorIconMini,
79+
CircleStackIconMini,
7680
CheckCircleIconMini,
7781
ClipboardDocumentListIconOutline,
7882
ExclamationTriangleIconMini,

0 commit comments

Comments
 (0)