fix order

This commit is contained in:
dev.daminik00 2025-10-30 03:34:54 +01:00
parent 2e3482c00e
commit f01469c1a5

View File

@ -1,5 +1,6 @@
"use client"; "use client";
import { useMemo } from "react";
import Link from "next/link"; import Link from "next/link";
import { Grid, Section } from "@/components/ui"; import { Grid, Section } from "@/components/ui";
@ -59,16 +60,32 @@ function VideoGuideCardWrapper({ videoGuide }: { videoGuide: VideoGuide }) {
export default function VideoGuidesSection({ export default function VideoGuidesSection({
videoGuides, videoGuides,
}: VideoGuidesSectionProps) { }: 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; return null;
} }
const columns = videoGuides.length; const columns = sortedVideoGuides.length;
return ( return (
<Section title="Video Guides" contentClassName={styles.sectionContent}> <Section title="Video Guides" contentClassName={styles.sectionContent}>
<Grid columns={columns} className={styles.grid}> <Grid columns={columns} className={styles.grid}>
{videoGuides.map(videoGuide => ( {sortedVideoGuides.map(videoGuide => (
<VideoGuideCardWrapper <VideoGuideCardWrapper
key={`video-guide-${videoGuide.id}`} key={`video-guide-${videoGuide.id}`}
videoGuide={videoGuide} videoGuide={videoGuide}