fix order
This commit is contained in:
parent
2e3482c00e
commit
f01469c1a5
@ -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 (
|
||||
<Section title="Video Guides" contentClassName={styles.sectionContent}>
|
||||
<Grid columns={columns} className={styles.grid}>
|
||||
{videoGuides.map(videoGuide => (
|
||||
{sortedVideoGuides.map(videoGuide => (
|
||||
<VideoGuideCardWrapper
|
||||
key={`video-guide-${videoGuide.id}`}
|
||||
videoGuide={videoGuide}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user