mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +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 React, { useState, useEffect } from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
import { Carousel } from 'primereact/carousel';
|
import { Carousel } from 'primereact/carousel';
|
||||||
import { parseEvent } from '@/utils/nostr';
|
import { parseEvent } from '@/utils/nostr';
|
||||||
import { DocumentTemplate } from '@/components/content/carousels/templates/DocumentTemplate';
|
import { DocumentTemplate } from '@/components/content/carousels/templates/DocumentTemplate';
|
||||||
import TemplateSkeleton from '@/components/content/carousels/skeletons/TemplateSkeleton';
|
import TemplateSkeleton from '@/components/content/carousels/skeletons/TemplateSkeleton';
|
||||||
import { useDocuments } from '@/hooks/nostr/useDocuments';
|
import { useDocuments } from '@/hooks/nostr/useDocuments';
|
||||||
import useWindowWidth from '@/hooks/useWindowWidth';
|
import useWindowWidth from '@/hooks/useWindowWidth';
|
||||||
|
import { nip19 } from 'nostr-tools';
|
||||||
import { Divider } from 'primereact/divider';
|
import { Divider } from 'primereact/divider';
|
||||||
const responsiveOptions = [
|
const responsiveOptions = [
|
||||||
{
|
{
|
||||||
@ -26,10 +28,26 @@ const responsiveOptions = [
|
|||||||
|
|
||||||
export default function DocumentsCarousel() {
|
export default function DocumentsCarousel() {
|
||||||
const [processedDocuments, setProcessedDocuments] = useState([]);
|
const [processedDocuments, setProcessedDocuments] = useState([]);
|
||||||
|
const [paidLessons, setPaidLessons] = useState([]);
|
||||||
const { documents, documentsLoading, documentsError } = useDocuments()
|
const { documents, documentsLoading, documentsError } = useDocuments()
|
||||||
const windowWidth = useWindowWidth();
|
const windowWidth = useWindowWidth();
|
||||||
const isMobileView = windowWidth <= 450;
|
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(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
@ -39,7 +57,10 @@ export default function DocumentsCarousel() {
|
|||||||
// Sort documents by created_at in descending order (most recent first)
|
// Sort documents by created_at in descending order (most recent first)
|
||||||
const sortedDocuments = processedDocuments.sort((a, b) => b.created_at - a.created_at);
|
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 {
|
} else {
|
||||||
console.log('No documents fetched or empty array returned');
|
console.log('No documents fetched or empty array returned');
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
import { Carousel } from 'primereact/carousel';
|
import { Carousel } from 'primereact/carousel';
|
||||||
import { parseEvent } from '@/utils/nostr';
|
import { parseEvent } from '@/utils/nostr';
|
||||||
import {VideoTemplate} from '@/components/content/carousels/templates/VideoTemplate';
|
import {VideoTemplate} from '@/components/content/carousels/templates/VideoTemplate';
|
||||||
@ -27,10 +28,25 @@ const responsiveOptions = [
|
|||||||
|
|
||||||
export default function VideosCarousel() {
|
export default function VideosCarousel() {
|
||||||
const [processedVideos, setProcessedVideos] = useState([]);
|
const [processedVideos, setProcessedVideos] = useState([]);
|
||||||
|
const [paidLessons, setPaidLessons] = useState([]);
|
||||||
const { videos, videosLoading, videosError } = useVideos();
|
const { videos, videosLoading, videosError } = useVideos();
|
||||||
const windowWidth = useWindowWidth();
|
const windowWidth = useWindowWidth();
|
||||||
const isMobileView = windowWidth <= 450;
|
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(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
@ -39,8 +55,10 @@ export default function VideosCarousel() {
|
|||||||
|
|
||||||
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
|
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
|
||||||
|
|
||||||
console.log('Sorted videos:', sortedVideos);
|
// filter out videos that are in the paid lessons array
|
||||||
setProcessedVideos(sortedVideos);
|
const filteredVideos = sortedVideos.filter(video => !paidLessons.includes(video.id));
|
||||||
|
|
||||||
|
setProcessedVideos(filteredVideos);
|
||||||
} else {
|
} else {
|
||||||
console.log('No videos fetched or empty array returned');
|
console.log('No videos fetched or empty array returned');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user