Удалены устаревшие файлы документации и отчетов, включая ADMIN_DESIGN_IMPROVEMENTS.md, DATABASE_SETUP.md, FIX_REPORT.md, IMPLEMENTATION_SUMMARY.md, S3_SETUP.md, S3_TROUBLESHOOTING.md. Обновлен docker-compose.yml для упрощения проверки состояния контейнера. Исправлены ошибки в компонентах админ-панели, включая улучшение логики авторизации и загрузки категорий новостей.
This commit is contained in:
@ -4,7 +4,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { useSearchParams, useRouter, usePathname } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import Image from 'next/image';
|
||||
import { NEWS_CATEGORIES, NewsItem } from '@/lib/types';
|
||||
import { NewsItem } from '@/lib/types';
|
||||
import { Search, Eye, ArrowRight } from 'lucide-react';
|
||||
import Header from '@/app/components/Header';
|
||||
import Footer from '@/app/components/Footer';
|
||||
@ -60,8 +60,18 @@ export default function NewsPageComponent() {
|
||||
const [news, setNews] = useState<NewsItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [totalNews, setTotalNews] = useState(0);
|
||||
const [categories, setCategories] = useState<{ id: string; name: string; color: string }[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/categories', { cache: 'no-store' });
|
||||
const data = await res.json();
|
||||
if (res.ok && data?.data?.length) {
|
||||
setCategories(data.data.map((c: any) => ({ id: c.slug, name: c.name, color: c.color || 'bg-gray-500' })));
|
||||
}
|
||||
} catch {}
|
||||
})();
|
||||
const loadNews = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
@ -126,9 +136,7 @@ export default function NewsPageComponent() {
|
||||
});
|
||||
};
|
||||
|
||||
const getCategoryInfo = (categoryId: string) => {
|
||||
return NEWS_CATEGORIES.find(cat => cat.id === categoryId);
|
||||
};
|
||||
const getCategoryInfo = (categoryId: string) => categories.find(cat => cat.id === categoryId);
|
||||
|
||||
const handleCategoryChange = (category: string) => {
|
||||
setSelectedCategory(category);
|
||||
@ -237,7 +245,7 @@ export default function NewsPageComponent() {
|
||||
>
|
||||
Все
|
||||
</button>
|
||||
{NEWS_CATEGORIES.map((category) => (
|
||||
{categories.map((category) => (
|
||||
<button
|
||||
key={category.id}
|
||||
onClick={() => handleCategoryChange(category.id)}
|
||||
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||
import { notFound } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import Image from 'next/image';
|
||||
import { NEWS_CATEGORIES } from '@/lib/types';
|
||||
// категории будем подтягивать с API
|
||||
|
||||
interface NewsDetailPageProps {
|
||||
params: Promise<{
|
||||
@ -72,11 +72,18 @@ export default async function NewsDetailPage({ params }: NewsDetailPageProps) {
|
||||
});
|
||||
};
|
||||
|
||||
const getCategoryInfo = (categoryId: string) => {
|
||||
return NEWS_CATEGORIES.find(cat => cat.id === categoryId);
|
||||
};
|
||||
async function getCategoryInfo(categoryId: string) {
|
||||
try {
|
||||
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000'}/api/categories`, { cache: 'no-store' });
|
||||
const data = await response.json();
|
||||
if (response.ok && data?.data?.length) {
|
||||
return data.data.find((c: any) => c.slug === categoryId);
|
||||
}
|
||||
} catch {}
|
||||
return null;
|
||||
}
|
||||
|
||||
const categoryInfo = getCategoryInfo(news.category);
|
||||
const categoryInfo = await getCategoryInfo(news.category);
|
||||
|
||||
// Получаем связанные новости (из той же категории, исключая текущую)
|
||||
const relatedNews = await getRelatedNews(news.category, news.slug);
|
||||
|
Reference in New Issue
Block a user