mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
fixed selecting foods with leading numbers in ShoppingListEntryInput
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-text-field :label="$t('Shopping_input_placeholder')" density="compact" @keyup.enter="addIngredient()" v-model="ingredientInput" :loading="props.loading" hide-detail v-if="!useUserPreferenceStore().deviceSettings.shopping_input_autocomplete"s>
|
<v-text-field :label="$t('Shopping_input_placeholder')" density="compact" @keyup.enter="addIngredient()" v-model="ingredientInput" :loading="props.loading" hide-detail
|
||||||
|
v-if="!useUserPreferenceStore().deviceSettings.shopping_input_autocomplete" s>
|
||||||
<template #append>
|
<template #append>
|
||||||
<v-btn
|
<v-btn
|
||||||
density="comfortable"
|
density="comfortable"
|
||||||
@@ -36,7 +37,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import {PropType, ref} from "vue";
|
import {PropType, ref} from "vue";
|
||||||
import {ApiApi, Food, IngredientString, MealPlan, ShoppingListEntry, ShoppingListRecipe} from "@/openapi";
|
import {ApiApi, Food, IngredientString, MealPlan, ShoppingListEntry, ShoppingListRecipe, Unit} from "@/openapi";
|
||||||
import {useShoppingStore} from "@/stores/ShoppingStore";
|
import {useShoppingStore} from "@/stores/ShoppingStore";
|
||||||
import {ErrorMessageType, MessageType, useMessageStore} from "@/stores/MessageStore";
|
import {ErrorMessageType, MessageType, useMessageStore} from "@/stores/MessageStore";
|
||||||
import Multiselect from "@vueform/multiselect";
|
import Multiselect from "@vueform/multiselect";
|
||||||
@@ -60,32 +61,36 @@ const loading = ref(false)
|
|||||||
/**
|
/**
|
||||||
* add new ingredient from ingredient text input
|
* add new ingredient from ingredient text input
|
||||||
*/
|
*/
|
||||||
function addIngredient() {
|
function addIngredient(amount: number, unit: Unit|null, food: Food|null) {
|
||||||
|
let sle = {
|
||||||
|
amount: Math.max(amount, 1),
|
||||||
|
unit: unit,
|
||||||
|
food: food,
|
||||||
|
} as ShoppingListEntry
|
||||||
|
|
||||||
|
console.log('adding SLR ? ', props.mealPlan)
|
||||||
|
if (props.mealPlan) {
|
||||||
|
console.log('yes')
|
||||||
|
sle.mealplanId = props.mealPlan.id
|
||||||
|
}
|
||||||
|
|
||||||
|
useShoppingStore().createObject(sle, true).finally(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
ingredientInput.value = ''
|
||||||
|
|
||||||
|
ingredientInputIcon.value = 'fa-solid fa-check'
|
||||||
|
setTimeout(() => {
|
||||||
|
ingredientInputIcon.value = 'fa-solid fa-plus'
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIngredient() {
|
||||||
const api = new ApiApi()
|
const api = new ApiApi()
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
api.apiIngredientFromStringCreate({ingredientString: {text: ingredientInput.value} as IngredientString}).then(r => {
|
api.apiIngredientFromStringCreate({ingredientString: {text: ingredientInput.value} as IngredientString}).then(r => {
|
||||||
let sle = {
|
addIngredient(r.amount, r.unit, r.food)
|
||||||
amount: Math.max(r.amount, 1),
|
|
||||||
unit: r.unit,
|
|
||||||
food: r.food,
|
|
||||||
} as ShoppingListEntry
|
|
||||||
|
|
||||||
console.log('adding SLR ? ', props.mealPlan)
|
|
||||||
if (props.mealPlan) {
|
|
||||||
console.log('yes')
|
|
||||||
sle.mealplanId = props.mealPlan.id
|
|
||||||
}
|
|
||||||
|
|
||||||
useShoppingStore().createObject(sle, true).finally(() => {
|
|
||||||
loading.value = false
|
|
||||||
})
|
|
||||||
ingredientInput.value = ''
|
|
||||||
|
|
||||||
ingredientInputIcon.value = 'fa-solid fa-check'
|
|
||||||
setTimeout(() => {
|
|
||||||
ingredientInputIcon.value = 'fa-solid fa-plus'
|
|
||||||
}, 1000)
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
useMessageStore().addError(ErrorMessageType.CREATE_ERROR, err)
|
useMessageStore().addError(ErrorMessageType.CREATE_ERROR, err)
|
||||||
loading.value = false
|
loading.value = false
|
||||||
@@ -99,14 +104,14 @@ function createObject(object: any, select$: Multiselect) {
|
|||||||
ingredientModelInput.value = {} as Food
|
ingredientModelInput.value = {} as Food
|
||||||
select$.close()
|
select$.close()
|
||||||
select$.clearSearch()
|
select$.clearSearch()
|
||||||
addIngredient()
|
parseIngredient()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectObject(foodId: number, food: Food, select$: Multiselect) {
|
function selectObject(foodId: number, food: Food, select$: Multiselect) {
|
||||||
ingredientInput.value = food.name
|
//ingredientInput.value = food.name
|
||||||
ingredientModelInput.value = {} as Food
|
ingredientModelInput.value = {} as Food
|
||||||
addIngredient()
|
addIngredient(1, null, food)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +123,7 @@ function search(query: string) {
|
|||||||
loading.value = true
|
loading.value = true
|
||||||
let api = new ApiApi()
|
let api = new ApiApi()
|
||||||
|
|
||||||
return api.apiFoodList({query: query, page: 1, pageSize: 25}).then(r => {
|
return api.apiFoodList({query: query, page: 1, pageSize: 25}).then(r => {
|
||||||
return r.results
|
return r.results
|
||||||
}).catch((err: any) => {
|
}).catch((err: any) => {
|
||||||
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
|
useMessageStore().addError(ErrorMessageType.FETCH_ERROR, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user