From f01469c1a5dfb7b3e13e4c23abd165b5dbd98b09 Mon Sep 17 00:00:00 2001 From: "dev.daminik00" Date: Thu, 30 Oct 2025 03:34:54 +0100 Subject: [PATCH] fix order --- .../VideoGuidesSection/VideoGuidesSection.tsx | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/components/domains/dashboard/sections/VideoGuidesSection/VideoGuidesSection.tsx b/src/components/domains/dashboard/sections/VideoGuidesSection/VideoGuidesSection.tsx index b747991..adab144 100644 --- a/src/components/domains/dashboard/sections/VideoGuidesSection/VideoGuidesSection.tsx +++ b/src/components/domains/dashboard/sections/VideoGuidesSection/VideoGuidesSection.tsx @@ -1,5 +1,6 @@ "use client"; +import { useMemo } from "react"; import Link from "next/link"; import { Grid, Section } from "@/components/ui"; @@ -59,16 +60,32 @@ function VideoGuideCardWrapper({ videoGuide }: { videoGuide: VideoGuide }) { export default function VideoGuidesSection({ videoGuides, }: VideoGuidesSectionProps) { - if (!videoGuides || videoGuides.length === 0) { + // Сортируем видео: купленные в начало + const sortedVideoGuides = useMemo(() => { + if (!videoGuides || videoGuides.length === 0) { + return []; + } + + return [...videoGuides].sort((a, b) => { + // Купленные видео идут первыми + if (a.isPurchased && !b.isPurchased) return -1; + if (!a.isPurchased && b.isPurchased) return 1; + + // Сохраняем исходный порядок для видео с одинаковым статусом покупки + return 0; + }); + }, [videoGuides]); + + if (sortedVideoGuides.length === 0) { return null; } - const columns = videoGuides.length; + const columns = sortedVideoGuides.length; return (
- {videoGuides.map(videoGuide => ( + {sortedVideoGuides.map(videoGuide => (