feature/improve-tag-organization-ux #8

Merged
pkartch merged 22 commits from feature/improve-tag-organization-ux into main 2026-01-17 06:13:39 +00:00
2 changed files with 11 additions and 4 deletions
Showing only changes of commit d29fee82a7 - Show all commits

View File

@@ -100,6 +100,7 @@ export interface Tag {
export interface RecipeTag { export interface RecipeTag {
tag: Tag; tag: Tag;
name?: string; // Optional for backward compatibility with code that accesses .name directly
} }
export interface Cookbook { export interface Cookbook {

View File

@@ -4,6 +4,11 @@ import { CookbookWithRecipes, Recipe } from '@basil/shared';
import { cookbooksApi } from '../services/api'; import { cookbooksApi } from '../services/api';
import '../styles/CookbookDetail.css'; import '../styles/CookbookDetail.css';
// Helper function to extract tag name from string or RecipeTag object
const getTagName = (tag: string | { tag: { name: string } }): string => {
return typeof tag === 'string' ? tag : tag.tag.name;
};
function CookbookDetail() { function CookbookDetail() {
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
const navigate = useNavigate(); const navigate = useNavigate();
@@ -75,7 +80,7 @@ function CookbookDetail() {
if (!cookbook) return []; if (!cookbook) return [];
const tagSet = new Set<string>(); const tagSet = new Set<string>();
cookbook.recipes.forEach(recipe => { cookbook.recipes.forEach(recipe => {
recipe.tags?.forEach(tag => tagSet.add(tag)); recipe.tags?.forEach(tag => tagSet.add(getTagName(tag)));
}); });
return Array.from(tagSet).sort(); return Array.from(tagSet).sort();
}; };
@@ -301,9 +306,10 @@ function CookbookDetail() {
</div> </div>
{recipe.tags && recipe.tags.length > 0 && ( {recipe.tags && recipe.tags.length > 0 && (
<div className="recipe-tags"> <div className="recipe-tags">
{recipe.tags.map(tag => ( {recipe.tags.map(tag => {
<span key={tag} className="tag">{tag}</span> const tagName = getTagName(tag);
))} return <span key={tagName} className="tag">{tagName}</span>;
})}
</div> </div>
)} )}
</div> </div>