diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..bffb357 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next/core-web-vitals" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1dda53a --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +node_modules +.next +.DS_Store +.env + +# Ignore archive copy bundled in repo +"aigiftgen_v101 2/" diff --git a/app/GiftForm.tsx b/app/GiftForm.tsx new file mode 100644 index 0000000..904eb6d --- /dev/null +++ b/app/GiftForm.tsx @@ -0,0 +1,105 @@ +'use client'; + +import { FormEvent, useState } from 'react'; +import Idea from './Idea'; + +const DEFAULT_TAG = process.env.NEXT_PUBLIC_AMAZON_TAG || 'yourtag-21'; + +export default function GiftForm() { + const [who, setWho] = useState('my outdoorsy sister who loves hiking'); + const [ideas, setIdeas] = useState([]); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(''); + const [affiliateTag, setAffiliateTag] = useState(DEFAULT_TAG); + + async function handleSubmit(event: FormEvent) { + event.preventDefault(); + if (!who.trim()) { + setError('Tell AI Santa who you are shopping for first.'); + return; + } + + setLoading(true); + setError(''); + + try { + const resp = await fetch('/', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ who }), + }); + + if (!resp.ok) { + const data = await resp.json().catch(() => ({})); + throw new Error(data.error || 'Something went wrong. Please try again.'); + } + + const data = await resp.json(); + setIdeas(Array.isArray(data.ideas) ? data.ideas : []); + } catch (err: any) { + setError(err.message || 'Unable to fetch ideas right now.'); + setIdeas([]); + } finally { + setLoading(false); + } + } + + return ( +
+
+
+ +