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 () => {
try {
const fetchedCourses = await fetchCourses();
console.log('fetchedCourses:', fetchedCourses);
if (fetchedCourses && fetchedCourses.length > 0) {
// First process the courses to be ready for display
const processedCourses = fetchedCourses.map(course => parseEvent(course));
console.log('processedCourses:', processedCourses);
// Fetch zaps for all processed courses at once
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

View File

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

View File

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