new: minimum viable product achieved

This commit is contained in:
ryana mittens 2024-09-06 11:36:37 +08:00
parent 151eb060d2
commit bd84089d7b
13 changed files with 111 additions and 163 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Binary file not shown.

View file

@ -1,27 +0,0 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
:root {
--background: #ffffff;
--foreground: #171717;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}
@layer utilities {
.text-balance {
text-wrap: balance;
}
}

View file

@ -1,35 +0,0 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";
const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}

View file

@ -1,101 +0,0 @@
import Image from "next/image";
export default function Home() {
return (
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
<Image
className="dark:invert"
src="https://nextjs.org/icons/next.svg"
alt="Next.js logo"
width={180}
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
src/app/page.tsx
</code>
.
</li>
<li>Save and see your changes instantly.</li>
</ol>
<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
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="https://nextjs.org/icons/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Deploy now
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
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"
>
Read our docs
</a>
</div>
</main>
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/file.svg"
alt="File icon"
width={16}
height={16}
/>
Learn
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Examples
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="https://nextjs.org/icons/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to nextjs.org
</a>
</footer>
</div>
);
}

View file

@ -0,0 +1,9 @@
const Header = () => (
<header className="py-4">
<h1 className="text-3xl font-bold">
Stock Price Application
</h1>
</header>
)
export default Header

View file

@ -0,0 +1,52 @@
import { useState } from 'react'
const StockPrice = () => {
const [symbol, setSymbol] = useState('')
const [price, setPrice] = useState<number | null>(null)
const [error, setError] = useState('')
const fetchStockPrice = async () => {
setError('')
try {
const res = await fetch(`/api/quote?symbol=${symbol}`)
const data = await res.json()
if (data.error) {
setError(data.error)
} else {
setPrice(data.c)
}
} catch (err) {
setError('Failed to fetch stock price')
}
}
return (
<div className="my-4">
<input
type="text"
placeholder="Enter stock symbol"
value={symbol}
onChange={(e) => setSymbol(e.target.value)}
className="border p-2 mr-2"
/>
<button
onClick={fetchStockPrice}
className="bg-blue-500 text-white p-2"
>
Get Price
</button>
{price !== null && (
<div className="mt-4">
<p>Current Price: ${price}</p>
</div>
)}
{error && (
<div className="mt-4 text-red-500">
<p>{error}</p>
</div>
)}
</div>
)
}
export default StockPrice

6
src/pages/_app.tsx Normal file
View file

@ -0,0 +1,6 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}

20
src/pages/api/quote.ts Normal file
View file

@ -0,0 +1,20 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { fetchQuote } from "../../utils/sparkle";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { symbol } = req.query;
if (!symbol || typeof symbol !== "string") {
res.status(400).json({ error: "Invalid symbol" });
return;
}
try {
const quote = await fetchQuote(symbol);
res.status(200).json(quote);
} catch (error) {
res.status(500).json({ error: "Error fetching quote" });
}
}

11
src/pages/index.tsx Normal file
View file

@ -0,0 +1,11 @@
import Header from '../components/Header'
import StockPrice from '../components/StockPrice'
export default function Home() {
return (
<div className="container mx-auto p-4">
<Header />
<StockPrice />
</div>
)
}

3
src/styles/globals.css Normal file
View file

@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

10
src/utils/sparkle.ts Normal file
View file

@ -0,0 +1,10 @@
const SPARKLE_BASE_URL = process.env.NEXT_PUBLIC_SPARKLE_BASE_URL;
export const fetchQuote = async (symbol: string) => {
const url = `${SPARKLE_BASE_URL}/quote?symbol=${symbol}`
const res = await fetch(url)
if (!res.ok) {
throw new Error('Error fetching quote')
}
return res.json()
}