mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-12 23:33:43 +08:00
104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
'use client';
|
|
|
|
import { Suspense, useMemo } from 'react';
|
|
import { SearchForm } from '@/components/search/SearchForm';
|
|
import { NoResults } from '@/components/search/NoResults';
|
|
import { PopularFeatures } from '@/components/home/PopularFeatures';
|
|
import { WatchHistorySidebar } from '@/components/history/WatchHistorySidebar';
|
|
import { FavoritesSidebar } from '@/components/favorites/FavoritesSidebar';
|
|
import { Navbar } from '@/components/layout/Navbar';
|
|
import { SearchResults } from '@/components/home/SearchResults';
|
|
import { useHomePage } from '@/lib/hooks/useHomePage';
|
|
import { useLatencyPing } from '@/lib/hooks/useLatencyPing';
|
|
|
|
function HomePage() {
|
|
const {
|
|
query,
|
|
hasSearched,
|
|
loading,
|
|
results,
|
|
availableSources,
|
|
completedSources,
|
|
totalSources,
|
|
handleSearch,
|
|
handleReset,
|
|
} = useHomePage();
|
|
|
|
// Real-time latency pinging
|
|
const sourceUrls = useMemo(() =>
|
|
availableSources.map(s => ({ id: s.id, baseUrl: s.id })), // Using id as baseUrl if not available elsewhere
|
|
[availableSources]
|
|
);
|
|
|
|
const { latencies } = useLatencyPing({
|
|
sourceUrls,
|
|
enabled: hasSearched && results.length > 0,
|
|
});
|
|
|
|
return (
|
|
<div className="min-h-screen">
|
|
{/* Glass Navbar */}
|
|
<Navbar onReset={handleReset} />
|
|
|
|
{/* Search Form - Separate from navbar */}
|
|
<div className="max-w-7xl mx-auto px-4 mt-6 mb-8 relative" style={{
|
|
transform: 'translate3d(0, 0, 0)',
|
|
zIndex: 1000
|
|
}}>
|
|
<SearchForm
|
|
onSearch={handleSearch}
|
|
onClear={handleReset}
|
|
isLoading={loading}
|
|
initialQuery={query}
|
|
currentSource=""
|
|
checkedSources={completedSources}
|
|
totalSources={totalSources}
|
|
/>
|
|
</div>
|
|
|
|
{/* Main Content */}
|
|
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pb-20">
|
|
{/* Results Section */}
|
|
{(results.length >= 1 || (!loading && results.length > 0)) && (
|
|
<SearchResults
|
|
results={results}
|
|
availableSources={availableSources}
|
|
loading={loading}
|
|
latencies={latencies}
|
|
/>
|
|
)}
|
|
|
|
{/* Popular Features - Homepage */}
|
|
{!loading && !hasSearched && (
|
|
<>
|
|
<PopularFeatures onSearch={handleSearch} />
|
|
</>
|
|
)}
|
|
|
|
{/* No Results */}
|
|
{!loading && hasSearched && results.length === 0 && (
|
|
<NoResults onReset={handleReset} />
|
|
)}
|
|
</main>
|
|
|
|
{/* Favorites Sidebar - Left */}
|
|
<FavoritesSidebar />
|
|
|
|
{/* Watch History Sidebar - Right */}
|
|
<WatchHistorySidebar />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default function Home() {
|
|
return (
|
|
<Suspense fallback={
|
|
<div className="min-h-screen flex items-center justify-center">
|
|
<div className="animate-spin rounded-full h-16 w-16 border-4 border-[var(--accent-color)] border-t-transparent"></div>
|
|
</div>
|
|
}>
|
|
<HomePage />
|
|
</Suspense>
|
|
);
|
|
}
|