Renaming to distinguish editor and display list items and adding component for IngredientGroupDisplayListItem.tsx

This commit is contained in:
araemer 2025-11-02 07:20:01 +01:00
parent 3e0a4ec38b
commit 09150ba3bb
8 changed files with 58 additions and 44 deletions

View file

@ -0,0 +1,22 @@
import type {IngredientGroupModel} from "../../models/IngredientGroupModel.ts";
type IngredientGroupDisplayListItemProps = {
groupModel: IngredientGroupModel,
index: number,
}
export default function IngredientGroupDisplayListItem({groupModel, index}: IngredientGroupDisplayListItemProps) {
return (<div key={index}>
{/* the title is optional, only print if present */}
{groupModel.title && groupModel.title.trim() !== "" && (
<h3 className="highlight-container-bg mb-2">{groupModel.title}</h3>
)}
<ul>
{groupModel.ingredientList.map((ing, j) => (
<li key={j} className="border-b border-gray-300 last:border-b-0 p-2">
{ing.amount ?? ""} {ing.unit ?? ""} {ing.name}
</li>
))}
</ul>
</div>);
}

View file

@ -5,7 +5,7 @@ import type {IngredientGroupModel} from "../../models/IngredientGroupModel.ts";
import type {IngredientModel} from "../../models/IngredientModel.ts"; import type {IngredientModel} from "../../models/IngredientModel.ts";
import HorizontalInputGroupLayout from "../basics/HorizontalInputGroupLayout.tsx"; import HorizontalInputGroupLayout from "../basics/HorizontalInputGroupLayout.tsx";
type IngredientGroupListItemProps = { type IngredientGroupEditorListItemProps = {
/** The list item's index */ /** The list item's index */
index: number index: number
/** Model containing data for ingredient group */ /** Model containing data for ingredient group */
@ -23,12 +23,12 @@ type IngredientGroupListItemProps = {
* @param handleUpdate Model containing data for ingredient group * @param handleUpdate Model containing data for ingredient group
* @param handleRemove Method for removing group * @param handleRemove Method for removing group
*/ */
export default function IngredientGroupListItem({ export default function IngredientGroupEditorListItem({
index, index,
ingredientGroupModel, ingredientGroupModel,
handleUpdate, handleUpdate,
handleRemove handleRemove
}: IngredientGroupListItemProps) { }: IngredientGroupEditorListItemProps) {
const updateIngredientList = (index: number, ingredientList: IngredientModel[]) => { const updateIngredientList = (index: number, ingredientList: IngredientModel[]) => {
handleUpdate(index, "ingredientList", ingredientList) handleUpdate(index, "ingredientList", ingredientList)
} }

View file

@ -3,7 +3,7 @@ import type {IngredientGroupModel} from "../../models/IngredientGroupModel"
import Button from "../basics/Button" import Button from "../basics/Button"
import {Plus} from "lucide-react" import {Plus} from "lucide-react"
import {ButtonType} from "../basics/BasicButtonDefinitions" import {ButtonType} from "../basics/BasicButtonDefinitions"
import IngredientGroupListItem from "./IngredientGroupListItem.tsx"; import IngredientGroupEditorListItem from "./IngredientGroupEditorListItem.tsx";
type IngredientGroupListEditorProps = { type IngredientGroupListEditorProps = {
ingredientGroupList: IngredientGroupModel[] ingredientGroupList: IngredientGroupModel[]
@ -48,7 +48,7 @@ export function IngredientGroupListEditor({ingredientGroupList, onChange}: Ingre
<h2>Zutaten</h2> <h2>Zutaten</h2>
<div> <div>
{ingredientGroupList.map((ingGrp, index) => ( {ingredientGroupList.map((ingGrp, index) => (
<IngredientGroupListItem <IngredientGroupEditorListItem
index={index} index={index}
ingredientGroupModel={ingGrp} ingredientGroupModel={ingGrp}
handleUpdate={handleUpdate} handleUpdate={handleUpdate}

View file

@ -10,7 +10,7 @@ import {X} from "lucide-react"
import {ButtonType} from "../basics/BasicButtonDefinitions"; import {ButtonType} from "../basics/BasicButtonDefinitions";
import {NumberCircle} from "../basics/NumberCircle.tsx"; import {NumberCircle} from "../basics/NumberCircle.tsx";
type InstructionStepDesktopListItemProps = { type InstructionStepEditorDesktopListItemProps = {
id: string | number; id: string | number;
index: number; index: number;
step: InstructionStepModel; step: InstructionStepModel;
@ -18,13 +18,13 @@ type InstructionStepDesktopListItemProps = {
onRemove: (index: number) => void; onRemove: (index: number) => void;
}; };
export function InstructionStepDesktopListItem({ export function InstructionStepEditorDesktopListItem({
id, id,
index, index,
step, step,
onUpdate, onUpdate,
onRemove, onRemove,
}: InstructionStepDesktopListItemProps) { }: InstructionStepEditorDesktopListItemProps) {
const {attributes, listeners, setNodeRef, transform, transition} = useSortable({id}); const {attributes, listeners, setNodeRef, transform, transition} = useSortable({id});
const style = {transform: CSS.Transform.toString(transform), transition}; const style = {transform: CSS.Transform.toString(transform), transition};

View file

@ -5,7 +5,7 @@ import type {InstructionStepModel} from "../../models/InstructionStepModel.ts";
import {MoveButtonControl} from "../basics/MoveButtonControl.tsx"; import {MoveButtonControl} from "../basics/MoveButtonControl.tsx";
import {NumberCircle} from "../basics/NumberCircle.tsx"; import {NumberCircle} from "../basics/NumberCircle.tsx";
type InstructionStepMobileListItemProps = { type InstructionStepEditorMobileListItemProps = {
/** Index of the instruction step */ /** Index of the instruction step */
index: number; index: number;
/** Model holding the instruction step data, e.g., instruction text */ /** Model holding the instruction step data, e.g., instruction text */
@ -46,7 +46,7 @@ type InstructionStepMobileListItemProps = {
* @param isFirst Indicates whether this is the first instruction step. In this case, the step cannot be moved up. * @param isFirst Indicates whether this is the first instruction step. In this case, the step cannot be moved up.
* @param isLast Indicates whether this is the last instruction step. In this case, the step cannot be moved down. * @param isLast Indicates whether this is the last instruction step. In this case, the step cannot be moved down.
*/ */
export function InstructionStepMobileListItem({ export function InstructionStepEditorMobileListItem({
index, index,
stepModel, stepModel,
onMove, onMove,
@ -54,7 +54,7 @@ export function InstructionStepMobileListItem({
onRemove, onRemove,
isFirst, isFirst,
isLast isLast
}: InstructionStepMobileListItemProps) { }: InstructionStepEditorMobileListItemProps) {
return ( return (
<div <div
key={stepModel.id} key={stepModel.id}

View file

@ -1,7 +1,7 @@
import {closestCenter, DndContext, PointerSensor, useSensor, useSensors,} from "@dnd-kit/core"; import {closestCenter, DndContext, PointerSensor, useSensor, useSensors,} from "@dnd-kit/core";
import {arrayMove, SortableContext, verticalListSortingStrategy,} from "@dnd-kit/sortable"; import {arrayMove, SortableContext, verticalListSortingStrategy,} from "@dnd-kit/sortable";
import type {InstructionStepModel} from "../../models/InstructionStepModel"; import type {InstructionStepModel} from "../../models/InstructionStepModel";
import {InstructionStepDesktopListItem} from "./InstructionStepDesktopListItem"; import {InstructionStepEditorDesktopListItem} from "./InstructionStepEditorDesktopListItem.tsx";
import Button from "../basics/Button"; import Button from "../basics/Button";
import {Plus} from "lucide-react"; import {Plus} from "lucide-react";
import {ButtonType} from "../basics/BasicButtonDefinitions"; import {ButtonType} from "../basics/BasicButtonDefinitions";
@ -61,7 +61,7 @@ export function InstructionStepListDesktopEditor({
> >
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
{instructionStepList.map((step, index) => ( {instructionStepList.map((step, index) => (
<InstructionStepDesktopListItem <InstructionStepEditorDesktopListItem
key={step.internalId} key={step.internalId}
id={step.internalId} id={step.internalId}
index={index} index={index}

View file

@ -3,7 +3,7 @@ import type {InstructionStepModel} from "../../models/InstructionStepModel";
import Button from "../basics/Button"; import Button from "../basics/Button";
import {ButtonType} from "../basics/BasicButtonDefinitions"; import {ButtonType} from "../basics/BasicButtonDefinitions";
import {instructionStepListEditorMethods} from "./InstructionStepListEditorMethods.ts"; import {instructionStepListEditorMethods} from "./InstructionStepListEditorMethods.ts";
import {InstructionStepMobileListItem} from "./InstructionStepMobileListItem.tsx"; import {InstructionStepEditorMobileListItem} from "./InstructionStepEditorMobileListItem.tsx";
type InstructionStepListEditorMobileProps = { type InstructionStepListEditorMobileProps = {
instructionStepList: InstructionStepModel[]; instructionStepList: InstructionStepModel[];
@ -48,7 +48,7 @@ export function InstructionStepListMobileEditor({
{/* Instruction list */} {/* Instruction list */}
<div className="flex flex-col gap-3"> <div className="flex flex-col gap-3">
{instructionStepList.map((step, index) => ( {instructionStepList.map((step, index) => (
<InstructionStepMobileListItem <InstructionStepEditorMobileListItem
index={index} index={index}
stepModel={step} stepModel={step}
onMove={moveStep} onMove={moveStep}

View file

@ -14,6 +14,7 @@ import ContentBackground from "../basics/ContentBackground.tsx";
import ContentBody from "../basics/ContentBody.tsx"; import ContentBody from "../basics/ContentBody.tsx";
import PageContainer from "../basics/PageContainer.tsx"; import PageContainer from "../basics/PageContainer.tsx";
import {BoxContainer} from "../basics/BoxContainer.tsx"; import {BoxContainer} from "../basics/BoxContainer.tsx";
import IngredientGroupDisplayListItem from "./IngredientGroupDisplayListItem.tsx";
/** /**
@ -121,19 +122,10 @@ export default function RecipeDetailPage() {
<h2>Zutaten</h2> <h2>Zutaten</h2>
<ul> <ul>
{recipeWorkingCopy.ingredientGroupList.map((group, i) => ( {recipeWorkingCopy.ingredientGroupList.map((group, i) => (
<div key={i}> <IngredientGroupDisplayListItem
{/* the title is optional, only print if present */} index={i}
{group.title && group.title.trim() !== "" && ( groupModel={group}
<h3 className="highlight-container-bg mb-2">{group.title}</h3> />
)}
<ul>
{group.ingredientList.map((ing, j) => (
<li key={j} className="border-b border-gray-300 last:border-b-0 p-2">
{ing.amount ?? ""} {ing.unit ?? ""} {ing.name}
</li>
))}
</ul>
</div>
))} ))}
</ul> </ul>