2026-03-16 17:12:52 +07:00
|
|
|
// app/ui/violations/file-page/violation-page-violations-list.tsx
|
|
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import { useTranslations } from 'next-intl';
|
2026-03-17 12:17:26 +07:00
|
|
|
import Link from 'next/link';
|
2026-03-16 17:12:52 +07:00
|
|
|
import { useRouter, usePathname } from 'next/navigation';
|
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
|
|
|
|
|
interface ViolationFileDetail {
|
|
|
|
|
id: number;
|
|
|
|
|
url: string;
|
|
|
|
|
page_url: string;
|
|
|
|
|
page_title: string;
|
|
|
|
|
host: string;
|
|
|
|
|
status: string;
|
|
|
|
|
created_date: string;
|
|
|
|
|
file_id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ViolationFile {
|
|
|
|
|
violations: ViolationFileDetail[],
|
|
|
|
|
total_elements: number,
|
|
|
|
|
total_pages: number,
|
|
|
|
|
current_page: number,
|
|
|
|
|
page_size: number,
|
|
|
|
|
has_next: boolean,
|
|
|
|
|
has_previous: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function ViolationPageViolationsList({
|
|
|
|
|
fileViolations,
|
|
|
|
|
currentPage,
|
|
|
|
|
fileId
|
|
|
|
|
}: {
|
|
|
|
|
fileViolations: ViolationFile,
|
|
|
|
|
currentPage: number,
|
|
|
|
|
fileId: string
|
|
|
|
|
}) {
|
|
|
|
|
const t = useTranslations('Global');
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const pathname = usePathname();
|
|
|
|
|
|
|
|
|
|
if (!fileViolations?.violations) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 12:17:26 +07:00
|
|
|
useEffect(() => {
|
|
|
|
|
console.log(fileViolations);
|
|
|
|
|
}, [fileViolations]);
|
|
|
|
|
|
2026-03-16 17:12:52 +07:00
|
|
|
const handlePageChange = (page: number) => {
|
|
|
|
|
router.push(`${pathname}?page=${page}`);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getPageNumbers = () => {
|
|
|
|
|
const pages = [];
|
|
|
|
|
const maxVisible = 5;
|
|
|
|
|
const total = fileViolations.total_pages;
|
|
|
|
|
|
|
|
|
|
let start = Math.max(1, currentPage - Math.floor(maxVisible / 2));
|
|
|
|
|
let end = Math.min(total, start + maxVisible - 1);
|
|
|
|
|
|
|
|
|
|
if (end - start + 1 < maxVisible) {
|
|
|
|
|
start = Math.max(1, end - maxVisible + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let i = start; i <= end; i++) {
|
|
|
|
|
pages.push(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pages;
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-02 18:57:52 +07:00
|
|
|
return (
|
2026-03-16 17:12:52 +07:00
|
|
|
<div className="block-wrapper">
|
2026-03-02 18:57:52 +07:00
|
|
|
<div className="card-header">
|
|
|
|
|
<h3 className="card-title">
|
|
|
|
|
Все нарушения этого файла
|
|
|
|
|
</h3>
|
|
|
|
|
<span>
|
2026-03-16 17:12:52 +07:00
|
|
|
Всего: {fileViolations.total_elements} | Страница {fileViolations.current_page} из {fileViolations.total_pages}
|
2026-03-02 18:57:52 +07:00
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-16 17:12:52 +07:00
|
|
|
<div className="sources-list">
|
|
|
|
|
{fileViolations.violations.map(item => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="source-card" key={item.id}>
|
|
|
|
|
<div className="source-image">
|
|
|
|
|
<img src={item.url} alt="" />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="source-header">
|
|
|
|
|
<a href={item.page_url} target="_blank" className="source-url">
|
|
|
|
|
<span>{item.page_title}</span>
|
|
|
|
|
</a>
|
|
|
|
|
<span className="source-status new">
|
|
|
|
|
{item.status}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="source-meta">
|
|
|
|
|
<span>{item.host}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="source-actions">
|
2026-03-17 12:17:26 +07:00
|
|
|
<Link
|
2026-03-16 17:12:52 +07:00
|
|
|
href={item.page_url}
|
|
|
|
|
className="btn-small btn-primary-small"
|
|
|
|
|
target="_blank"
|
2026-03-17 12:17:26 +07:00
|
|
|
scroll={false}
|
2026-03-16 17:12:52 +07:00
|
|
|
>
|
|
|
|
|
{t('open')}
|
2026-03-17 12:17:26 +07:00
|
|
|
</Link>
|
2026-03-16 17:12:52 +07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2026-03-02 18:57:52 +07:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-16 17:12:52 +07:00
|
|
|
{fileViolations.total_pages > 1 && (
|
|
|
|
|
<div className="pagination">
|
|
|
|
|
{fileViolations.has_previous && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => handlePageChange(currentPage - 1)}
|
|
|
|
|
className="pagination__item pagination__item--prev"
|
|
|
|
|
>
|
|
|
|
|
Предыдущая
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{getPageNumbers().map(pageNum => (
|
|
|
|
|
<button
|
|
|
|
|
key={pageNum}
|
|
|
|
|
onClick={() => handlePageChange(pageNum)}
|
|
|
|
|
className={`pagination__item ${currentPage === pageNum ? 'pagination__item--active' : ''}`}
|
|
|
|
|
>
|
|
|
|
|
{pageNum}
|
|
|
|
|
</button>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
{fileViolations.has_next && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => handlePageChange(currentPage + 1)}
|
|
|
|
|
className="pagination__item pagination__item--next"
|
|
|
|
|
>
|
|
|
|
|
Следующая
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-02 18:57:52 +07:00
|
|
|
</div>
|
2026-03-16 17:12:52 +07:00
|
|
|
);
|
2026-03-02 18:57:52 +07:00
|
|
|
}
|