mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-05-10 16:26:11 +00:00
Revert zap ordering
This commit is contained in:
parent
b4534a23c4
commit
94474cddf1
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect, use } from 'react';
|
||||||
import { Carousel } from 'primereact/carousel';
|
import { Carousel } from 'primereact/carousel';
|
||||||
import { parseCourseEvent } from '@/utils/nostr';
|
import { parseCourseEvent } from '@/utils/nostr';
|
||||||
import { CourseTemplate } from '@/components/content/carousels/templates/CourseTemplate';
|
import { CourseTemplate } from '@/components/content/carousels/templates/CourseTemplate';
|
||||||
@ -26,21 +26,20 @@ const responsiveOptions = [
|
|||||||
|
|
||||||
export default function CoursesCarousel() {
|
export default function CoursesCarousel() {
|
||||||
const [processedCourses, setProcessedCourses] = useState([]);
|
const [processedCourses, setProcessedCourses] = useState([]);
|
||||||
const [zapAmounts, setZapAmounts] = useState({});
|
|
||||||
const { courses, coursesLoading, coursesError } = useCourses()
|
const { courses, coursesLoading, coursesError } = useCourses()
|
||||||
const windowWidth = useWindowWidth();
|
const windowWidth = useWindowWidth();
|
||||||
const isMobileView = windowWidth <= 450;
|
const isMobileView = windowWidth <= 450;
|
||||||
|
|
||||||
const handleZapAmountChange = useCallback((courseId, amount) => {
|
|
||||||
setZapAmounts(prev => ({ ...prev, [courseId]: amount }));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetch = async () => {
|
const fetch = async () => {
|
||||||
try {
|
try {
|
||||||
if (courses && courses.length > 0) {
|
if (courses && courses.length > 0) {
|
||||||
const processedCourses = courses.map(course => parseCourseEvent(course));
|
const processedCourses = courses.map(course => parseCourseEvent(course));
|
||||||
setProcessedCourses(processedCourses);
|
|
||||||
|
// Sort courses by created_at in descending order (most recent first)
|
||||||
|
const sortedCourses = processedCourses.sort((a, b) => b.created_at - a.created_at);
|
||||||
|
|
||||||
|
setProcessedCourses(sortedCourses);
|
||||||
} else {
|
} else {
|
||||||
console.log('No courses fetched or empty array returned');
|
console.log('No courses fetched or empty array returned');
|
||||||
}
|
}
|
||||||
@ -51,15 +50,6 @@ export default function CoursesCarousel() {
|
|||||||
fetch();
|
fetch();
|
||||||
}, [courses]);
|
}, [courses]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (Object.keys(zapAmounts).length === processedCourses.length) {
|
|
||||||
const sortedCourses = [...processedCourses].sort((a, b) =>
|
|
||||||
(zapAmounts[b.id] || 0) - (zapAmounts[a.id] || 0)
|
|
||||||
);
|
|
||||||
setProcessedCourses(sortedCourses);
|
|
||||||
}
|
|
||||||
}, [zapAmounts, processedCourses]);
|
|
||||||
|
|
||||||
if (coursesError) {
|
if (coursesError) {
|
||||||
return <div>Error: {coursesError.message}</div>
|
return <div>Error: {coursesError.message}</div>
|
||||||
}
|
}
|
||||||
@ -83,7 +73,7 @@ export default function CoursesCarousel() {
|
|||||||
itemTemplate={(item) =>
|
itemTemplate={(item) =>
|
||||||
!processedCourses.length ?
|
!processedCourses.length ?
|
||||||
<TemplateSkeleton key={Math.random()} /> :
|
<TemplateSkeleton key={Math.random()} /> :
|
||||||
<CourseTemplate key={item.id} course={item} onZapAmountChange={handleZapAmountChange} />
|
<CourseTemplate key={item.id} course={item} />
|
||||||
}
|
}
|
||||||
responsiveOptions={responsiveOptions} />
|
responsiveOptions={responsiveOptions} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Carousel } from 'primereact/carousel';
|
import { Carousel } from 'primereact/carousel';
|
||||||
import { parseEvent } from '@/utils/nostr';
|
import { parseEvent } from '@/utils/nostr';
|
||||||
@ -30,15 +30,10 @@ export default function DocumentsCarousel() {
|
|||||||
const [processedDocuments, setProcessedDocuments] = useState([]);
|
const [processedDocuments, setProcessedDocuments] = useState([]);
|
||||||
const [paidLessons, setPaidLessons] = useState([]);
|
const [paidLessons, setPaidLessons] = useState([]);
|
||||||
const [freeLessons, setFreeLessons] = useState([]);
|
const [freeLessons, setFreeLessons] = useState([]);
|
||||||
const [zapAmounts, setZapAmounts] = 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;
|
||||||
|
|
||||||
const handleZapAmountChange = useCallback((documentId, amount) => {
|
|
||||||
setZapAmounts(prev => ({ ...prev, [documentId]: amount }));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// todo: cache this in react query
|
// todo: cache this in react query
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get('/api/lessons').then(res => {
|
axios.get('/api/lessons').then(res => {
|
||||||
@ -61,8 +56,12 @@ export default function DocumentsCarousel() {
|
|||||||
try {
|
try {
|
||||||
if (documents && documents.length > 0 && paidLessons.length > 0) {
|
if (documents && documents.length > 0 && paidLessons.length > 0) {
|
||||||
const processedDocuments = documents.map(document => parseEvent(document));
|
const processedDocuments = documents.map(document => parseEvent(document));
|
||||||
// Filter out documents that are in the paid lessons array
|
// Sort documents by created_at in descending order (most recent first)
|
||||||
const filteredDocuments = processedDocuments.filter(document => !paidLessons.includes(document?.d));
|
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));
|
||||||
|
|
||||||
setProcessedDocuments(filteredDocuments);
|
setProcessedDocuments(filteredDocuments);
|
||||||
} else {
|
} else {
|
||||||
console.log('No documents fetched or empty array returned');
|
console.log('No documents fetched or empty array returned');
|
||||||
@ -74,15 +73,6 @@ export default function DocumentsCarousel() {
|
|||||||
fetch();
|
fetch();
|
||||||
}, [documents, paidLessons]);
|
}, [documents, paidLessons]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (Object.keys(zapAmounts).length === processedDocuments.length) {
|
|
||||||
const sortedDocuments = [...processedDocuments].sort((a, b) =>
|
|
||||||
(zapAmounts[b.id] || 0) - (zapAmounts[a.id] || 0)
|
|
||||||
);
|
|
||||||
setProcessedDocuments(sortedDocuments);
|
|
||||||
}
|
|
||||||
}, [zapAmounts, processedDocuments]);
|
|
||||||
|
|
||||||
if (documentsError) {
|
if (documentsError) {
|
||||||
return <div>Error: {documentsError.message}</div>
|
return <div>Error: {documentsError.message}</div>
|
||||||
}
|
}
|
||||||
@ -104,7 +94,7 @@ export default function DocumentsCarousel() {
|
|||||||
}}
|
}}
|
||||||
itemTemplate={(item) =>
|
itemTemplate={(item) =>
|
||||||
processedDocuments.length > 0 ?
|
processedDocuments.length > 0 ?
|
||||||
<DocumentTemplate key={item.id} document={item} isLesson={freeLessons.includes(item.d)} handleZapAmountChange={handleZapAmountChange} /> :
|
<DocumentTemplate key={item.id} document={item} isLesson={freeLessons.includes(item.d)} /> :
|
||||||
<TemplateSkeleton key={Math.random()} />
|
<TemplateSkeleton key={Math.random()} />
|
||||||
}
|
}
|
||||||
responsiveOptions={responsiveOptions} />
|
responsiveOptions={responsiveOptions} />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, useCallback } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Carousel } from 'primereact/carousel';
|
import { Carousel } from 'primereact/carousel';
|
||||||
import { parseEvent } from '@/utils/nostr';
|
import { parseEvent } from '@/utils/nostr';
|
||||||
@ -30,15 +30,10 @@ export default function VideosCarousel() {
|
|||||||
const [processedVideos, setProcessedVideos] = useState([]);
|
const [processedVideos, setProcessedVideos] = useState([]);
|
||||||
const [paidLessons, setPaidLessons] = useState([]);
|
const [paidLessons, setPaidLessons] = useState([]);
|
||||||
const [freeLessons, setFreeLessons] = useState([]);
|
const [freeLessons, setFreeLessons] = useState([]);
|
||||||
const [zapAmounts, setZapAmounts] = 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;
|
||||||
|
|
||||||
const handleZapAmountChange = useCallback((videoId, amount) => {
|
|
||||||
setZapAmounts(prev => ({ ...prev, [videoId]: amount }));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get('/api/lessons').then(res => {
|
axios.get('/api/lessons').then(res => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
@ -60,8 +55,12 @@ export default function VideosCarousel() {
|
|||||||
try {
|
try {
|
||||||
if (videos && videos.length > 0 && paidLessons.length > 0) {
|
if (videos && videos.length > 0 && paidLessons.length > 0) {
|
||||||
const processedVideos = videos.map(video => parseEvent(video));
|
const processedVideos = videos.map(video => parseEvent(video));
|
||||||
// Filter out videos that are in the paid lessons array
|
|
||||||
const filteredVideos = processedVideos.filter(video => !paidLessons.includes(video?.d));
|
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));
|
||||||
|
|
||||||
setProcessedVideos(filteredVideos);
|
setProcessedVideos(filteredVideos);
|
||||||
} else {
|
} else {
|
||||||
console.log('No videos fetched or empty array returned');
|
console.log('No videos fetched or empty array returned');
|
||||||
@ -73,15 +72,6 @@ export default function VideosCarousel() {
|
|||||||
fetch();
|
fetch();
|
||||||
}, [videos, paidLessons]);
|
}, [videos, paidLessons]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (Object.keys(zapAmounts).length === processedVideos.length) {
|
|
||||||
const sortedVideos = [...processedVideos].sort((a, b) =>
|
|
||||||
(zapAmounts[b.id] || 0) - (zapAmounts[a.id] || 0)
|
|
||||||
);
|
|
||||||
setProcessedVideos(sortedVideos);
|
|
||||||
}
|
|
||||||
}, [zapAmounts, processedVideos]);
|
|
||||||
|
|
||||||
if (videosError) return <div>Error: {videosError}</div>;
|
if (videosError) return <div>Error: {videosError}</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -102,12 +92,7 @@ export default function VideosCarousel() {
|
|||||||
itemTemplate={(item) =>
|
itemTemplate={(item) =>
|
||||||
!processedVideos.length ?
|
!processedVideos.length ?
|
||||||
<TemplateSkeleton key={Math.random()} /> :
|
<TemplateSkeleton key={Math.random()} /> :
|
||||||
<VideoTemplate
|
<VideoTemplate key={item.id} video={item} isLesson={freeLessons.includes(item.d)} />
|
||||||
key={item.id}
|
|
||||||
video={item}
|
|
||||||
isLesson={freeLessons.includes(item.d)}
|
|
||||||
onZapAmountChange={handleZapAmountChange}
|
|
||||||
/>
|
|
||||||
}
|
}
|
||||||
responsiveOptions={responsiveOptions}
|
responsiveOptions={responsiveOptions}
|
||||||
/>
|
/>
|
||||||
|
@ -15,7 +15,7 @@ import useWindowWidth from "@/hooks/useWindowWidth";
|
|||||||
import GenericButton from "@/components/buttons/GenericButton";
|
import GenericButton from "@/components/buttons/GenericButton";
|
||||||
import appConfig from "@/config/appConfig";
|
import appConfig from "@/config/appConfig";
|
||||||
|
|
||||||
export function CourseTemplate({ course, onZapAmountChange }) {
|
export function CourseTemplate({ course }) {
|
||||||
const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: course });
|
const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: course });
|
||||||
const [zapAmount, setZapAmount] = useState(0);
|
const [zapAmount, setZapAmount] = useState(0);
|
||||||
const [lessonCount, setLessonCount] = useState(0);
|
const [lessonCount, setLessonCount] = useState(0);
|
||||||
@ -29,9 +29,8 @@ export function CourseTemplate({ course, onZapAmountChange }) {
|
|||||||
if (zaps.length > 0) {
|
if (zaps.length > 0) {
|
||||||
const total = getTotalFromZaps(zaps, course);
|
const total = getTotalFromZaps(zaps, course);
|
||||||
setZapAmount(total);
|
setZapAmount(total);
|
||||||
onZapAmountChange(course.id, total);
|
|
||||||
}
|
}
|
||||||
}, [zaps, course, onZapAmountChange]);
|
}, [zaps, course]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (course && course?.tags) {
|
if (course && course?.tags) {
|
||||||
|
@ -14,8 +14,9 @@ import useWindowWidth from "@/hooks/useWindowWidth";
|
|||||||
import GenericButton from "@/components/buttons/GenericButton";
|
import GenericButton from "@/components/buttons/GenericButton";
|
||||||
import appConfig from "@/config/appConfig";
|
import appConfig from "@/config/appConfig";
|
||||||
|
|
||||||
export function DocumentTemplate({ document, isLesson, onZapAmountChange }) {
|
export function DocumentTemplate({ document, isLesson }) {
|
||||||
const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: document });
|
const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: document });
|
||||||
|
const [nAddress, setNAddress] = useState(null);
|
||||||
const [zapAmount, setZapAmount] = useState(0);
|
const [zapAmount, setZapAmount] = useState(0);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { returnImageProxy } = useImageProxy();
|
const { returnImageProxy } = useImageProxy();
|
||||||
@ -38,9 +39,8 @@ export function DocumentTemplate({ document, isLesson, onZapAmountChange }) {
|
|||||||
if (zaps.length > 0) {
|
if (zaps.length > 0) {
|
||||||
const total = getTotalFromZaps(zaps, document);
|
const total = getTotalFromZaps(zaps, document);
|
||||||
setZapAmount(total);
|
setZapAmount(total);
|
||||||
onZapAmountChange(document.id, total);
|
|
||||||
}
|
}
|
||||||
}, [zaps, document, onZapAmountChange]);
|
}, [zaps, document]);
|
||||||
|
|
||||||
if (zapsError) return <div>Error: {zapsError}</div>;
|
if (zapsError) return <div>Error: {zapsError}</div>;
|
||||||
|
|
||||||
|
@ -15,8 +15,9 @@ import useWindowWidth from "@/hooks/useWindowWidth";
|
|||||||
import GenericButton from "@/components/buttons/GenericButton";
|
import GenericButton from "@/components/buttons/GenericButton";
|
||||||
import appConfig from "@/config/appConfig";
|
import appConfig from "@/config/appConfig";
|
||||||
|
|
||||||
export function VideoTemplate({ video, isLesson, onZapAmountChange }) {
|
export function VideoTemplate({ video, isLesson }) {
|
||||||
const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: video });
|
const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: video });
|
||||||
|
const [nAddress, setNAddress] = useState(null);
|
||||||
const [zapAmount, setZapAmount] = useState(0);
|
const [zapAmount, setZapAmount] = useState(0);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { returnImageProxy } = useImageProxy();
|
const { returnImageProxy } = useImageProxy();
|
||||||
@ -39,9 +40,8 @@ export function VideoTemplate({ video, isLesson, onZapAmountChange }) {
|
|||||||
if (zaps.length > 0) {
|
if (zaps.length > 0) {
|
||||||
const total = getTotalFromZaps(zaps, video);
|
const total = getTotalFromZaps(zaps, video);
|
||||||
setZapAmount(total);
|
setZapAmount(total);
|
||||||
onZapAmountChange(video.id, total);
|
|
||||||
}
|
}
|
||||||
}, [zaps, video, onZapAmountChange]);
|
}, [zaps, video]);
|
||||||
|
|
||||||
if (zapsError) return <div>Error: {zapsError}</div>;
|
if (zapsError) return <div>Error: {zapsError}</div>;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user