mirror of
https://gitlab.com/foxixus/neomovies.git
synced 2025-10-29 18:38: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
105 lines
2.5 KiB
TypeScript
105 lines
2.5 KiB
TypeScript
'use client';
|
|
|
|
import React, { useRef, useState } from 'react';
|
|
import styled from 'styled-components';
|
|
|
|
const Container = styled.div`
|
|
display: flex;
|
|
gap: 0.5rem;
|
|
justify-content: center;
|
|
margin: 1rem 0;
|
|
`;
|
|
|
|
const Input = styled.input`
|
|
width: 3rem;
|
|
height: 3.5rem;
|
|
padding: 0.5rem;
|
|
font-size: 1.5rem;
|
|
text-align: center;
|
|
border-radius: 8px;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
background: rgba(255, 255, 255, 0.05);
|
|
color: #fff;
|
|
transition: all 0.2s;
|
|
|
|
&:focus {
|
|
outline: none;
|
|
border-color: #2196f3;
|
|
background: rgba(255, 255, 255, 0.1);
|
|
box-shadow: 0 0 0 4px rgba(33,150,243,0.1);
|
|
}
|
|
`;
|
|
|
|
interface Props {
|
|
length?: number;
|
|
onChange: (code: string) => void;
|
|
}
|
|
|
|
export function VerificationCodeInput({ length = 6, onChange }: Props) {
|
|
const [code, setCode] = useState<string[]>(Array(length).fill(''));
|
|
const inputs = useRef<(HTMLInputElement | null)[]>([]);
|
|
|
|
const processInput = (e: React.ChangeEvent<HTMLInputElement>, slot: number) => {
|
|
const num = e.target.value;
|
|
if (/[^0-9]/.test(num)) return;
|
|
|
|
const newCode = [...code];
|
|
newCode[slot] = num;
|
|
setCode(newCode);
|
|
|
|
const combinedCode = newCode.join('');
|
|
onChange(combinedCode);
|
|
|
|
if (slot !== length - 1 && num) {
|
|
inputs.current[slot + 1]?.focus();
|
|
}
|
|
};
|
|
|
|
const onKeyUp = (e: React.KeyboardEvent<HTMLInputElement>, slot: number) => {
|
|
if (e.key === 'Backspace' && !code[slot] && slot !== 0) {
|
|
const newCode = [...code];
|
|
newCode[slot - 1] = '';
|
|
setCode(newCode);
|
|
inputs.current[slot - 1]?.focus();
|
|
}
|
|
};
|
|
|
|
const handlePaste = (e: React.ClipboardEvent) => {
|
|
e.preventDefault();
|
|
const paste = e.clipboardData.getData('text');
|
|
const pasteNumbers = paste.match(/[0-9]/g);
|
|
|
|
if (!pasteNumbers) return;
|
|
|
|
const newCode = [...code];
|
|
pasteNumbers.forEach((num, i) => {
|
|
if (i >= length) return;
|
|
newCode[i] = num;
|
|
inputs.current[i]?.value = num;
|
|
});
|
|
|
|
setCode(newCode);
|
|
onChange(newCode.join(''));
|
|
inputs.current[Math.min(pasteNumbers.length, length - 1)]?.focus();
|
|
};
|
|
|
|
return (
|
|
<Container>
|
|
{code.map((num, idx) => (
|
|
<Input
|
|
key={idx}
|
|
type="text"
|
|
inputMode="numeric"
|
|
maxLength={1}
|
|
value={num}
|
|
autoFocus={!code[0].length && idx === 0}
|
|
onChange={(e) => processInput(e, idx)}
|
|
onKeyUp={(e) => onKeyUp(e, idx)}
|
|
onPaste={handlePaste}
|
|
ref={(ref) => inputs.current[idx] = ref}
|
|
/>
|
|
))}
|
|
</Container>
|
|
);
|
|
}
|