Improvements to course details

This commit is contained in:
austinkelsay 2024-08-16 17:08:35 -05:00
parent b8b10907bb
commit 4232c1963b
5 changed files with 17 additions and 70 deletions

View File

@ -21,16 +21,8 @@ const MDDisplay = dynamic(
} }
); );
const BitcoinConnectPayButton = dynamic(
() => import('@getalby/bitcoin-connect-react').then((mod) => mod.PayButton),
{
ssr: false,
}
);
export default function CourseDetails({ processedEvent }) { export default function CourseDetails({ processedEvent }) {
const [author, setAuthor] = useState(null); const [author, setAuthor] = useState(null);
const [bitcoinConnect, setBitcoinConnect] = useState(false);
const [nAddress, setNAddress] = useState(null); const [nAddress, setNAddress] = useState(null);
const [zapAmount, setZapAmount] = useState(0); const [zapAmount, setZapAmount] = useState(0);
const [user, setUser] = useState(null); const [user, setUser] = useState(null);
@ -46,15 +38,6 @@ export default function CourseDetails({ processedEvent }) {
} }
}, [session]); }, [session]);
const handleZapEvent = async () => {
if (!processedEvent) return;
// Update zap event logic if necessary for NDK
const response = await zapEvent(processedEvent);
console.log('zap response:', response);
};
const fetchAuthor = useCallback(async (pubkey) => { const fetchAuthor = useCallback(async (pubkey) => {
if (!pubkey) return; if (!pubkey) return;
const author = await ndk.getUser({ pubkey }); const author = await ndk.getUser({ pubkey });
@ -65,16 +48,6 @@ export default function CourseDetails({ processedEvent }) {
} }
}, [ndk]); }, [ndk]);
useEffect(() => {
if (typeof window === 'undefined') return;
const bitcoinConnectConfig = window.localStorage.getItem('bc:config');
if (bitcoinConnectConfig) {
setBitcoinConnect(true);
}
}, []);
useEffect(() => { useEffect(() => {
if (processedEvent) { if (processedEvent) {
fetchAuthor(processedEvent.pubkey); fetchAuthor(processedEvent.pubkey);
@ -141,15 +114,9 @@ export default function CourseDetails({ processedEvent }) {
height={194} height={194}
className="w-[344px] h-[194px] object-cover object-top rounded-lg" className="w-[344px] h-[194px] object-cover object-top rounded-lg"
/> />
{bitcoinConnect ? (
<div>
<BitcoinConnectPayButton onClick={handleZapEvent} />
</div>
) : (
<div className='w-full flex justify-end'> <div className='w-full flex justify-end'>
<ZapDisplay zapAmount={zapAmount} event={processedEvent} zapsLoading={zapsLoading} /> <ZapDisplay zapAmount={zapAmount} event={processedEvent} zapsLoading={zapsLoading} />
</div> </div>
)}
</div> </div>
)} )}
</div> </div>

View File

@ -7,13 +7,6 @@ import ZapDisplay from "@/components/zaps/ZapDisplay";
import dynamic from "next/dynamic"; import dynamic from "next/dynamic";
import { useZapsQuery } from "@/hooks/nostrQueries/zaps/useZapsQuery"; import { useZapsQuery } from "@/hooks/nostrQueries/zaps/useZapsQuery";
const BitcoinConnectPayButton = dynamic(
() => import('@getalby/bitcoin-connect-react').then((mod) => mod.PayButton),
{
ssr: false,
}
);
const MDDisplay = dynamic( const MDDisplay = dynamic(
() => import("@uiw/react-markdown-preview"), () => import("@uiw/react-markdown-preview"),
{ {
@ -22,26 +15,11 @@ const MDDisplay = dynamic(
); );
const CourseLesson = ({ lesson, course }) => { const CourseLesson = ({ lesson, course }) => {
const [bitcoinConnect, setBitcoinConnect] = useState(false);
const [zapAmount, setZapAmount] = useState(0); const [zapAmount, setZapAmount] = useState(0);
const { zaps, zapsLoading, zapsError } = useZapsQuery({ event: lesson, type: "lesson" }); const { zaps, zapsLoading, zapsError } = useZapsQuery({ event: lesson, type: "lesson" });
const { returnImageProxy } = useImageProxy(); const { returnImageProxy } = useImageProxy();
useEffect(() => {
if (typeof window === 'undefined') return;
const bitcoinConnectConfig = window.localStorage.getItem('bc:config');
if (bitcoinConnectConfig) {
setBitcoinConnect(true);
}
}, []);
const handleZapEvent = async () => {
return;
}
useEffect(() => { useEffect(() => {
if (!zaps || zapsLoading || zapsError) return; if (!zaps || zapsLoading || zapsError) return;
@ -90,15 +68,9 @@ const CourseLesson = ({ lesson, course }) => {
height={194} height={194}
className="w-[344px] h-[194px] object-cover object-top rounded-lg" className="w-[344px] h-[194px] object-cover object-top rounded-lg"
/> />
{bitcoinConnect ? (
<div>
<BitcoinConnectPayButton onClick={handleZapEvent} />
</div>
) : (
<div className="w-full flex justify-end"> <div className="w-full flex justify-end">
<ZapDisplay zapAmount={zapAmount} event={lesson} zapsLoading={zapsLoading} /> <ZapDisplay zapAmount={zapAmount} event={lesson} zapsLoading={zapsLoading} />
</div> </div>
)}
</div> </div>
)} )}
</div> </div>

View File

@ -115,12 +115,12 @@ export default function DraftCourseDetails({ processedEvent, draftId, lessons })
await axios.delete(`/api/courses/drafts/${processedEvent.id}`); await axios.delete(`/api/courses/drafts/${processedEvent.id}`);
// Step 6: Show success message and redirect // Step 6: Show success message and redirect
showToast('success', 'Course created successfully'); showToast('success', 'Success', 'Course created successfully');
router.push(`/course/${courseEvent.id}`); router.push(`/course/${courseEvent.id}`);
} catch (error) { } catch (error) {
console.error('Error creating course:', error); console.error('Error creating course:', error);
showToast('error', error.message || 'Failed to create course. Please try again.'); showToast('error', 'Error', error.message || 'Failed to create course. Please try again.');
} }
}; };

View File

@ -8,7 +8,15 @@ const ContentListItem = (content) => {
const { returnImageProxy } = useImageProxy(); const { returnImageProxy } = useImageProxy();
const router = useRouter(); const router = useRouter();
const isDraft = Object.keys(content).includes('type'); const isDraft = Object.keys(content).includes('type');
const isCourse = content && content?.resources && content?.resources?.length > 0; const isCourse = content && content?.kind === 30004;
useEffect(() => {
if (content && content?.kind === 30004) {
console.log("isDraft", isDraft);
console.log("content", content);
console.log("isCourse", isCourse);
}
}, [content, isDraft, isCourse]);
const handleClick = () => { const handleClick = () => {
let path = ''; let path = '';
@ -21,8 +29,8 @@ const ContentListItem = (content) => {
path = '/details'; path = '/details';
} }
const draftSuffix = isCourse ? '/draft' : ''; // const draftSuffix = isCourse ? '/draft' : '';
const fullPath = `${path}/${content.id}${draftSuffix}`; const fullPath = `${path}/${content.id}`;
router.push(fullPath); router.push(fullPath);
}; };

View File

@ -2,7 +2,7 @@ import React, { useEffect, useState, useCallback } from "react";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { parseCourseEvent, parseEvent, findKind0Fields } from "@/utils/nostr"; import { parseCourseEvent, parseEvent, findKind0Fields } from "@/utils/nostr";
import CourseDetails from "@/components/content/courses/CourseDetails"; import CourseDetails from "@/components/content/courses/CourseDetails";
import CourseLesson from "@/components/courses/CourseLesson"; import CourseLesson from "@/components/content/courses/CourseLesson";
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { useNDKContext } from "@/context/NDKContext"; import { useNDKContext } from "@/context/NDKContext";