diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index f18fc6d..59c6fdb 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -140,7 +140,7 @@ "changeLanguage": "Change Language", "changeLanguageTitle": "Change recipe language", "category": "Category", - "selectCategory": "Select category" + "selectCategory": "Select category..." }, "gallery": { "recipeImage": "Recipe Image" diff --git a/public/locales/pt/translation.json b/public/locales/pt/translation.json index c3cd466..91903be 100644 --- a/public/locales/pt/translation.json +++ b/public/locales/pt/translation.json @@ -139,7 +139,7 @@ "changeLanguage": "Alterar idioma", "changeLanguageTitle": "Alterar idioma da receita", "category": "Categoria", - "selectCategory": "Selecione categoria" + "selectCategory": "Selecione categoria..." }, "gallery": { "recipeImage": "Imagem de Receita" diff --git a/src/components/CategoryList.vue b/src/components/CategoryList.vue index 23ef994..4d4161a 100644 --- a/src/components/CategoryList.vue +++ b/src/components/CategoryList.vue @@ -25,7 +25,8 @@ function goToCategory(id: number) {
+ :imageAvailable="category.image != undefined" :recipeCount="category.recipeCount" + @click="goToCategory(category.id)" :rating="0" />
diff --git a/src/components/RecipeCard.vue b/src/components/RecipeCard.vue index 9a9b29a..926248a 100644 --- a/src/components/RecipeCard.vue +++ b/src/components/RecipeCard.vue @@ -4,6 +4,7 @@ const props = defineProps<{ image: string | undefined; imageAvailable: boolean; rating: number; + recipeCount: number; }>(); const emit = defineEmits<{ @@ -23,7 +24,7 @@ const emit = defineEmits<{ cursor-pointer ">
- Recipe + Recipe
@@ -33,15 +34,19 @@ const emit = defineEmits<{
-
-
+
+
{{ props.title }}
-
- {{ - props.rating }}⭐ +
+ ⭐{{ + props.rating }} +
+
+ {{ + props.recipeCount }}
diff --git a/src/components/RecipeList.vue b/src/components/RecipeList.vue index 522d415..ffeb25c 100644 --- a/src/components/RecipeList.vue +++ b/src/components/RecipeList.vue @@ -156,7 +156,7 @@ onMounted(async () => { }); async function loadCategory() { - if (props.categoryId){ + if (props.categoryId) { allRecipes = (await getRecipesByCategory(props.categoryId)) as RecipeViewModel[]; } else { allRecipes = (await getRecipes()) as RecipeViewModel[]; @@ -196,7 +196,11 @@ function goToRecipe(id: number) { } function goToNew() { - router.push("/recipe/0/edit"); + if (props.categoryId && props.categoryId > 0) { + router.push(`/recipe/0/edit?categoryId=${props.categoryId}`); + } else { + router.push(`/recipe/0/edit`); + } } function goToImportFromUrl() { @@ -288,7 +292,8 @@ function simpleSearchInText(a: string, b: string) {
+ :imageAvailable="item.imageAvailable" :rating="item.score" @click="goToRecipe(item.id || 0)" + :recipeCount="0" />
diff --git a/src/pages/recipe/[id]/edit.vue b/src/pages/recipe/[id]/edit.vue index 1469472..6343763 100644 --- a/src/pages/recipe/[id]/edit.vue +++ b/src/pages/recipe/[id]/edit.vue @@ -37,8 +37,9 @@ const { t } = useTranslation(); let isDirty = false; let croppingCanvas: HTMLCanvasElement; -const id = computed(() => parseInt(route.params.id as string)); const query = computed(() => route.query); +const id = computed(() => parseInt(route.params.id as string)); +const categoryId = computed(() => parseInt(query.value.categoryId as string ?? "0")); const item = ref({ id: 0, title: "", @@ -49,6 +50,7 @@ const item = ref({ imageAvailable: false, multiplier: 1, language: i18next.language, + categoryId: categoryId.value, nutrition: { servingSize: 0, totalFat: 0, @@ -332,6 +334,11 @@ async function importRecipeFromUrl() { } item.value.imageAvailable = images.value.length > 0; + + if (editInSingleTextArea.value) { + ingredientsText.value = item.value.ingredients.join("\n"); + stepsText.value = item.value.steps.join("\n"); + } } catch { isImportFromUrlModalOpen.value = true; @@ -678,7 +685,7 @@ function changeLanguage() { diff --git a/src/services/category.ts b/src/services/category.ts index 54f4ebf..956d8d7 100644 --- a/src/services/category.ts +++ b/src/services/category.ts @@ -2,4 +2,5 @@ export class Category { id!: number; name!: string; image!: string | undefined; + recipeCount!: number; } \ No newline at end of file diff --git a/src/services/dataService.ts b/src/services/dataService.ts index 618e95b..04eed42 100644 --- a/src/services/dataService.ts +++ b/src/services/dataService.ts @@ -243,7 +243,12 @@ export async function getCategories(): Promise> { id: category.id, name: category.name } as Category; - const recipe = await db.recipes.where("categoryId").equals(category.id).first(); + const recipes = db.recipes.where("categoryId").equals(category.id); + const count = await recipes.count(); + const recipe = await recipes.first(); + + resultItem.recipeCount = count; + if (category.image) { resultItem.image = category.image; } else if (recipe) { @@ -255,7 +260,8 @@ export async function getCategories(): Promise> { result.push(resultItem); } } - result.push({ id: 0, name: "All", image: undefined }); + const allRecipesCount = await db.recipes.count(); + result.push({ id: 0, name: "All", image: undefined, recipeCount: allRecipesCount }); return result; }