Skip to content

Commit

Permalink
Fix dynamic page issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pathak-ashutosh committed Jul 5, 2024
1 parent 8f02d43 commit 19ef976
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 137 deletions.
52 changes: 0 additions & 52 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}: {
Expand Down
4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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')
Expand Down
26 changes: 1 addition & 25 deletions src/app/properties/page.tsx
Original file line number Diff line number Diff line change
@@ -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 <div>Error loading properties</div>
}

return <PropertiesList properties={properties} />
return <PropertiesList />
}
47 changes: 42 additions & 5 deletions src/components/PropertiesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertyImagesRow, 'id' | 'cloudinary_public_id' | 'cloudinary_url' | 'is_primary'>[]
property_images: Pick<PropertyImagesRow, 'id' | 'cloudinary_public_id' | 'is_primary'>[]
}

interface PropertiesListProps {
properties: Property[]
}
export default function PropertiesList() {
const [properties, setProperties] = useState<Property[]>([])
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(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 <div>Loading properties...</div>
if (error) return <div>{error}</div>

export default function PropertiesList({ properties }: PropertiesListProps) {
return (
<div className="bg-background text-foreground">
<section className="py-20">
Expand Down
7 changes: 3 additions & 4 deletions src/lib/supabase-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>(supabaseUrl, supabaseAnonKey)

export const supabase = createClient<Database['hive']>(supabaseUrl, supabaseAnonKey)
export const hiveClient = supabase.schema('hive')
export { supabase }
12 changes: 4 additions & 8 deletions src/lib/supabase-server-client.ts
Original file line number Diff line number Diff line change
@@ -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<Database['hive']>(
export const supabaseServerClient = createClient<Database>(
supabaseUrl,
supabaseServiceRoleKey,
{
Expand All @@ -17,4 +13,4 @@ export const supabaseServerClient = createClient<Database['hive']>(
persistSession: false
}
}
)
).schema('hive')
41 changes: 0 additions & 41 deletions src/types/property.ts

This file was deleted.

0 comments on commit 19ef976

Please sign in to comment.