-
Notifications
You must be signed in to change notification settings - Fork 0
make a demo home page #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,65 +1,94 @@ | ||||||||||||||||||||
| import Image from "next/image"; | ||||||||||||||||||||
| "use client"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import { useState } from "react"; | ||||||||||||||||||||
| import ReactMarkdown from "react-markdown"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export default function Home() { | ||||||||||||||||||||
| const [url, setUrl] = useState(""); | ||||||||||||||||||||
| const [loading, setLoading] = useState(false); | ||||||||||||||||||||
| const [markdown, setMarkdown] = useState(""); | ||||||||||||||||||||
| const [error, setError] = useState(""); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const handleGenerate = async () => { | ||||||||||||||||||||
| setLoading(true); | ||||||||||||||||||||
| setError(""); | ||||||||||||||||||||
| setMarkdown(""); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| try { | ||||||||||||||||||||
| const response = await fetch("/api/generate", { | ||||||||||||||||||||
| method: "POST", | ||||||||||||||||||||
| headers: { "Content-Type": "application/json" }, | ||||||||||||||||||||
| body: JSON.stringify({ url }), | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const data = await response.json(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (!response.ok) throw new Error(data.error || "Failed to generate"); | ||||||||||||||||||||
|
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the API route is missing or the server returns a non-JSON response, Proposed fix: check status before parsing- const data = await response.json();
-
- if (!response.ok) throw new Error(data.error || "Failed to generate");
+ if (!response.ok) {
+ const data = await response.json().catch(() => ({}));
+ throw new Error(data.error || `Request failed (${response.status})`);
+ }
+
+ const data = await response.json();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
|
|
||||||||||||||||||||
| setMarkdown(data.markdown); | ||||||||||||||||||||
| } catch (err: unknown) { | ||||||||||||||||||||
| if (err instanceof Error) { | ||||||||||||||||||||
| setError(err.message); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| setError(String(err)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } finally { | ||||||||||||||||||||
| setLoading(false); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const copyToClipboard = () => { | ||||||||||||||||||||
| navigator.clipboard.writeText(markdown); | ||||||||||||||||||||
| alert("Copied to clipboard!"); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return ( | ||||||||||||||||||||
| <div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black"> | ||||||||||||||||||||
| <main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start"> | ||||||||||||||||||||
| <Image | ||||||||||||||||||||
| className="dark:invert" | ||||||||||||||||||||
| src="/next.svg" | ||||||||||||||||||||
| alt="Next.js logo" | ||||||||||||||||||||
| width={100} | ||||||||||||||||||||
| height={20} | ||||||||||||||||||||
| priority | ||||||||||||||||||||
| /> | ||||||||||||||||||||
| <div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left"> | ||||||||||||||||||||
| <h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50"> | ||||||||||||||||||||
| To get started, edit the page.tsx file. | ||||||||||||||||||||
| </h1> | ||||||||||||||||||||
| <p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400"> | ||||||||||||||||||||
| Looking for a starting point or more instructions? Head over to{" "} | ||||||||||||||||||||
| <a | ||||||||||||||||||||
| href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" | ||||||||||||||||||||
| className="font-medium text-zinc-950 dark:text-zinc-50" | ||||||||||||||||||||
| > | ||||||||||||||||||||
| Templates | ||||||||||||||||||||
| </a>{" "} | ||||||||||||||||||||
| or the{" "} | ||||||||||||||||||||
| <a | ||||||||||||||||||||
| href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" | ||||||||||||||||||||
| className="font-medium text-zinc-950 dark:text-zinc-50" | ||||||||||||||||||||
| > | ||||||||||||||||||||
| Learning | ||||||||||||||||||||
| </a>{" "} | ||||||||||||||||||||
| center. | ||||||||||||||||||||
| </p> | ||||||||||||||||||||
| <main className="min-h-screen bg-slate-950 text-slate-50 p-8"> | ||||||||||||||||||||
| <div className="max-w-4xl mx-auto space-y-8"> | ||||||||||||||||||||
| {/* Header */} | ||||||||||||||||||||
| <div className="text-center space-y-2"> | ||||||||||||||||||||
| <h1 className="text-4xl font-bold tracking-tight text-blue-400">ReadmeGenAI</h1> | ||||||||||||||||||||
| <p className="text-slate-400">Turn any GitHub URL into a professional README in seconds.</p> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| <div className="flex flex-col gap-4 text-base font-medium sm:flex-row"> | ||||||||||||||||||||
| <a | ||||||||||||||||||||
| className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]" | ||||||||||||||||||||
| href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" | ||||||||||||||||||||
| target="_blank" | ||||||||||||||||||||
| rel="noopener noreferrer" | ||||||||||||||||||||
| > | ||||||||||||||||||||
| <Image | ||||||||||||||||||||
| className="dark:invert" | ||||||||||||||||||||
| src="/vercel.svg" | ||||||||||||||||||||
| alt="Vercel logomark" | ||||||||||||||||||||
| width={16} | ||||||||||||||||||||
| height={16} | ||||||||||||||||||||
| /> | ||||||||||||||||||||
| Deploy Now | ||||||||||||||||||||
| </a> | ||||||||||||||||||||
| <a | ||||||||||||||||||||
| className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]" | ||||||||||||||||||||
| href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" | ||||||||||||||||||||
| target="_blank" | ||||||||||||||||||||
| rel="noopener noreferrer" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| {/* Input Section */} | ||||||||||||||||||||
| <div className="flex gap-4"> | ||||||||||||||||||||
| <input | ||||||||||||||||||||
| type="text" | ||||||||||||||||||||
| placeholder="https://github.com/username/repo" | ||||||||||||||||||||
| className="flex-1 bg-slate-900 border border-slate-800 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" | ||||||||||||||||||||
| value={url} | ||||||||||||||||||||
| onChange={(e) => setUrl(e.target.value)} | ||||||||||||||||||||
| /> | ||||||||||||||||||||
| <button | ||||||||||||||||||||
| onClick={handleGenerate} | ||||||||||||||||||||
| disabled={loading || !url} | ||||||||||||||||||||
| className="bg-blue-600 hover:bg-blue-500 disabled:opacity-50 px-6 py-2 rounded-lg font-medium transition-all" | ||||||||||||||||||||
| > | ||||||||||||||||||||
| Documentation | ||||||||||||||||||||
| </a> | ||||||||||||||||||||
| {loading ? "Generating..." : "Generate"} | ||||||||||||||||||||
| </button> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| </main> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| {error && <div className="p-4 bg-red-900/20 border border-red-900 text-red-400 rounded-lg">{error}</div>} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| {/* Output Section */} | ||||||||||||||||||||
| {markdown && ( | ||||||||||||||||||||
| <div className="space-y-4 animate-in fade-in duration-700"> | ||||||||||||||||||||
| <div className="flex justify-between items-center"> | ||||||||||||||||||||
| <h2 className="text-xl font-semibold text-slate-300">Preview</h2> | ||||||||||||||||||||
| <button | ||||||||||||||||||||
| onClick={copyToClipboard} | ||||||||||||||||||||
| className="text-sm bg-slate-800 hover:bg-slate-700 px-3 py-1 rounded border border-slate-700" | ||||||||||||||||||||
| > | ||||||||||||||||||||
| Copy Markdown | ||||||||||||||||||||
| </button> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| <div className="prose prose-invert max-w-none bg-slate-900 p-6 rounded-xl border border-slate-800 shadow-xl"> | ||||||||||||||||||||
| <ReactMarkdown>{markdown}</ReactMarkdown> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| )} | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| </main> | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: BeyteFlow/ReadmeGenAI
Length of output: 432
🏁 Script executed:
Repository: BeyteFlow/ReadmeGenAI
Length of output: 642
The
/api/generateroute is missing from the codebase and must be created.The component at line 18 makes a POST request to
/api/generate, but no API route file exists. Theapp/apidirectory and corresponding route handler are required for this feature to function.🤖 Prompt for AI Agents