feat: implement initial app layout and Supabase integration with item grid display
This commit is contained in:
parent
df039d08be
commit
3b180728e1
@ -12,17 +12,45 @@ const geistMono = Geist_Mono({
|
||||
});
|
||||
|
||||
export const metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
title: "MyFavStuff",
|
||||
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 }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased bg-neutral-900 text-neutral-100`}
|
||||
>
|
||||
<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>
|
||||
</html>
|
||||
);
|
||||
|
||||
@ -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 (
|
||||
<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-[32px] row-start-2 items-center sm:items-start">
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={180}
|
||||
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>
|
||||
<header className="mb-8">
|
||||
<h1 className="text-4xl font-bold text-neutral-100">My Favorite Stuff</h1>
|
||||
<p className="text-neutral-400">
|
||||
A curated list of things I've enjoyed, in reverse chronological order.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<div className="flex gap-4 items-center flex-col sm:flex-row">
|
||||
{fetchError && (
|
||||
<div className="bg-red-900 border border-red-700 text-red-100 px-4 py-3 rounded relative mb-6" role="alert">
|
||||
<strong className="font-bold">Error: </strong>
|
||||
<span className="block sm:inline">{fetchError}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!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
|
||||
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"
|
||||
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"
|
||||
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
|
||||
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
|
||||
Add New Item
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
<footer className="row-start-3 flex gap-[24px] 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="/file.svg"
|
||||
alt="File icon"
|
||||
width={16}
|
||||
height={16}
|
||||
)}
|
||||
|
||||
{items.length > 0 && (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{items.map((item) => (
|
||||
<div key={item.id} className="bg-neutral-800 rounded-lg shadow-lg p-4 flex flex-col">
|
||||
{item.image_url ? (
|
||||
<div className="aspect-[3/4] w-full bg-neutral-700 rounded mb-3 overflow-hidden">
|
||||
<img
|
||||
src={item.image_url}
|
||||
alt={item.title || 'Item image'}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300 ease-in-out"
|
||||
/>
|
||||
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="/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="/globe.svg"
|
||||
alt="Globe icon"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Go to nextjs.org →
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
) : (
|
||||
<div className="aspect-[3/4] w-full bg-neutral-700 rounded mb-3 flex items-center justify-center">
|
||||
<span className="text-neutral-500 text-sm">No Image</span>
|
||||
</div>
|
||||
)}
|
||||
<h2 className="text-xl font-semibold mb-1 text-neutral-100 truncate" title={item.title}>{item.title || 'Untitled'}</h2>
|
||||
<p className="text-sm text-neutral-400 mb-1 capitalize">{item.type || 'N/A'}</p>
|
||||
{typeof item.rating === 'number' && <StarRating rating={item.rating} />}
|
||||
{item.notes && (
|
||||
<p className="text-xs text-neutral-500 mt-2 flex-grow overflow-hidden line-clamp-3">
|
||||
{item.notes}
|
||||
</p>
|
||||
)}
|
||||
{/* Placeholder for a details link/modal trigger */}
|
||||
{/* <a href={`/item/${item.id}`} className="text-sky-400 hover:text-sky-300 text-sm mt-auto pt-2">
|
||||
View Details
|
||||
</a> */}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
23
myfavstuff/lib/supabaseClient.js
Normal file
23
myfavstuff/lib/supabaseClient.js
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user