Course form improvements

This commit is contained in:
austinkelsay 2024-07-22 16:50:09 -05:00
parent 831e42d188
commit 06209b6371
5 changed files with 20 additions and 11 deletions

View File

@ -31,9 +31,11 @@ export default function CoursesCarousel() {
const fetch = async () => { const fetch = async () => {
try { try {
const fetchedCourses = await fetchCourses(); const fetchedCourses = await fetchCourses();
console.log('fetchedCourses:', fetchedCourses);
if (fetchedCourses && fetchedCourses.length > 0) { if (fetchedCourses && fetchedCourses.length > 0) {
// First process the courses to be ready for display // First process the courses to be ready for display
const processedCourses = fetchedCourses.map(course => parseEvent(course)); const processedCourses = fetchedCourses.map(course => parseEvent(course));
console.log('processedCourses:', processedCourses);
// Fetch zaps for all processed courses at once // Fetch zaps for all processed courses at once
const allZaps = await fetchZapsForEvents(processedCourses); const allZaps = await fetchZapsForEvents(processedCourses);

View File

@ -113,7 +113,7 @@ const CourseForm = () => {
]); ]);
} }
processedLessons.push({ id: lesson.d, noteId: lesson.id }); processedLessons.push({ id: lesson?.d });
} }
// Step 2: Create and publish course // Step 2: Create and publish course

View File

@ -11,7 +11,7 @@ const ZapDisplay = ({ zapAmount, event }) => {
<p className="text-xs cursor-pointer" onClick={(e) => op.current.toggle(e)}> <p className="text-xs cursor-pointer" onClick={(e) => op.current.toggle(e)}>
<i className="pi pi-bolt text-yellow-300"></i> <i className="pi pi-bolt text-yellow-300"></i>
{zapAmount ? zapAmount : <ProgressSpinner />} {zapAmount || zapAmount === 0 ? zapAmount : <ProgressSpinner />}
</p> </p>
<OverlayPanel className='w-[40%] h-[40%]' ref={op}> <OverlayPanel className='w-[40%] h-[40%]' ref={op}>
<ZapForm event={event} /> <ZapForm event={event} />

View File

@ -414,12 +414,13 @@ export function useNostr() {
}, [subscribe]); }, [subscribe]);
const fetchCourses = useCallback(async () => { const fetchCourses = useCallback(async () => {
const filter = [{ kinds: [30023], authors: [AUTHOR_PUBKEY] }]; const filter = [{ kinds: [30004], authors: [AUTHOR_PUBKEY] }];
const hasRequiredTags = (tags) => { // Do we need required tags for courses? community instead?
const hasPlebDevs = tags.some(([tag, value]) => tag === "t" && value === "plebdevs"); // const hasRequiredTags = (tags) => {
const hasCourse = tags.some(([tag, value]) => tag === "t" && value === "course"); // const hasPlebDevs = tags.some(([tag, value]) => tag === "t" && value === "plebdevs");
return hasPlebDevs && hasCourse; // const hasCourse = tags.some(([tag, value]) => tag === "t" && value === "course");
}; // return hasPlebDevs && hasCourse;
// };
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let courses = []; let courses = [];
@ -427,9 +428,10 @@ export function useNostr() {
filter, filter,
{ {
onevent: (event) => { onevent: (event) => {
if (hasRequiredTags(event.tags)) { // if (hasRequiredTags(event.tags)) {
courses.push(event); // courses.push(event);
} // }
courses.push(event);
}, },
onerror: (error) => { onerror: (error) => {
console.error('Error fetching courses:', error); console.error('Error fetching courses:', error);

View File

@ -72,6 +72,11 @@ export const parseEvent = (event) => {
} }
}); });
// if published_at is an empty string, then set it to event.created_at
if (!eventData.published_at) {
eventData.published_at = event.created_at;
}
return eventData; return eventData;
}; };