mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-04-19 19:01:19 +00:00
Filter out paid lessons from video and document carousels
This commit is contained in:
parent
cae0396092
commit
9b0def8123
@ -1,10 +1,12 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import { Carousel } from 'primereact/carousel';
|
||||
import { parseEvent } from '@/utils/nostr';
|
||||
import { DocumentTemplate } from '@/components/content/carousels/templates/DocumentTemplate';
|
||||
import TemplateSkeleton from '@/components/content/carousels/skeletons/TemplateSkeleton';
|
||||
import { useDocuments } from '@/hooks/nostr/useDocuments';
|
||||
import useWindowWidth from '@/hooks/useWindowWidth';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { Divider } from 'primereact/divider';
|
||||
const responsiveOptions = [
|
||||
{
|
||||
@ -26,10 +28,26 @@ const responsiveOptions = [
|
||||
|
||||
export default function DocumentsCarousel() {
|
||||
const [processedDocuments, setProcessedDocuments] = useState([]);
|
||||
const [paidLessons, setPaidLessons] = useState([]);
|
||||
const { documents, documentsLoading, documentsError } = useDocuments()
|
||||
const windowWidth = useWindowWidth();
|
||||
const isMobileView = windowWidth <= 450;
|
||||
|
||||
// todo: cache this in react query
|
||||
useEffect(() => {
|
||||
axios.get('/api/lessons').then(res => {
|
||||
if (res.data) {
|
||||
res.data.forEach(lesson => {
|
||||
if (lesson?.resource?.price > 0) {
|
||||
setPaidLessons(prev => [...prev, lesson]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log('err', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetch = async () => {
|
||||
try {
|
||||
@ -39,7 +57,10 @@ export default function DocumentsCarousel() {
|
||||
// Sort documents by created_at in descending order (most recent first)
|
||||
const sortedDocuments = processedDocuments.sort((a, b) => b.created_at - a.created_at);
|
||||
|
||||
setProcessedDocuments(sortedDocuments);
|
||||
// filter out documents that are in the paid lessons array
|
||||
const filteredDocuments = sortedDocuments.filter(document => !paidLessons.includes(document.id));
|
||||
|
||||
setProcessedDocuments(filteredDocuments);
|
||||
} else {
|
||||
console.log('No documents fetched or empty array returned');
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import { Carousel } from 'primereact/carousel';
|
||||
import { parseEvent } from '@/utils/nostr';
|
||||
import {VideoTemplate} from '@/components/content/carousels/templates/VideoTemplate';
|
||||
@ -27,10 +28,25 @@ const responsiveOptions = [
|
||||
|
||||
export default function VideosCarousel() {
|
||||
const [processedVideos, setProcessedVideos] = useState([]);
|
||||
const [paidLessons, setPaidLessons] = useState([]);
|
||||
const { videos, videosLoading, videosError } = useVideos();
|
||||
const windowWidth = useWindowWidth();
|
||||
const isMobileView = windowWidth <= 450;
|
||||
|
||||
useEffect(() => {
|
||||
axios.get('/api/lessons').then(res => {
|
||||
if (res.data) {
|
||||
res.data.forEach(lesson => {
|
||||
if (lesson?.resource?.price > 0) {
|
||||
setPaidLessons(prev => [...prev, lesson]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log('err', err);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetch = async () => {
|
||||
try {
|
||||
@ -39,8 +55,10 @@ export default function VideosCarousel() {
|
||||
|
||||
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
|
||||
|
||||
console.log('Sorted videos:', sortedVideos);
|
||||
setProcessedVideos(sortedVideos);
|
||||
// filter out videos that are in the paid lessons array
|
||||
const filteredVideos = sortedVideos.filter(video => !paidLessons.includes(video.id));
|
||||
|
||||
setProcessedVideos(filteredVideos);
|
||||
} else {
|
||||
console.log('No videos fetched or empty array returned');
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user