Public
Back
Version 7
11/8/2024
/** @jsxImportSource https://esm.sh/react */
import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
interface Suggestion {
text: string;
imageUrl: string;
productUrl: string;
}
function App() {
const [age, setAge] = useState<string[]>([]);
const [gender, setGender] = useState<string[]>([]);
const [budget, setBudget] = useState<string[]>([]);
const [loading, setLoading] = useState(false);
const [suggestion, setSuggestion] = useState<Suggestion | null>(null);
const [error, setError] = useState<string | null>(null);
const [openDropdown, setOpenDropdown] = useState<string | null>(null);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError(null);
setSuggestion(null);
try {
const response = await fetch("/api/shopping-assistant", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ age, gender, budget }),
});
if (!response.ok) {
throw new Error("Failed to get suggestion");
}
trollishka-giftsuggestionapp.web.val.run
Updated: November 8, 2024