Fix carousel filtering condition for documents and videos

This commit is contained in:
austinkelsay 2024-11-15 11:56:26 -06:00
parent 543ad6ed38
commit 33da6d34f1
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02
2 changed files with 20 additions and 8 deletions

View File

@ -54,15 +54,19 @@ export default function DocumentsCarousel() {
useEffect(() => {
const fetch = async () => {
try {
if (documents && documents.length > 0 && paidLessons.length > 0) {
if (documents && documents.length > 0 && paidLessons) {
const processedDocuments = documents.map(document => parseEvent(document));
// Sort documents by created_at in descending order (most recent first)
const sortedDocuments = processedDocuments.sort((a, b) => b.created_at - a.created_at);
// filter out documents that are in the paid lessons array
const filteredDocuments = sortedDocuments.filter(document => !paidLessons.includes(document?.d));
if (paidLessons && paidLessons.length > 0) {
// filter out documents that are in the paid lessons array
const filteredDocuments = sortedDocuments.filter(document => !paidLessons.includes(document?.d));
setProcessedDocuments(filteredDocuments);
setProcessedDocuments(filteredDocuments);
} else {
setProcessedDocuments(sortedDocuments);
}
} else {
console.log('No documents fetched or empty array returned');
}

View File

@ -34,6 +34,10 @@ export default function VideosCarousel() {
const windowWidth = useWindowWidth();
const isMobileView = windowWidth <= 450;
useEffect(() => {
console.log('videos', videos);
}, [videos]);
useEffect(() => {
axios.get('/api/lessons').then(res => {
if (res.data) {
@ -53,15 +57,19 @@ export default function VideosCarousel() {
useEffect(() => {
const fetch = async () => {
try {
if (videos && videos.length > 0 && paidLessons.length > 0) {
if (videos && videos.length > 0 && paidLessons) {
const processedVideos = videos.map(video => parseEvent(video));
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
// filter out videos that are in the paid lessons array
const filteredVideos = sortedVideos.filter(video => !paidLessons.includes(video?.d));
if (paidLessons && paidLessons.length > 0) {
// filter out videos that are in the paid lessons array
const filteredVideos = sortedVideos.filter(video => !paidLessons.includes(video?.d));
setProcessedVideos(filteredVideos);
setProcessedVideos(filteredVideos);
} else {
setProcessedVideos(sortedVideos);
}
} else {
console.log('No videos fetched or empty array returned');
}