diff --git a/.peppa/memory.md b/.peppa/memory.md index 765da48..a8f0708 100644 --- a/.peppa/memory.md +++ b/.peppa/memory.md @@ -17,6 +17,7 @@ - WTC-20: пока в списке нет блюда с кнопкой «Рецепт», виден блок #recipeExample (подсказка + кнопка #addExample «Добавить «…»», пример = recipeExample() в logic.js); иначе — фраза #recipesHint (WTC-19). Подпись #noRecipeHint под списком — при блюде без рецепта (hasNoRecipe). - WTC-24: подсказка под кнопкой «Что приготовить?» — i18n pickHint (в app.js #hint: пусто→emptyHint, одно блюдо после выбора→oneHint, иначе pickHint); остальные критерии были готовы с WTC-5..8. - WTC-26: #noRecipeHint виден на пустом экране (n===0) или при блюде без рецепта; вместе с #recipeExample объясняет оба случая. sed на macOS с | и & падает — правь через Edit. +- WTC-27: примеры на пустом экране — recipeExamples() (до 4) в logic.js, кнопки .add-example в #examples, подпись examplesNote; recipeExample (один) остался для тестов WTC-20. ## Соглашения - Цвета кнопки: доступная #b4500c, недоступная #e8dccb/#5c4a35 (контраст ≥4.5:1, проверяется тестом); opacity для disabled не используем. diff --git a/openspec/changes/archive/2026-11-16-wtc-27-more-examples/design.md b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/design.md new file mode 100644 index 0000000..2b3cdfa --- /dev/null +++ b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/design.md @@ -0,0 +1,3 @@ +## Решения +- `recipeExamples(dishes, catalog, findRecipe, limit=4)` в logic.js вместо одного `recipeExample`; кнопки строятся в `#examples`, клик — делегированием. +- Условие показа прежнее: пока в списке нет блюда с кнопкой «Рецепт». Подпись — i18n `examplesNote` (ru/kk/en). diff --git a/openspec/changes/archive/2026-11-16-wtc-27-more-examples/proposal.md b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/proposal.md new file mode 100644 index 0000000..0419645 --- /dev/null +++ b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/proposal.md @@ -0,0 +1,7 @@ +## Why +На пустом экране предложен один пример блюда — кажется, что в базе только оно. + +## What Changes +- Показываем до 4 блюд из базы, каждое добавляется одним нажатием. +- Добавленное блюдо из примеров пропадает. +- Подпись: это только примеры, можно вписать своё блюдо. diff --git a/openspec/changes/archive/2026-11-16-wtc-27-more-examples/specs/examples/spec.md b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/specs/examples/spec.md new file mode 100644 index 0000000..8f6be22 --- /dev/null +++ b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/specs/examples/spec.md @@ -0,0 +1,14 @@ +## ADDED Requirements +### Requirement: Несколько примеров из базы +Пустой экран SHALL показывать до 4 блюд из базы, добавляемых одним нажатием, с подписью, что это только примеры. + +#### Scenario: Пустой экран +- **GIVEN** список блюд пуст +- **WHEN** открывается главный экран +- **THEN** видны 4 блюда из базы с кнопками добавления +- **AND** подпись говорит, что это только примеры и можно вписать своё блюдо + +#### Scenario: Блюдо уже добавлено +- **GIVEN** пользователь добавил «Плов» из примеров +- **WHEN** экран обновился +- **THEN** «Плов» среди примеров больше не показывается diff --git a/openspec/changes/archive/2026-11-16-wtc-27-more-examples/tasks.md b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/tasks.md new file mode 100644 index 0000000..baadc84 --- /dev/null +++ b/openspec/changes/archive/2026-11-16-wtc-27-more-examples/tasks.md @@ -0,0 +1,3 @@ +- [x] recipeExamples в logic.js +- [x] Кнопки примеров и подпись на экране, тексты на трёх языках +- [x] Тесты diff --git a/src/app.js b/src/app.js index d93f5d9..5d750fd 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,4 @@ -import { submitDish, addDish, removeDish, pickDish, parseState, suggest, inCatalog, difficultyOf, pickByDifficulty, placeholderFor, hasRecipe, hasNoRecipe, recipeExample } from "./logic.js"; +import { submitDish, addDish, removeDish, pickDish, parseState, suggest, inCatalog, difficultyOf, pickByDifficulty, placeholderFor, hasRecipe, hasNoRecipe, recipeExamples } from "./logic.js"; import { catalog, LEVEL_KEYS } from "./catalog.js"; import { findRecipe } from "./recipes.js"; import { messages, pickLang } from "./i18n.js"; @@ -47,11 +47,18 @@ function render() { $("empty").hidden = n !== 0; $("recipesHint").textContent = t.listRecipes; $("recipesHint").hidden = !hasRecipe(state.dishes, findRecipe); - const example = hasRecipe(state.dishes, findRecipe) ? null : recipeExample(state.dishes, catalog, findRecipe); - $("recipeExample").hidden = example === null; + const examples = hasRecipe(state.dishes, findRecipe) ? [] : recipeExamples(state.dishes, catalog, findRecipe); + $("recipeExample").hidden = examples.length === 0; $("recipeExampleHint").textContent = t.recipeExampleHint; - $("addExample").textContent = example === null ? "" : t.addExample.replace("{name}", example); - $("addExample").dataset.name = example ?? ""; + $("examplesNote").textContent = t.examplesNote; + $("examples").replaceChildren(...examples.map((name) => { + const b = document.createElement("button"); + b.type = "button"; + b.className = "add-example"; + b.dataset.name = name; + b.textContent = t.addExample.replace("{name}", name); + return b; + })); $("noRecipeHint").textContent = t.noRecipeHint; $("noRecipeHint").hidden = n !== 0 && !hasNoRecipe(state.dishes, findRecipe); const ul = $("list"); @@ -123,10 +130,10 @@ $("back").addEventListener("click", () => { $("recipeToday").addEventListener("click", () => openRecipe(state.last, $("recipeToday"))); // Пример из подсказки добавляется одним нажатием; фокус — на кнопку «Рецепт» нового блюда. -$("addExample").addEventListener("click", () => { - const name = $("addExample").dataset.name; - if (!name) return; - state.dishes = addDish(state.dishes, name); +$("examples").addEventListener("click", (e) => { + const btn = e.target.closest(".add-example"); + if (!btn || !btn.dataset.name) return; + state.dishes = addDish(state.dishes, btn.dataset.name); save(); renderSuggest(); render(); const btns = $("list").querySelectorAll(".recipe-btn"); if (btns.length) btns[btns.length - 1].focus(); diff --git a/src/i18n.js b/src/i18n.js index c2ab0cd..5cdbb84 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -16,6 +16,7 @@ export const messages = { listRecipes: "У блюд из нашей базы есть рецепт — он откроется кнопкой «Рецепт».", recipeExampleHint: "Хотите увидеть рецепт? Добавьте блюдо из нашей базы — рядом с ним появится кнопка «Рецепт». Например:", addExample: "Добавить «{name}»", + examplesNote: "Это только примеры из нашей базы — можно вписать и своё блюдо.", noRecipeHint: "Пометка «Рецепта нет» стоит у блюд, которых нет в нашей базе. Рецепты есть только у блюд из базы.", pick: "Что приготовить?", yourDishes: "Ваши блюда", @@ -53,6 +54,7 @@ export const messages = { listRecipes: "Біздің қордағы тағамдардың рецепті бар — оны «Рецепт» түймесімен ашасыз.", recipeExampleHint: "Рецептті көргіңіз келе ме? Біздің қордағы тағамды қосыңыз — қасында «Рецепт» түймесі пайда болады. Мысалы:", addExample: "«{name}» қосу", + examplesNote: "Бұл біздің қордағы мысалдар ғана — өз тағамыңызды да жаза аласыз.", noRecipeHint: "«Рецепт жоқ» белгісі біздің қорда жоқ тағамдарда тұрады. Рецепт тек қордағы тағамдарда бар.", pick: "Не дайындаймыз?", yourDishes: "Сіздің тағамдарыңыз", @@ -90,6 +92,7 @@ export const messages = { listRecipes: "Dishes from our collection come with a recipe — open it with the “Recipe” button.", recipeExampleHint: "Want to see a recipe? Add a dish from our collection — a “Recipe” button will appear next to it. For example:", addExample: "Add “{name}”", + examplesNote: "These are just examples from our collection — you can type your own dish too.", noRecipeHint: "“No recipe” marks dishes that are not in our collection. Only dishes from the collection have a recipe.", pick: "What to cook?", yourDishes: "Your dishes", diff --git a/src/index.html b/src/index.html index acc1631..2590db3 100644 --- a/src/index.html +++ b/src/index.html @@ -40,7 +40,8 @@