diff --git a/app/page.tsx b/app/page.tsx index fb4189f..1ab37c0 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,17 +1,55 @@ 'use client' +import { useEffect, useState } from 'react' import Link from 'next/link' import { useAuth } from '@/lib/auth/context' import { initiateOAuthFlow, initiateSignupFlow } from '@/lib/api/oauth' +import { listSites, deleteSite, type Site } from '@/lib/api/sites' import { LoadingOverlay } from '@ciphera-net/ui' import SiteList from '@/components/sites/SiteList' import { Button } from '@ciphera-net/ui' import { BarChartIcon, LockIcon, ZapIcon } from '@ciphera-net/ui' +import { toast } from 'sonner' export default function HomePage() { - const { user, loading } = useAuth() + const { user, loading: authLoading } = useAuth() + const [sites, setSites] = useState([]) + const [sitesLoading, setSitesLoading] = useState(true) - if (loading) { + useEffect(() => { + if (user) { + loadSites() + } + }, [user]) + + const loadSites = async () => { + try { + setSitesLoading(true) + const data = await listSites() + setSites(Array.isArray(data) ? data : []) + } catch (error: any) { + toast.error('Failed to load sites: ' + (error.message || 'Unknown error')) + setSites([]) + } finally { + setSitesLoading(false) + } + } + + const handleDelete = async (id: string) => { + if (!confirm('Are you sure you want to delete this site? This action cannot be undone.')) { + return + } + + try { + await deleteSite(id) + toast.success('Site deleted successfully') + loadSites() + } catch (error: any) { + toast.error('Failed to delete site: ' + (error.message || 'Unknown error')) + } + } + + if (authLoading) { return } @@ -95,7 +133,7 @@ export default function HomePage() { } return ( -
+

Your Sites

@@ -103,7 +141,24 @@ export default function HomePage() {
Add New Site
- + + {/* Global Overview */} +
+
+

Total Sites

+

{sites.length}

+
+
+

Total Visitors (24h)

+

--

+
+
+

Plan Status

+

Pro Plan

+
+
+ +
) -} +} \ No newline at end of file diff --git a/components/sites/SiteList.tsx b/components/sites/SiteList.tsx index 03a737d..fc9a39b 100644 --- a/components/sites/SiteList.tsx +++ b/components/sites/SiteList.tsx @@ -1,51 +1,27 @@ 'use client' -import { useEffect, useState } from 'react' import Link from 'next/link' -import { listSites, deleteSite, type Site } from '@/lib/api/sites' -import { toast } from 'sonner' -import { LoadingOverlay } from '@ciphera-net/ui' +import { Site } from '@/lib/api/sites' +import { BarChartIcon, SettingsIcon, BookOpenIcon, ExternalLinkIcon } from '@ciphera-net/ui' import { useAuth } from '@/lib/auth/context' -import { BarChartIcon } from '@ciphera-net/ui' -export default function SiteList() { +interface SiteListProps { + sites: Site[] + loading: boolean + onDelete: (id: string) => void +} + +export default function SiteList({ sites, loading, onDelete }: SiteListProps) { const { user } = useAuth() - const [sites, setSites] = useState([]) - const [loading, setLoading] = useState(true) - - useEffect(() => { - loadSites() - }, []) - - const loadSites = async () => { - try { - setLoading(true) - const data = await listSites() - setSites(Array.isArray(data) ? data : []) - } catch (error: any) { - toast.error('Failed to load sites: ' + (error.message || 'Unknown error')) - setSites([]) // Ensure sites is always an array - } finally { - setLoading(false) - } - } - - const handleDelete = async (id: string) => { - if (!confirm('Are you sure you want to delete this site? This action cannot be undone.')) { - return - } - - try { - await deleteSite(id) - toast.success('Site deleted successfully') - loadSites() - } catch (error: any) { - toast.error('Failed to delete site: ' + (error.message || 'Unknown error')) - } - } if (loading) { - return + return ( +
+ {[1, 2, 3].map((i) => ( +
+ ))} +
+ ) } if (sites.length === 0) { @@ -58,18 +34,67 @@ export default function SiteList() { } return ( -
+
{sites.map((site) => (
-

{site.name}

-

{site.domain}

-
+ {/* Header: Icon + Name + Live Status */} +
+
+ {/* Auto-fetch favicon */} +
+ {site.name} +
+
+

{site.name}

+
+ {site.domain} + e.stopPropagation()} + > + + +
+
+
+ + {/* "Live" Indicator */} +
+ + + + + Active +
+
+ + {/* Mini Stats Grid */} +
+
+

Visitors (24h)

+

--

+
+
+

Pageviews

+

--

+
+
+ + {/* Actions */} +
View Dashboard @@ -77,15 +102,28 @@ export default function SiteList() { {(user?.role === 'owner' || user?.role === 'admin') && ( )}
))} + + {/* Resources Card */} +
+
+ +
+

Need help setup?

+

Check our documentation for installation guides.

+ + Read Documentation → + +
) } diff --git a/package.json b/package.json index 6f4a04d..7b4d3c2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "type-check": "tsc --noEmit" }, "dependencies": { - "@ciphera-net/ui": "^0.0.20", + "@ciphera-net/ui": "^0.0.21", "axios": "^1.13.2", "country-flag-icons": "^1.6.4", "d3-scale": "^4.0.2",