Progress on course for, deleting draft after posting

This commit is contained in:
austinkelsay 2024-04-30 12:34:48 -05:00
parent 7ce97d158c
commit 43d0c6d321
4 changed files with 32 additions and 27 deletions

View File

@ -31,6 +31,7 @@ const ContentDropdownItem = ({ content, onSelect, selected }) => {
return ( return (
<div className="w-full border-t-2 border-gray-700 py-4"> <div className="w-full border-t-2 border-gray-700 py-4">
<div className="flex flex-row gap-4 p-2"> <div className="flex flex-row gap-4 p-2">
{console.log(content)}
<Image <Image
alt="content thumbnail" alt="content thumbnail"
src={returnImageProxy(content.image)} src={returnImageProxy(content.image)}

View File

@ -8,6 +8,7 @@ import { Dropdown } from "primereact/dropdown";
import { v4 as uuidv4, v4 } from 'uuid'; import { v4 as uuidv4, v4 } from 'uuid';
import { useLocalStorageWithEffect } from "@/hooks/useLocalStorage"; import { useLocalStorageWithEffect } from "@/hooks/useLocalStorage";
import { useNostr } from "@/hooks/useNostr"; import { useNostr } from "@/hooks/useNostr";
import {nip19} from "nostr-tools"
import { parseEvent } from "@/utils/nostr"; import { parseEvent } from "@/utils/nostr";
import ContentDropdownItem from "@/components/content/dropdowns/ContentDropdownItem"; import ContentDropdownItem from "@/components/content/dropdowns/ContentDropdownItem";
import 'primeicons/primeicons.css'; import 'primeicons/primeicons.css';
@ -113,19 +114,28 @@ const CourseForm = () => {
// Add the signed event's id to finalIds // Add the signed event's id to finalIds
finalIds.push(signedEvent.id); finalIds.push(signedEvent.id);
// Publish the lesson (uncomment the line below if you want to publish immediately) const published = await publish(signedEvent);
// await publish(signedEvent);
if (published) {
// delete the draft
axios.delete(`/api/drafts/${lesson.id}`)
.then((response) => {
console.log('Draft deleted:', response);
})
.catch((error) => {
console.error('Error deleting draft:', error);
});
}
} }
} }
console.log('finalIds:', finalIds); console.log('finalIds:', finalIds);
const testIds = ["8e364adf6b81ef34d30f42bf0356a9b362bf928e178d7bcd4baa912623f6b3ee", "41bcee8f1293ee3cc221f5bc1417ee3f5accfa90ccec8db4f9eda7e8ffef5c30"]
// Fetch all of the lessons from Nostr by their ids // Fetch all of the lessons from Nostr by their ids
const fetchedLessons = await Promise.all( const fetchedLessons = await Promise.all(
testIds.map(async (id) => { finalIds.map(async (id) => {
const lesson = await fetchSingleEvent(id); const lesson = await fetchSingleEvent(id);
console.log('got lesson:', lesson);
return lesson; return lesson;
}) })
); );
@ -152,7 +162,7 @@ const CourseForm = () => {
if (parsedLessons.length === selectedLessons.length) { if (parsedLessons.length === selectedLessons.length) {
// Create a new course event // Create a new course event
const courseEvent = { const courseEvent = {
kind: 30005, kind: 30004,
created_at: Math.floor(Date.now() / 1000), created_at: Math.floor(Date.now() / 1000),
content: "", content: "",
tags: [ tags: [
@ -164,14 +174,11 @@ const CourseForm = () => {
], ],
}; };
console.log('courseEvent:', courseEvent);
// Sign the course event // Sign the course event
const signedCourseEvent = await window?.nostr?.signEvent(courseEvent); const signedCourseEvent = await window?.nostr?.signEvent(courseEvent);
console.log('signedCourseEvent:', signedCourseEvent);
// Publish the course event using Nostr // Publish the course event using Nostr
// await publish(signedCourseEvent); await publish(signedCourseEvent);
}
// Reset the form fields after publishing the course // Reset the form fields after publishing the course
setTitle(''); setTitle('');
@ -182,6 +189,7 @@ const CourseForm = () => {
setLessons([{ id: uuidv4(), title: 'Select a lesson' }]); setLessons([{ id: uuidv4(), title: 'Select a lesson' }]);
setSelectedLessons([]); setSelectedLessons([]);
setTopics(['']); setTopics(['']);
}
}; };
const handleLessonChange = (e, index) => { const handleLessonChange = (e, index) => {

View File

@ -1,6 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import axios from 'axios'; import axios from 'axios';
import router from 'next/router'; import { useRouter } from 'next/router';
import { InputText } from 'primereact/inputtext'; import { InputText } from 'primereact/inputtext';
import { InputNumber } from 'primereact/inputnumber'; import { InputNumber } from 'primereact/inputnumber';
import { InputSwitch } from 'primereact/inputswitch'; import { InputSwitch } from 'primereact/inputswitch';

View File

@ -57,8 +57,10 @@ export function useNostr() {
try { try {
await Promise.any(pool.publish(defaultRelays, event)); await Promise.any(pool.publish(defaultRelays, event));
console.log('Published event to at least one relay'); console.log('Published event to at least one relay');
return true;
} catch (error) { } catch (error) {
console.error('Failed to publish event:', error); console.error('Failed to publish event:', error);
return false;
} }
}, },
[pool] [pool]
@ -388,9 +390,6 @@ export function useNostr() {
filter, filter,
{ {
onevent: (event) => { onevent: (event) => {
if (event.id === "fe63bb28f3e560046f3653edff75fb1d816412e5a7a1dfdddca5494d94ff22c9") {
console.log('event:!!!!', event);
}
if (hasRequiredTags(event.tags)) { if (hasRequiredTags(event.tags)) {
workshops.push(event); workshops.push(event);
} }
@ -421,9 +420,6 @@ export function useNostr() {
const hasCourse = tags.some(([tag, value]) => tag === "t" && value === "course"); const hasCourse = tags.some(([tag, value]) => tag === "t" && value === "course");
console.log('hasPlebDevs:', hasPlebDevs);
console.log('hasCourse:', hasCourse);
return hasPlebDevs && hasCourse; return hasPlebDevs && hasCourse;
}; };