feat: connect title and description inputs to state

- Add updateTitle prop to Frame component
- Add handleUpdateFrameTitle to useNewGuide hook
- Wire onChange handlers for guide title, description, and frame title inputs
This commit is contained in:
johannes-hernehult 2026-06-15 11:18:34 +02:00
parent 0f70457d29
commit b95d687904
3 changed files with 28 additions and 8 deletions

View file

@ -7,23 +7,27 @@ export default function Frame({
addStep, addStep,
removeStep, removeStep,
updateStep, updateStep,
updateTitle,
}: { }: {
frame: FrameType; frame: FrameType;
onRemove: (frameId: string) => void; onRemove: (frameId: string) => void;
addStep: (frameId: string) => void; addStep: (frameId: string) => void;
removeStep: (stepId: string) => void; removeStep: (stepId: string) => void;
updateStep: (stepId: string, text: string) => void; updateStep: (stepId: string, text: string) => void;
updateTitle: (frameId: string, title: string) => void;
}) { }) {
return ( return (
<div> <div>
<button type="button" onClick={() => onRemove(frame.id)}> <button type="button" onClick={() => onRemove(frame.id)}>
Remove Frame Remove Frame
</button> </button>
<label>Title</label> <label>
<input Title
type="text" <input
onChange={(e) => updateStep(frame.id, e.target.value)} type="text"
/> onChange={(e) => updateTitle(frame.id, e.target.value)}
/>
</label>
<img src={URL.createObjectURL(frame.file)} alt={frame.title} /> <img src={URL.createObjectURL(frame.file)} alt={frame.title} />
<button type="button" onClick={() => addStep(frame.id)}> <button type="button" onClick={() => addStep(frame.id)}>
Add Step Add Step

View file

@ -44,6 +44,12 @@ export default function useNewGuide() {
setFrames((prev) => [...prev, ...newFrameObjects]); setFrames((prev) => [...prev, ...newFrameObjects]);
}; };
const handleUpdateFrameTitle = (frameId: string, title: string) => {
setFrames((prev) =>
prev.map((frame) => (frame.id === frameId ? { ...frame, title } : frame)),
);
};
const handleRemoveFrame = (frameId: string) => { const handleRemoveFrame = (frameId: string) => {
setFrames((prev) => prev.filter((frame) => frame.id !== frameId)); setFrames((prev) => prev.filter((frame) => frame.id !== frameId));
}; };
@ -116,6 +122,7 @@ export default function useNewGuide() {
handleUpdateTitle, handleUpdateTitle,
handleUpdateDescription, handleUpdateDescription,
handleAddFrames, handleAddFrames,
handleUpdateFrameTitle,
handleAddSteps, handleAddSteps,
handleRemoveFrame, handleRemoveFrame,
handleUpdateStep, handleUpdateStep,

View file

@ -9,6 +9,7 @@ export default function NewGuide() {
handleUpdateTitle, handleUpdateTitle,
handleUpdateDescription, handleUpdateDescription,
handleAddFrames, handleAddFrames,
handleUpdateFrameTitle,
handleAddSteps, handleAddSteps,
handleRemoveFrame, handleRemoveFrame,
handleRemoveStep, handleRemoveStep,
@ -21,11 +22,18 @@ export default function NewGuide() {
<form className="new-guide__form" onSubmit={(e) => handleSaveGuide(e)}> <form className="new-guide__form" onSubmit={(e) => handleSaveGuide(e)}>
<label> <label>
<span>Title</span> <span>Title</span>
<input type="text" name="title" /> <input
type="text"
name="title"
onChange={(e) => handleUpdateTitle(e.target.value)}
/>
</label> </label>
<label> <label>
<span>Description</span> <span>Description</span>
<textarea name="description" /> <textarea
name="description"
onChange={(e) => handleUpdateDescription(e.target.value)}
/>
</label> </label>
<FileUpload onChange={handleAddFrames} /> <FileUpload onChange={handleAddFrames} />
@ -37,8 +45,9 @@ export default function NewGuide() {
frame={frame} frame={frame}
onRemove={handleRemoveFrame} onRemove={handleRemoveFrame}
addStep={handleAddSteps} addStep={handleAddSteps}
removeStep={handleRemoveStep}
updateStep={handleUpdateStep} updateStep={handleUpdateStep}
removeStep={handleRemoveStep}
updateTitle={handleUpdateFrameTitle}
/> />
))} ))}