diff --git a/src/app/page.tsx b/src/app/page.tsx index fb0924b..5348ee2 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -3,7 +3,7 @@ import Stocks from '@/components/App/index/Stocks' export default function Home() { return ( <> - + ) } diff --git a/src/components/App/index/Stocks.tsx b/src/components/App/index/Stocks.tsx index 2464d79..65907f1 100644 --- a/src/components/App/index/Stocks.tsx +++ b/src/components/App/index/Stocks.tsx @@ -1,6 +1,6 @@ import {unstable_noStore as noStore} from 'next/cache' +import {client, urlForImage} from '@/lib/sanity' -import {client} from '@/lib/sanity' import StocksSlider from '#/App/index/StocksSlider' const getData = async () => { @@ -8,27 +8,29 @@ const getData = async () => { const query = ` *[_type == 'stocks'] { - images + title, + caption, + image }` const data = await client.fetch(query) return data } -interface StocksProps { - classes: string -} - -const Stocks: React.FC = async ({classes}) => { +const Stocks = async ({classes}) => { const stocks = await getData() if (!stocks) { return Произошла ошибка при получении данных! } - const images = stocks.map((stock) => stock.images).flat() + const sliderData = stocks.map((stock) => ({ + imageUrl: urlForImage(stock.image.asset._ref).url(), + title: stock.title, + caption: stock.caption, + })) - return + return } export default Stocks diff --git a/src/components/App/index/StocksSlider.tsx b/src/components/App/index/StocksSlider.tsx index 22b8fc1..4a37e8a 100644 --- a/src/components/App/index/StocksSlider.tsx +++ b/src/components/App/index/StocksSlider.tsx @@ -1,7 +1,5 @@ 'use client' -import {urlForImage} from '@/lib/sanity' - import Image from 'next/image' import {Swiper, SwiperSlide} from 'swiper/react' import {Pagination, Autoplay} from 'swiper/modules' @@ -11,16 +9,27 @@ import 'swiper/css/pagination' import '@/assets/stylesheets/stocks_slider.css' interface SliderProps { - images: string[] + sliderData: { + imageUrl: string + title: string + caption: string + }[] classes: string } -const Slider: React.FC = ({images, classes}) => { +const Slider: React.FC = ({sliderData, classes}) => { return ( - - {images.map((image, index) => ( + + {sliderData.map((slide, index) => ( - {`slide-${index + {`акция + +
+
+

{slide.title}

+

{slide.caption}

+
+
))}