feat: add support for prefilled image URL in recipe creation and display
This commit is contained in:
@@ -44,6 +44,9 @@ export default function CreateRecipePage() {
|
||||
// Omdirigera till /recipes/write med förifylld Markdown
|
||||
// Vi använder sessionStorage för att passa data mellan sidor
|
||||
sessionStorage.setItem('prefilled_markdown', data.markdown);
|
||||
if (data.imageUrl) {
|
||||
sessionStorage.setItem('prefilled_image_url', data.imageUrl);
|
||||
}
|
||||
router.push('/recipes/write');
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -58,6 +58,11 @@ export default function WriteRecipePage() {
|
||||
|
||||
// Kontrollera om det finns förifylld Markdown från snabbimport
|
||||
const prefilledMarkdown = sessionStorage.getItem('prefilled_markdown');
|
||||
const prefilledImageUrl = sessionStorage.getItem('prefilled_image_url');
|
||||
if (prefilledImageUrl) {
|
||||
setImageUrl(prefilledImageUrl);
|
||||
sessionStorage.removeItem('prefilled_image_url');
|
||||
}
|
||||
if (prefilledMarkdown) {
|
||||
setMarkdown(prefilledMarkdown);
|
||||
sessionStorage.removeItem('prefilled_markdown');
|
||||
@@ -174,6 +179,7 @@ export default function WriteRecipePage() {
|
||||
name: editedName,
|
||||
description: editedDescription || undefined,
|
||||
instructions: editedInstructions || undefined,
|
||||
imageUrl: imageUrl || undefined,
|
||||
ingredients: validIngredients.map((ing) => ({
|
||||
productId: ing.selectedProductId,
|
||||
quantity: Number(ing.editedQuantity),
|
||||
@@ -305,6 +311,24 @@ Stek löken i lite smör. Tillsätt köttfärsen...`}</pre>
|
||||
<div style={{ display: 'grid', gap: '1rem', padding: '1rem', border: '1px solid #ddd', borderRadius: '8px' }}>
|
||||
<h2 style={{ margin: 0, fontSize: '1.1rem' }}>Receptdetaljer</h2>
|
||||
|
||||
{imageUrl && (
|
||||
<div>
|
||||
<label style={{ display: 'block', marginBottom: '0.5rem', fontWeight: 600 }}>Bild</label>
|
||||
<img
|
||||
src={imageUrl}
|
||||
alt="Receptbild"
|
||||
style={{ width: '100%', maxHeight: '220px', objectFit: 'cover', borderRadius: '6px', border: '1px solid #ddd' }}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setImageUrl(null)}
|
||||
style={{ marginTop: '0.4rem', fontSize: '0.8rem', color: '#dc2626', background: 'none', border: 'none', cursor: 'pointer', padding: 0 }}
|
||||
>
|
||||
Ta bort bild
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<label style={{ display: 'block', marginBottom: '0.5rem', fontWeight: 600 }}>Receptnamn *</label>
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user