import React, { useState, useMemo } from "react"; import Image from "next/image"; import…
- User
import React, { useState, useMemo } from "react"; import Image from "next/image"; import Link from "next/link"; import { motion } from "framer-motion";
const categories = [ { name: "Все", value: "Все" }, { name: "Установка ПО", value: "Установка ПО" }, { name: "Оборудование", value: "Оборудование" }, { name: "Советы", value: "Советы" }, { name: "Общее", value: "Общее" }, { name: "Ошибки", value: "Ошибки" }, ];
const blogPosts = [ { title: "Как справиться с ошибкой при открытии архива", image: "/images/blog/post1.jpg", excerpt: "Узнайте, как справиться с наиболее частыми ошибками при открытии архивов.", link: "/articles/errors/archive", category: "Ошибки", keywords: ["ошибки архива", "проблемы с архивом", "ошибка открытия архива", "архив"], }, { title: "Инструкция по установке Autocom 2021", image: "/images/blog/post1.jpg", excerpt: "Полноценная, подробная инструкция по установке программного обеспечения.", link: "/articles/software/autocom2021", category: "Установка ПО", keywords: ["установка ПО", "Autocom 2021", "инструкция"], }, { title: "тест", image: "/images/blog/post1.jpg", excerpt: "тест.", link: "/articles/software/autocom2021", category: "Установка ПО", keywords: ["установка ПО", "Autocom 2021", "инструкция"], }, { title: "Инструкdция по установке Autocom 2021 Инструкdция по установке Autocom 2021 Инструкdция по установке Autocom 2021", image: "/images/blog/post1.jpg", excerpt: "Инструкdция по установке Autocom 2021 Инструкdция по установке Autocom 2021 Инструкdция по установке Autocom 2021", link: "/articles/software/autocom2021", category: "Установка ПО", keywords: ["установка ПО", "Autocom 2021", "инструкция"], }, ];
export default function Blog() { const [selectedCategory, setSelectedCategory] = useState("Все"); const [searchTerm, setSearchTerm] = useState(""); const [currentPage, setCurrentPage] = useState(1);
const postsPerPage = 8;
const filteredPosts = useMemo(() => { const filteredByCategory = selectedCategory === "Все" ? blogPosts : blogPosts.filter((post) => post.category === selectedCategory); return filteredByCategory.filter( (post) => post.title.toLowerCase().includes(searchTerm.toLowerCase()) || post.excerpt.toLowerCase().includes(searchTerm.toLowerCase()) ); }, [selectedCategory, searchTerm]);
const paginatedPosts = useMemo(() => { const startIndex = (currentPage - 1) * postsPerPage; return filteredPosts.slice(startIndex, startIndex + postsPerPage); }, [currentPage, filteredPosts]);
const totalPages = Math.ceil(filteredPosts.length / postsPerPage);
const handlePageChange = (page: number) => { setCurrentPage(page); };
return ( {/* Заголовок */} <motion.h2 className="text-4xl font-extrabold text-center text-black dark:text-white" initial={{ opacity: 0, y: -20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.6 }} > Статьи 💻 </motion.h2> <motion.p className="pt-6 text-lg max-w-2xl text-center m-auto text-gray-700 dark:text-gray-300" initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ delay: 0.3, duration: 0.6 }} > В этом разделе вы можете найти статьи и решения по программному обеспечению. </motion.p>
- Assistant
This React component,
Blog, is built with Next.js and utilizes several third-party libraries such asframer-motionfor animations andImageandLinkcomponents fromnext/imageand respectively. Here’s a breakdown of the component's structure and functionality: