mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-23 16:05:24 +00:00
Reset relays again
This commit is contained in:
parent
0a39f4f1c3
commit
e40ec068e7
@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect, use } from 'react';
|
import React, { useState, useEffect, useCallback } 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,20 +26,21 @@ 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');
|
||||||
}
|
}
|
||||||
@ -50,6 +51,15 @@ 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>
|
||||||
}
|
}
|
||||||
@ -73,7 +83,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} />
|
<CourseTemplate key={item.id} course={item} onZapAmountChange={handleZapAmountChange} />
|
||||||
}
|
}
|
||||||
responsiveOptions={responsiveOptions} />
|
responsiveOptions={responsiveOptions} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -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 }) {
|
export function CourseTemplate({ course, onZapAmountChange }) {
|
||||||
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,8 +29,9 @@ export function CourseTemplate({ course }) {
|
|||||||
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]);
|
}, [zaps, course, onZapAmountChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (course && course?.tags) {
|
if (course && course?.tags) {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
const appConfig = {
|
const appConfig = {
|
||||||
defaultRelayUrls: [
|
defaultRelayUrls: [
|
||||||
// "wss://nos.lol/",
|
"wss://nos.lol/",
|
||||||
// "wss://relay.damus.io/",
|
"wss://relay.damus.io/",
|
||||||
// "wss://relay.snort.social/",
|
"wss://relay.snort.social/",
|
||||||
// "wss://relay.nostr.band/",
|
"wss://relay.nostr.band/",
|
||||||
// "wss://relay.mutinywallet.com/",
|
"wss://relay.mutinywallet.com/",
|
||||||
// "wss://relay.primal.net/",
|
"wss://relay.primal.net/",
|
||||||
// "wss://nostr21.com/",
|
"wss://nostr21.com/",
|
||||||
// "wss://nostrue.com/",
|
"wss://nostrue.com/",
|
||||||
// "wss://purplerelay.com/",
|
"wss://purplerelay.com/",
|
||||||
"wss://relay.devs.tools/"
|
"wss://relay.devs.tools/"
|
||||||
],
|
],
|
||||||
authorPubkeys: ["8cb60e215678879cda0bef4d5b3fc1a5c5925d2adb5d8c4fa7b7d03b5f2deaea", "676c02247668d5b18479be3d1a80933044256f3fbd03640a8c234684e641b6d6", "f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741"],
|
authorPubkeys: ["8cb60e215678879cda0bef4d5b3fc1a5c5925d2adb5d8c4fa7b7d03b5f2deaea", "676c02247668d5b18479be3d1a80933044256f3fbd03640a8c234684e641b6d6", "f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741"],
|
||||||
|
@ -11,8 +11,8 @@ const readOnlyRelays = ["wss://nostr21.com/", "wss://nostr.wine/", "wss://yestr.
|
|||||||
export const NDKProvider = ({ children }) => {
|
export const NDKProvider = ({ children }) => {
|
||||||
const [ndk, setNdk] = useState(null);
|
const [ndk, setNdk] = useState(null);
|
||||||
// todo: remove this after testing phase
|
// todo: remove this after testing phase
|
||||||
// const [userRelays, setUserRelays] = useLocalStorage("userRelays", appConfig.defaultRelayUrls);
|
const [userRelays, setUserRelays] = useLocalStorage("userRelays", appConfig.defaultRelayUrls);
|
||||||
const [userRelays, setUserRelays] = useState([...readOnlyRelays, "wss://relay.devs.tools"]);
|
// const [userRelays, setUserRelays] = useState([...readOnlyRelays, "wss://relay.devs.tools"]);
|
||||||
|
|
||||||
const createNDKInstance = (relays) => {
|
const createNDKInstance = (relays) => {
|
||||||
const allRelays = [...new Set([...appConfig.defaultRelayUrls, ...relays])];
|
const allRelays = [...new Set([...appConfig.defaultRelayUrls, ...relays])];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user