Add extra logs to debug and add condition to check paud lessons.length

This commit is contained in:
austinkelsay 2024-10-13 17:51:37 -05:00
parent 229cd2ecb3
commit 3ddcf47a72
2 changed files with 7 additions and 5 deletions

View File

@ -51,9 +51,9 @@ export default function DocumentsCarousel() {
useEffect(() => {
const fetch = async () => {
try {
if (documents && documents.length > 0) {
if (documents && documents.length > 0 && paidLessons.length > 0) {
const processedDocuments = documents.map(document => parseEvent(document));
console.log('processedDocuments', processedDocuments);
// Sort documents by created_at in descending order (most recent first)
const sortedDocuments = processedDocuments.sort((a, b) => b.created_at - a.created_at);
@ -69,7 +69,7 @@ export default function DocumentsCarousel() {
}
};
fetch();
}, [documents]);
}, [documents, paidLessons]);
if (documentsError) {
return <div>Error: {documentsError.message}</div>

View File

@ -50,10 +50,12 @@ export default function VideosCarousel() {
useEffect(() => {
const fetch = async () => {
try {
if (videos && videos.length > 0) {
if (videos && videos.length > 0 && paidLessons.length > 0) {
const processedVideos = videos.map(video => parseEvent(video));
console.log('processedVideos', processedVideos);
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
console.log('paidLessons', paidLessons);
// filter out videos that are in the paid lessons array
const filteredVideos = sortedVideos.filter(video => !paidLessons.includes(video?.d));
@ -67,7 +69,7 @@ export default function VideosCarousel() {
}
};
fetch();
}, [videos]);
}, [videos, paidLessons]);
if (videosError) return <div>Error: {videosError}</div>;