dynamic news
This commit is contained in:
@@ -7,10 +7,12 @@ import { data } from '@/app/staticData'
|
||||
import { routes } from '@/app/staticData'
|
||||
import Button from '@/components/ui/Button'
|
||||
import News from '@/components/News'
|
||||
import { getFAQs } from '@/lib/fetchFAQ'
|
||||
import { getFAQs } from '@/lib/main/fetchFAQ'
|
||||
import { getNews } from '@/lib/main/fetchNews'
|
||||
|
||||
export default async function Home() {
|
||||
const faqs = await getFAQs()
|
||||
const news = await getNews()
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center max-w-[93%] mx-auto">
|
||||
@@ -239,7 +241,7 @@ export default async function Home() {
|
||||
<FAQ faqs={faqs} />
|
||||
|
||||
{/* новости */}
|
||||
<News />
|
||||
<News news={news} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -54,3 +54,15 @@ export interface FAQ {
|
||||
export interface FAQProps {
|
||||
faqs: FAQ[]
|
||||
}
|
||||
|
||||
export interface NewsItem {
|
||||
id: number
|
||||
title: string
|
||||
content: string
|
||||
image: string
|
||||
slug: string
|
||||
}
|
||||
|
||||
export interface NewsProps {
|
||||
news: NewsItem[]
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
import React from 'react'
|
||||
import Image from 'next/image'
|
||||
import Link from 'next/link'
|
||||
import { news } from '@/app/staticData'
|
||||
import ShowMore from './ui/ShowMore'
|
||||
import { NewsProps } from '@/app/types'
|
||||
|
||||
interface NewsItem {
|
||||
id: number
|
||||
title: string
|
||||
description: string
|
||||
image: string
|
||||
slug: string
|
||||
}
|
||||
|
||||
export default function News() {
|
||||
const News: React.FC<NewsProps> = ({ news }) => {
|
||||
if (!news || news.length === 0) {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<div className="w-full max-w-[1250px] mx-auto px-4 sm:px-6 mb-20">
|
||||
<h2 className="text-3xl sm:text-4xl text-center font-bold mb-10">
|
||||
@@ -33,7 +28,7 @@ export default function News() {
|
||||
</div>
|
||||
<div className="pt-6">
|
||||
<h3 className="text-base font-semibold mb-3">{item.title}</h3>
|
||||
<ShowMore text={item.description} />
|
||||
<ShowMore text={item.content} />
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
@@ -42,3 +37,5 @@ export default function News() {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default News
|
||||
|
||||
18
frontend/lib/main/fetchNews.ts
Normal file
18
frontend/lib/main/fetchNews.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { NewsItem, NewsProps } from '@/app/types'
|
||||
|
||||
export async function getNews(): Promise<NewsItem[]> {
|
||||
const API_URL = process.env.NEXT_PUBLIC_API_URL
|
||||
|
||||
const response = await fetch(`${API_URL}/news/`, {
|
||||
next: {
|
||||
revalidate: 259200, // три дня
|
||||
},
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch FAQs')
|
||||
}
|
||||
|
||||
const data: NewsProps = await response.json()
|
||||
return data.news
|
||||
}
|
||||
Reference in New Issue
Block a user