diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 381750d..250f446 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -7,58 +7,6 @@ import { ThemeProvider } from 'next-themes' const inter = Inter({ subsets: ['latin'] }) -export const metadata: Metadata = { - // Basic Metadata - title: { - default: 'HiveHaven - Student Accommodation Made Easy', - template: '%s | HiveHaven' - }, - description: 'Find your perfect student accommodation in the US with ease.', - keywords: ['student accommodation', 'US housing', 'international students'], - authors: [{ name: 'Ashutosh Pathak' }], - creator: 'Ashutosh Pathak', - - // Theme Color - themeColor: [ - { media: '(prefers-color-scheme: light)', color: 'white' }, - { media: '(prefers-color-scheme: dark)', color: 'black' } - ], - - // Open Graph Metadata - openGraph: { - type: 'website', - locale: 'en_US', - url: 'https://www.hive-haven.vercel.app/', - siteName: 'HiveHaven', - title: 'HiveHaven - Student Accommodation Made Easy', - description: 'Find your perfect student accommodation in the US with ease.', - images: [ - { - url: '#', - width: 1200, - height: 630, - alt: 'HiveHaven - Student Accommodation', - }, - ], - }, - - // Twitter Card Metadata - twitter: { - card: 'summary_large_image', - title: 'HiveHaven - Student Accommodation Made Easy', - description: 'Find your perfect student accommodation in the US with ease.', - images: ['#'], - creator: '@4shutoshpathak' - }, - - // Viewport Settings - viewport: { - width: 'device-width', - initialScale: 1, - maximumScale: 1, - }, -} - export default function RootLayout({ children, }: { diff --git a/src/app/page.tsx b/src/app/page.tsx index bfc5286..1078c2c 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,4 +1,4 @@ -import { createClient } from '@/lib/supabase-server' +import { hiveClient } from '@/lib/supabase-client' import Hero from '@/components/home/Hero' import FeaturedProperties from '@/components/home/FeaturedProperties' import HowItWorks from '@/components/home/HowItWorks' @@ -7,7 +7,7 @@ import WhyChooseUs from '@/components/home/WhyChooseUs' import CallToAction from '@/components/home/CallToAction' export default async function Home() { - const supabase = createClient() + const supabase = hiveClient const { data: properties, error: propertiesError } = await supabase .from('properties') diff --git a/src/app/properties/page.tsx b/src/app/properties/page.tsx index bacf52e..3969373 100644 --- a/src/app/properties/page.tsx +++ b/src/app/properties/page.tsx @@ -1,29 +1,5 @@ -// src/app/properties/page.tsx -import { createClient } from '@/lib/supabase-server' import PropertiesList from '@/components/PropertiesList' -import { Property } from '@/types/property' export default async function PropertiesPage() { - const supabase = createClient() - - const { data: properties, error } = await supabase - .from('properties') - .select(` - *, - property_images ( - id, - cloudinary_public_id, - cloudinary_url, - is_primary - ) - `) - .order('created_at', { ascending: false }) - - if (error) { - console.error('Error fetching properties:', error) - // Handle error appropriately - return
Error loading properties
- } - - return + return } \ No newline at end of file diff --git a/src/components/PropertiesList.tsx b/src/components/PropertiesList.tsx index 1ae8d9e..942c062 100644 --- a/src/components/PropertiesList.tsx +++ b/src/components/PropertiesList.tsx @@ -3,19 +3,56 @@ import Link from 'next/link' import { CldImage } from 'next-cloudinary' import { Database } from '@/types/supabase' +import { hiveClient } from '@/lib/supabase-client' +import { useEffect, useState } from 'react' type PropertyImagesRow = Database['hive']['Tables']['property_images']['Row'] type PropertyRow = Database['hive']['Tables']['properties']['Row'] type Property = PropertyRow & { - property_images: Pick[] + property_images: Pick[] } -interface PropertiesListProps { - properties: Property[] -} +export default function PropertiesList() { + const [properties, setProperties] = useState([]) + const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) + + useEffect(() => { + const fetchProperties = async () => { + setLoading(true) + const supabase = hiveClient + + try { + const { data, error } = await supabase + .from('properties') + .select(` + *, + property_images ( + id, + cloudinary_public_id, + cloudinary_url, + is_primary + ) + `) + .order('created_at', { ascending: false }) + + if (error) throw error + setProperties(data as Property[]) + } catch (err) { + setError('Error fetching properties') + console.error('Error fetching properties:', err) + } finally { + setLoading(false) + } + } + + fetchProperties() + }, []) + + if (loading) return
Loading properties...
+ if (error) return
{error}
-export default function PropertiesList({ properties }: PropertiesListProps) { return (
diff --git a/src/lib/supabase-client.ts b/src/lib/supabase-client.ts index 5d8ad04..5a8e916 100644 --- a/src/lib/supabase-client.ts +++ b/src/lib/supabase-client.ts @@ -4,8 +4,7 @@ import { Database } from '@/types/supabase' const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL! const supabaseAnonKey = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY! -if (!supabaseUrl || !supabaseAnonKey) { - throw new Error('Missing Supabase environment variables') -} +const supabase = createClient(supabaseUrl, supabaseAnonKey) -export const supabase = createClient(supabaseUrl, supabaseAnonKey) \ No newline at end of file +export const hiveClient = supabase.schema('hive') +export { supabase } \ No newline at end of file diff --git a/src/lib/supabase-server-client.ts b/src/lib/supabase-server-client.ts index 42a435b..79c1cd8 100644 --- a/src/lib/supabase-server-client.ts +++ b/src/lib/supabase-server-client.ts @@ -1,14 +1,10 @@ import { createClient } from '@supabase/supabase-js' import { Database } from '@/types/supabase' -const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL -const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY +const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL! +const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY! -if (!supabaseUrl || !supabaseServiceRoleKey) { - throw new Error('Missing Supabase environment variables') -} - -export const supabaseServerClient = createClient( +export const supabaseServerClient = createClient( supabaseUrl, supabaseServiceRoleKey, { @@ -17,4 +13,4 @@ export const supabaseServerClient = createClient( persistSession: false } } -) \ No newline at end of file +).schema('hive') \ No newline at end of file diff --git a/src/types/property.ts b/src/types/property.ts deleted file mode 100644 index d66b489..0000000 --- a/src/types/property.ts +++ /dev/null @@ -1,41 +0,0 @@ -export type User = { - id: string; - first_name?: string | null; - last_name?: string | null; - email?: string | null; - phone?: string | null; - user_type?: "student" | "landlord" | "admin"; - created_at?: string; - updated_at?: string; -}; - -export type PropertyImage = { - id: string; - property_id?: string; - cloudinary_public_id: string; - cloudinary_url: string; - is_primary: boolean; - created_at?: string; -}; - -export type Property = { - id: string; - landlord_id: string; - name: string; - description: string | null; - address: string; - city: string; - state: string; - zip_code: string; - country: string; - property_type: "apartment" | "house" | "dorm" | "shared_room"; - total_rooms: number | null; - bathrooms: number | null; - square_feet: number | null; - price_per_month: number; - is_available: boolean; - created_at: string; - updated_at: string; - users?: User | null; - property_images?: PropertyImage[]; -}; \ No newline at end of file