mirror of
https://gitlab.com/foxixus/neomovies.git
synced 2025-10-28 01:48:50 +05:00
- /public/file.svg - /public/globe.svg - /public/next.svg - /public/vercel.svg - /public/window.svg - /public/google.svg - /public/logo.png - /src/eslint.config.mjs - /src/api.ts - /src/middleware.ts - /src/app/favicon.ico - /src/app/globals.css - /src/app/layout.tsx - /src/app/page.tsx - /src/app/providers.tsx - /src/app/not-found.tsx - /src/app/error.tsx - /src/app/metadata.ts - /src/app/styles.tsx - /src/app/api/auth/[...nextauth]/route.ts - /src/app/api/auth/register/route.ts - /src/app/api/auth/verify/route.ts - /src/app/api/auth/check-verification/route.ts - /src/app/api/auth/resend-code/route.ts - /src/app/api/movies/search/route.ts - /src/app/api/movies/sync/route.ts - /src/app/api/admin/send-verification/route.ts - /src/app/api/admin/verify-code/route.ts - /src/app/api/admin/movies/route.ts - /src/app/api/admin/movies/toggle-visibility/route.ts - /src/app/api/admin/create/route.ts - /src/app/api/admin/users/toggle-admin/route.ts - /src/app/api/admin/toggle-admin/route.ts - /src/app/login/page.tsx - /src/app/login/LoginClient.tsx - /src/app/verify/page.tsx - /src/app/verify/VerificationClient.tsx - /src/app/profile/page.tsx - /src/app/movie/[id]/page.tsx - /src/app/movie/[id]/MoviePage.tsx - /src/app/movie/[id]/MovieContent.tsx - /src/app/settings/page.tsx - /src/app/tv/[id]/page.tsx - /src/app/tv/[id]/TVShowPage.tsx - /src/app/tv/[id]/TVShowContent.tsx - /src/app/admin/login/page.tsx - /src/app/admin/login/AdminLoginClient.tsx - /src/lib/db.ts - /src/lib/jwt.ts - /src/lib/registry.tsx - /src/lib/api.ts - /src/lib/mongodb.ts - /src/lib/mailer.ts - /src/lib/auth.ts - /src/lib/utils.ts - /src/lib/email.ts - /src/lib/movieSync.ts - /src/models/User.ts - /src/models/index.ts - /src/models/Movie.ts - /src/types/auth.ts - /src/types/movie.ts - /src/components/MovieCard.tsx - /src/components/Notification.tsx - /src/components/Pagination.tsx - /src/components/GoogleIcon.tsx - /src/components/StyleProvider.tsx - /src/components/Providers.tsx - /src/components/VerificationCodeInput.tsx - /src/components/GlassCard.tsx - /src/components/AppLayout.tsx - /src/components/SearchModal.tsx - /src/components/DarkReaderFix.tsx - /src/components/ClientLayout.tsx - /src/components/MenuItem.tsx - /src/components/MoviePlayer.tsx - /src/components/PageLayout.tsx - /src/components/SettingsContent.tsx - /src/components/Navbar.tsx - /src/components/LayoutContent.tsx - /src/components/SearchResults.tsx - /src/components/Icons/Icons.tsx - /src/components/Icons/HeartIcon.tsx - /src/components/Icons/PlayIcon.tsx - /src/components/admin/MovieSearch.tsx - /src/hooks/useUser.ts - /src/hooks/useMovies.ts - /src/hooks/useSettings.ts - /src/hooks/useSearch.ts - /src/styles/GlobalStyles.ts - /src/styles/GlobalStyles.tsx - /src/providers/AuthProvider.tsx - /src/data/movies.ts - /types/next-auth.d.ts - /middleware.ts - /next.config.js - /next-env.d.ts - /package.json - /postcss.config.mjs - /README.md - /tailwind.config.ts - /tsconfig.json - /package-lock.json
178 lines
4.4 KiB
TypeScript
178 lines
4.4 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useRef, useState } from 'react';
|
|
import styled from 'styled-components';
|
|
import { useRouter } from 'next/navigation';
|
|
import { Movie, TVShow } from '@/lib/api';
|
|
import SearchResults from './SearchResults';
|
|
|
|
const Overlay = styled.div<{ $isOpen: boolean }>`
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: rgba(0, 0, 0, 0.7);
|
|
display: ${props => props.$isOpen ? 'flex' : 'none'};
|
|
justify-content: center;
|
|
align-items: flex-start;
|
|
padding-top: 100px;
|
|
z-index: 1000;
|
|
backdrop-filter: blur(5px);
|
|
`;
|
|
|
|
const Modal = styled.div`
|
|
width: 100%;
|
|
max-width: 600px;
|
|
background: rgba(30, 30, 30, 0.95);
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
|
|
position: relative;
|
|
`;
|
|
|
|
const SearchHeader = styled.div`
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 1rem;
|
|
gap: 1rem;
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
`;
|
|
|
|
const SearchInput = styled.input`
|
|
flex: 1;
|
|
background: none;
|
|
border: none;
|
|
color: white;
|
|
font-size: 1rem;
|
|
outline: none;
|
|
|
|
&::placeholder {
|
|
color: rgba(255, 255, 255, 0.5);
|
|
}
|
|
`;
|
|
|
|
const CloseButton = styled.button`
|
|
background: none;
|
|
border: none;
|
|
color: rgba(255, 255, 255, 0.6);
|
|
cursor: pointer;
|
|
padding: 0.5rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: color 0.2s;
|
|
|
|
&:hover {
|
|
color: white;
|
|
}
|
|
`;
|
|
|
|
const SearchIcon = styled.div`
|
|
color: rgba(255, 255, 255, 0.6);
|
|
display: flex;
|
|
align-items: center;
|
|
`;
|
|
|
|
const LoadingSpinner = styled.div`
|
|
display: inline-block;
|
|
width: 1rem;
|
|
height: 1rem;
|
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
border-radius: 50%;
|
|
border-top-color: white;
|
|
animation: spin 1s linear infinite;
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
`;
|
|
|
|
interface SearchModalProps {
|
|
onClose: () => void;
|
|
}
|
|
|
|
export default function SearchModal({ onClose }: SearchModalProps) {
|
|
const [query, setQuery] = useState('');
|
|
const [results, setResults] = useState<(Movie | TVShow)[]>([]);
|
|
const [loading, setLoading] = useState(false);
|
|
const modalRef = useRef<HTMLDivElement>(null);
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
const handleClickOutside = (event: MouseEvent) => {
|
|
if (modalRef.current && !modalRef.current.contains(event.target as Node)) {
|
|
onClose();
|
|
}
|
|
};
|
|
|
|
document.addEventListener('mousedown', handleClickOutside);
|
|
inputRef.current?.focus();
|
|
|
|
return () => {
|
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
};
|
|
}, [onClose]);
|
|
|
|
useEffect(() => {
|
|
const searchTimeout = setTimeout(async () => {
|
|
if (query.length < 2) {
|
|
setResults([]);
|
|
return;
|
|
}
|
|
|
|
setLoading(true);
|
|
try {
|
|
const response = await fetch(`/api/movies/search?query=${encodeURIComponent(query)}`);
|
|
const data = await response.json();
|
|
setResults(data.results || []);
|
|
} catch (error) {
|
|
console.error('Error searching:', error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, 300);
|
|
|
|
return () => clearTimeout(searchTimeout);
|
|
}, [query]);
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
if (e.key === 'Escape') {
|
|
onClose();
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Overlay $isOpen={true} onKeyDown={handleKeyDown}>
|
|
<Modal ref={modalRef}>
|
|
<SearchHeader>
|
|
<SearchIcon>
|
|
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
|
|
</svg>
|
|
</SearchIcon>
|
|
<SearchInput
|
|
ref={inputRef}
|
|
type="text"
|
|
placeholder="Поиск фильмов и сериалов..."
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
/>
|
|
{loading ? (
|
|
<LoadingSpinner />
|
|
) : (
|
|
<CloseButton onClick={onClose}>
|
|
<svg width="20" height="20" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
|
|
</svg>
|
|
</CloseButton>
|
|
)}
|
|
</SearchHeader>
|
|
{results.length > 0 && <SearchResults results={results} onItemClick={onClose} />}
|
|
</Modal>
|
|
</Overlay>
|
|
);
|
|
}
|