feat: implement initial app layout and Supabase integration with item grid display

This commit is contained in:
Greg 2025-05-18 16:03:53 +02:00
parent df039d08be
commit 3b180728e1
3 changed files with 152 additions and 98 deletions

View File

@ -12,17 +12,45 @@ const geistMono = Geist_Mono({
}); });
export const metadata = { export const metadata = {
title: "Create Next App", title: "MyFavStuff",
description: "Generated by create next app", description: "A curated collection of favorite things.",
}; };
// Basic Navbar component (can be moved to its own file later)
function Navbar() {
return (
<nav className="bg-neutral-800 text-white p-4">
<div className="container mx-auto flex justify-between items-center">
<a href="/" className="text-xl font-bold hover:text-neutral-300">
MyFavStuff
</a>
<div>
{/* Future: Add Item link for admin, Auth links */}
<a href="/add-item" className="px-3 py-2 rounded hover:bg-neutral-700">
Add Item
</a>
<a href="/login" className="ml-2 px-3 py-2 rounded hover:bg-neutral-700">
Login
</a>
</div>
</div>
</nav>
);
}
export default function RootLayout({ children }) { export default function RootLayout({ children }) {
return ( return (
<html lang="en"> <html lang="en">
<body <body
className={`${geistSans.variable} ${geistMono.variable} antialiased`} className={`${geistSans.variable} ${geistMono.variable} antialiased bg-neutral-900 text-neutral-100`}
> >
{children} <Navbar />
<main className="container mx-auto p-4 md:p-8">
{children}
</main>
<footer className="text-center p-4 text-neutral-500 text-sm">
© {new Date().getFullYear()} MyFavStuff. All rights reserved.
</footer>
</body> </body>
</html> </html>
); );

View File

@ -1,103 +1,106 @@
import Image from "next/image"; import { supabase } from '../lib/supabaseClient';
// Function to generate star ratings
const StarRating = ({ rating }) => {
const totalStars = 5;
let stars = [];
for (let i = 1; i <= totalStars; i++) {
stars.push(
<span key={i} className={i <= rating ? 'text-yellow-400' : 'text-neutral-600'}>
</span>
);
}
return <div className="flex">{stars}</div>;
};
export default async function Home() {
let items = [];
let fetchError = null;
if (supabase) {
try {
const { data, error } = await supabase
.from('items')
.select('*')
.order('created_at', { ascending: false }); // Assuming you have a created_at timestamp
if (error) {
throw error;
}
items = data || [];
} catch (error) {
console.error('Error fetching items:', error.message);
fetchError = 'Could not fetch items. Please check the connection and try again.';
// If Supabase client isn't initialized (e.g. missing .env.local), items will remain []
// and this error message will be displayed if supabase itself was the issue.
}
} else {
fetchError = 'Supabase client is not initialized. Please check your .env.local file and ensure it has the correct Supabase URL and Anon key.';
}
export default function Home() {
return ( 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)]"> <div>
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start"> <header className="mb-8">
<Image <h1 className="text-4xl font-bold text-neutral-100">My Favorite Stuff</h1>
className="dark:invert" <p className="text-neutral-400">
src="/next.svg" A curated list of things I've enjoyed, in reverse chronological order.
alt="Next.js logo" </p>
width={180} </header>
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm/6 text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2 tracking-[-.01em]">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-[family-name:var(--font-geist-mono)] font-semibold">
app/page.js
</code>
.
</li>
<li className="tracking-[-.01em]">
Save and see your changes instantly.
</li>
</ol>
<div className="flex gap-4 items-center flex-col sm:flex-row"> {fetchError && (
<a <div className="bg-red-900 border border-red-700 text-red-100 px-4 py-3 rounded relative mb-6" role="alert">
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] font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:w-auto" <strong className="font-bold">Error: </strong>
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" <span className="block sm:inline">{fetchError}</span>
target="_blank" </div>
rel="noopener noreferrer" )}
{!fetchError && items.length === 0 && (
<div className="text-center text-neutral-500 py-10">
<p>No items added yet. Start by adding your favorite books, movies, or series!</p>
<a
href="/add-item" // We'll create this page later
className="mt-4 inline-block bg-sky-600 hover:bg-sky-700 text-white font-semibold py-2 px-4 rounded transition-colors"
> >
<Image Add New Item
className="dark:invert"
src="/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 font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 w-full sm:w-auto 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"
>
Read our docs
</a> </a>
</div> </div>
</main> )}
<footer className="row-start-3 flex gap-[24px] flex-wrap items-center justify-center">
<a {items.length > 0 && (
className="flex items-center gap-2 hover:underline hover:underline-offset-4" <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app" {items.map((item) => (
target="_blank" <div key={item.id} className="bg-neutral-800 rounded-lg shadow-lg p-4 flex flex-col">
rel="noopener noreferrer" {item.image_url ? (
> <div className="aspect-[3/4] w-full bg-neutral-700 rounded mb-3 overflow-hidden">
<Image <img
aria-hidden src={item.image_url}
src="/file.svg" alt={item.title || 'Item image'}
alt="File icon" className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300 ease-in-out"
width={16} />
height={16} </div>
/> ) : (
Learn <div className="aspect-[3/4] w-full bg-neutral-700 rounded mb-3 flex items-center justify-center">
</a> <span className="text-neutral-500 text-sm">No Image</span>
<a </div>
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" <h2 className="text-xl font-semibold mb-1 text-neutral-100 truncate" title={item.title}>{item.title || 'Untitled'}</h2>
target="_blank" <p className="text-sm text-neutral-400 mb-1 capitalize">{item.type || 'N/A'}</p>
rel="noopener noreferrer" {typeof item.rating === 'number' && <StarRating rating={item.rating} />}
> {item.notes && (
<Image <p className="text-xs text-neutral-500 mt-2 flex-grow overflow-hidden line-clamp-3">
aria-hidden {item.notes}
src="/window.svg" </p>
alt="Window icon" )}
width={16} {/* Placeholder for a details link/modal trigger */}
height={16} {/* <a href={`/item/${item.id}`} className="text-sky-400 hover:text-sky-300 text-sm mt-auto pt-2">
/> View Details
Examples </a> */}
</a> </div>
<a ))}
className="flex items-center gap-2 hover:underline hover:underline-offset-4" </div>
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="/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to nextjs.org
</a>
</footer>
</div> </div>
); );
} }

View File

@ -0,0 +1,23 @@
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL;
const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
if (!supabaseUrl) {
console.error('Error: Missing Supabase URL. Please set NEXT_PUBLIC_SUPABASE_URL in .env.local');
}
if (!supabaseAnonKey) {
console.error('Error: Missing Supabase Anon Key. Please set NEXT_PUBLIC_SUPABASE_ANON_KEY in .env.local');
}
// Ensure client is only created if keys are present, to avoid errors during build or in environments where keys might not be set.
// The actual fetch operations in components should handle cases where supabase might not be initialized.
let supabaseInstance = null;
if (supabaseUrl && supabaseAnonKey) {
supabaseInstance = createClient(supabaseUrl, supabaseAnonKey);
} else {
console.warn('Supabase client not initialized due to missing URL or Anon Key. App will run without Supabase functionality.');
}
export const supabase = supabaseInstance;