diff --git a/backend/src/quick-import/quick-import.service.ts b/backend/src/quick-import/quick-import.service.ts index 2a6d3542..c33bc3b7 100644 --- a/backend/src/quick-import/quick-import.service.ts +++ b/backend/src/quick-import/quick-import.service.ts @@ -12,6 +12,7 @@ export class QuickImportService { */ async importFromInput(input: string): Promise { input = input.trim(); + console.log('[QuickImport] Mottog input:', input); if (!input) { throw new BadRequestException('Du måste ange en URL eller filsökväg'); @@ -21,20 +22,26 @@ export class QuickImportService { const isUrl = this.isUrl(input); const isPdf = this.isPdfPath(input); + console.log('[QuickImport] isUrl:', isUrl, 'isPdf:', isPdf); + if (isUrl) { // Försök detektera webbplats if (input.includes('ica.se')) { + console.log('[QuickImport] Detekterade ICA-länk, startar skrapning...'); return this.scrapeIcaRecipe(input); } else { + console.log('[QuickImport] URL är inte från ICA.se'); throw new BadRequestException( 'Endast ICA-recept stöds för närvarande. Försök med en ICA-länk (ica.se)' ); } } else if (isPdf) { + console.log('[QuickImport] PDF-fil identifierad'); throw new BadRequestException( 'PDF-import är under utveckling. Använd snabbimport för ICA-recept eller skriv in receptet manuellt.' ); } else { + console.log('[QuickImport] Input är inte URL eller PDF'); throw new BadRequestException( 'Ogültig input. Ange en gyltig URL (t.ex. ica.se/recept/...) eller filsökväg' ); @@ -74,6 +81,8 @@ export class QuickImportService { */ private async scrapeIcaRecipe(url: string): Promise { try { + console.log('[QuickImport] Hämtar HTML från:', url); + // Hämta HTML från URL const response = await fetch(url, { headers: { @@ -82,14 +91,18 @@ export class QuickImportService { }, }); + console.log('[QuickImport] HTTP status:', response.status); + if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const html = await response.text(); + console.log('[QuickImport] HTML längd:', html.length, 'tecken'); // Extrahera receptinformation från HTML const recipe = this.parseIcaHtml(html); + console.log('[QuickImport] Parsad recept:', { name: recipe.name, ingredienser: recipe.ingredients.length }); if (!recipe.name) { throw new Error('Kunde inte hitta receptnamn på sidan. Försök med en annan länk.'); @@ -97,6 +110,7 @@ export class QuickImportService { // Konvertera till Markdown-format const markdown = this.recipeToMarkdown(recipe); + console.log('[QuickImport] Markdown genererad, längd:', markdown.length); return { markdown, @@ -104,6 +118,7 @@ export class QuickImportService { }; } catch (err) { const message = err instanceof Error ? err.message : 'Okänt fel vid scraping'; + console.error('[QuickImport] ERROR:', message); throw new BadRequestException( `Kunde inte hämta recept från ICA: ${message}. Kontrollera att länken är korrekt och försök igen.` ); diff --git a/frontend/app/Navigation.tsx b/frontend/app/Navigation.tsx index 6da06187..ccbeac90 100644 --- a/frontend/app/Navigation.tsx +++ b/frontend/app/Navigation.tsx @@ -75,7 +75,7 @@ export default function Navigation() { ⚙️ Admin - 📥 Importera recept + ⚡ Snabbimport recept ); diff --git a/frontend/app/admin/products/ExpandableCreateProductSection.tsx b/frontend/app/admin/products/ExpandableCreateProductSection.tsx new file mode 100644 index 00000000..a71222dd --- /dev/null +++ b/frontend/app/admin/products/ExpandableCreateProductSection.tsx @@ -0,0 +1,54 @@ +'use client'; + +import { useState } from 'react'; +import ProductForm from '../../inventory/ProductForm'; + +export default function ExpandableCreateProductSection() { + const [isExpanded, setIsExpanded] = useState(false); + + return ( +
+ + + {isExpanded && ( +
+ +
+ )} +
+ ); +} diff --git a/frontend/app/admin/products/MergePreviewForm.tsx b/frontend/app/admin/products/MergePreviewForm.tsx index 02cfb658..3b1ae357 100644 --- a/frontend/app/admin/products/MergePreviewForm.tsx +++ b/frontend/app/admin/products/MergePreviewForm.tsx @@ -16,6 +16,7 @@ export default function MergePreviewForm({ products }: Props) { const [successMessage, setSuccessMessage] = useState(null); const [isPending, startTransition] = useTransition(); const [isConfirming, setIsConfirming] = useState(false); + const [isExpanded, setIsExpanded] = useState(false); const fetchPreview = () => { setError(null); @@ -89,15 +90,44 @@ export default function MergePreviewForm({ products }: Props) { return (
-

Förhandsgranska merge

+ + + {isExpanded && ( +
- ) : null} + )}
); } \ No newline at end of file diff --git a/frontend/app/admin/products/page.tsx b/frontend/app/admin/products/page.tsx index 2137c686..2181dede 100644 --- a/frontend/app/admin/products/page.tsx +++ b/frontend/app/admin/products/page.tsx @@ -3,6 +3,7 @@ import type { Product } from '../../../features/inventory/types'; import MergePreviewForm from './MergePreviewForm'; import AdminProductList from './AdminProductList'; import Navigation from '../../Navigation'; +import ExpandableCreateProductSection from './ExpandableCreateProductSection'; export default async function AdminProductsPage() { const products = await fetchJson('/api/products'); @@ -13,6 +14,8 @@ export default async function AdminProductsPage() {

Admin: Produkter

Här kan du granska och standardisera produktnamn.

+ + diff --git a/frontend/app/inventory/page.tsx b/frontend/app/inventory/page.tsx index 57170a50..ba1463cc 100644 --- a/frontend/app/inventory/page.tsx +++ b/frontend/app/inventory/page.tsx @@ -1,5 +1,4 @@ import InventoryForm from './InventoryForm'; -import ProductForm from './ProductForm'; import Link from 'next/link'; import { fetchJson } from '../../lib/api'; import type { InventoryItem, Product } from '../../features/inventory/types'; @@ -109,7 +108,6 @@ export default async function InventoryPage({ searchParams }: InventoryPageProps

Varor hemma

-