Files
tset-antiplagiat/frontend/src/pages/Home.tsx
jze9 2a14350ee3
Some checks failed
Deploy / deploy (push) Has been cancelled
test build
2026-05-18 01:14:40 +05:00

54 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState } from 'react'
import DropZone from '../components/DropZone'
import { uploadDocument } from '../api/client'
interface Props {
onTaskCreated: (taskId: string) => void
}
export default function Home({ onTaskCreated }: Props) {
const [file, setFile] = useState<File | null>(null)
const [loading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const handleSubmit = async () => {
if (!file) return
setLoading(true)
setError(null)
try {
const res = await uploadDocument(file)
onTaskCreated(res.task_id)
} catch (e: unknown) {
const msg = (e as { response?: { data?: { detail?: string } } })?.response?.data?.detail ?? 'Ошибка загрузки'
setError(msg)
} finally {
setLoading(false)
}
}
return (
<div className="min-h-screen bg-gray-50 flex flex-col items-center justify-center p-6">
<div className="bg-white rounded-2xl shadow-md p-8 w-full max-w-lg flex flex-col gap-6">
<h1 className="text-2xl font-bold text-gray-800 text-center">Антиплагиат</h1>
<p className="text-sm text-gray-500 text-center">
Загрузите документ для проверки на заимствования
</p>
<DropZone onFile={setFile} disabled={loading} />
{error && (
<p className="text-red-500 text-sm text-center">{error}</p>
)}
<button
onClick={handleSubmit}
disabled={!file || loading}
className="w-full py-3 rounded-xl bg-blue-600 text-white font-semibold hover:bg-blue-700 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
>
{loading ? 'Загрузка…' : 'Проверить'}
</button>
</div>
</div>
)
}