mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
Fix carousel filtering condition for documents and videos
This commit is contained in:
parent
543ad6ed38
commit
33da6d34f1
@ -54,15 +54,19 @@ export default function DocumentsCarousel() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
if (documents && documents.length > 0 && paidLessons.length > 0) {
|
if (documents && documents.length > 0 && paidLessons) {
|
||||||
const processedDocuments = documents.map(document => parseEvent(document));
|
const processedDocuments = documents.map(document => parseEvent(document));
|
||||||
// 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);
|
||||||
|
|
||||||
// filter out documents that are in the paid lessons array
|
if (paidLessons && paidLessons.length > 0) {
|
||||||
const filteredDocuments = sortedDocuments.filter(document => !paidLessons.includes(document?.d));
|
// 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 {
|
} else {
|
||||||
console.log('No documents fetched or empty array returned');
|
console.log('No documents fetched or empty array returned');
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,10 @@ export default function VideosCarousel() {
|
|||||||
const windowWidth = useWindowWidth();
|
const windowWidth = useWindowWidth();
|
||||||
const isMobileView = windowWidth <= 450;
|
const isMobileView = windowWidth <= 450;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log('videos', videos);
|
||||||
|
}, [videos]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get('/api/lessons').then(res => {
|
axios.get('/api/lessons').then(res => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
@ -53,15 +57,19 @@ export default function VideosCarousel() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
if (videos && videos.length > 0 && paidLessons.length > 0) {
|
if (videos && videos.length > 0 && paidLessons) {
|
||||||
const processedVideos = videos.map(video => parseEvent(video));
|
const processedVideos = videos.map(video => parseEvent(video));
|
||||||
|
|
||||||
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
|
const sortedVideos = processedVideos.sort((a, b) => b.created_at - a.created_at);
|
||||||
|
|
||||||
// filter out videos that are in the paid lessons array
|
if (paidLessons && paidLessons.length > 0) {
|
||||||
const filteredVideos = sortedVideos.filter(video => !paidLessons.includes(video?.d));
|
// 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 {
|
} 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