mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-03 07:42:03 +00:00
linted before rebase
This commit is contained in:
parent
07e94fbb40
commit
ad218d8803
@ -6,4 +6,4 @@
|
||||
"printWidth": 100,
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,6 @@
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
|
||||
const ZapThreadsWrapper = ({
|
||||
anchor,
|
||||
user,
|
||||
relays,
|
||||
disable,
|
||||
className,
|
||||
isAuthorized,
|
||||
}) => {
|
||||
const ZapThreadsWrapper = ({ anchor, user, relays, disable, className, isAuthorized }) => {
|
||||
// Create a ref to store the reference to the <div> element
|
||||
const zapRef = useRef(null);
|
||||
|
||||
@ -18,37 +11,37 @@ const ZapThreadsWrapper = ({
|
||||
}
|
||||
|
||||
// Create a new <script> element
|
||||
const script = document.createElement("script");
|
||||
const script = document.createElement('script');
|
||||
// Set the source URL of the script to load the ZapThreads library
|
||||
script.src = "https://unpkg.com/zapthreads/dist/zapthreads.iife.js";
|
||||
script.src = 'https://unpkg.com/zapthreads/dist/zapthreads.iife.js';
|
||||
// Set the script to load asynchronously
|
||||
script.async = true;
|
||||
|
||||
// Function to handle the script load event
|
||||
const handleScriptLoad = () => {
|
||||
// Create a new <zap-threads> element
|
||||
const zapElement = document.createElement("zap-threads");
|
||||
zapElement.setAttribute("anchor", anchor);
|
||||
const zapElement = document.createElement('zap-threads');
|
||||
zapElement.setAttribute('anchor', anchor);
|
||||
|
||||
// Only set user if it exists and is not null
|
||||
if (user) {
|
||||
zapElement.setAttribute("user", user);
|
||||
zapElement.setAttribute('user', user);
|
||||
}
|
||||
|
||||
// Clean up relay URLs
|
||||
const cleanRelays = relays
|
||||
.split(",")
|
||||
.map((relay) => relay.trim())
|
||||
.filter((relay) => relay)
|
||||
.join(",");
|
||||
zapElement.setAttribute("relays", cleanRelays);
|
||||
.split(',')
|
||||
.map(relay => relay.trim())
|
||||
.filter(relay => relay)
|
||||
.join(',');
|
||||
zapElement.setAttribute('relays', cleanRelays);
|
||||
|
||||
// Always set disable attribute, even if empty
|
||||
zapElement.setAttribute("disable", disable || "");
|
||||
zapElement.setAttribute('disable', disable || '');
|
||||
|
||||
// Add error handling
|
||||
zapElement.addEventListener("error", (e) => {
|
||||
console.error("ZapThreads error:", e);
|
||||
zapElement.addEventListener('error', e => {
|
||||
console.error('ZapThreads error:', e);
|
||||
});
|
||||
|
||||
// Remove any existing <zap-threads> element
|
||||
@ -65,9 +58,9 @@ const ZapThreadsWrapper = ({
|
||||
};
|
||||
|
||||
// Attach the handleScriptLoad function to the script's load event
|
||||
script.addEventListener("load", handleScriptLoad);
|
||||
script.addEventListener("error", (e) => {
|
||||
console.error("Failed to load ZapThreads script:", e);
|
||||
script.addEventListener('load', handleScriptLoad);
|
||||
script.addEventListener('error', e => {
|
||||
console.error('Failed to load ZapThreads script:', e);
|
||||
});
|
||||
|
||||
// Append the <script> element to the <body> of the document
|
||||
@ -83,7 +76,7 @@ const ZapThreadsWrapper = ({
|
||||
// Remove the <script> element from the <body> of the document
|
||||
document.body.removeChild(script);
|
||||
// Remove the load event listener from the script
|
||||
script.removeEventListener("load", handleScriptLoad);
|
||||
script.removeEventListener('load', handleScriptLoad);
|
||||
};
|
||||
}, [anchor, user, relays, disable, isAuthorized]);
|
||||
|
||||
@ -92,9 +85,7 @@ const ZapThreadsWrapper = ({
|
||||
}
|
||||
|
||||
// Render a <div> element and attach the zapRef to it
|
||||
return (
|
||||
<div className={`overflow-x-hidden ${className || ""}`} ref={zapRef} />
|
||||
);
|
||||
return <div className={`overflow-x-hidden ${className || ''}`} ref={zapRef} />;
|
||||
};
|
||||
|
||||
export default ZapThreadsWrapper;
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
} from '@/components/ui/card';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import ZapDisplay from '@/components/zaps/ZapDisplay';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import Image from 'next/image';
|
||||
import { useZapsSubscription } from '@/hooks/nostrQueries/zaps/useZapsSubscription';
|
||||
@ -22,7 +23,7 @@ import useWindowWidth from '@/hooks/useWindowWidth';
|
||||
import GenericButton from '@/components/buttons/GenericButton';
|
||||
import appConfig from '@/config/appConfig';
|
||||
import { BookOpen } from 'lucide-react';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
import { useSession } from 'next-auth/react';
|
||||
|
||||
export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
const { zaps, zapsLoading, zapsError } = useZapsSubscription({
|
||||
@ -74,6 +75,15 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
}
|
||||
}, [course]);
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
const shouldShowMetaTags = topic => {
|
||||
if (!showMetaTags) {
|
||||
return !['lesson', 'document', 'video', 'course'].includes(topic);
|
||||
@ -112,9 +122,7 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
</div>
|
||||
<CardHeader className="flex flex-row justify-between items-center p-4 border-b border-gray-700">
|
||||
<div className="flex items-center gap-4">
|
||||
<CardTitle className="text-xl sm:text-2xl text-[#f8f8ff]">
|
||||
{course.name}
|
||||
</CardTitle>
|
||||
<CardTitle className="text-xl sm:text-2xl text-[#f8f8ff]">{course.name}</CardTitle>
|
||||
</div>
|
||||
<div className="text-[#f8f8ff]">
|
||||
<ZapDisplay
|
||||
@ -125,7 +133,9 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent
|
||||
className={`${isMobile ? 'px-3' : ''} pt-4 pb-2 w-full flex flex-row justify-between items-center`}
|
||||
className={`${
|
||||
isMobile ? 'px-3' : ''
|
||||
} pt-4 pb-2 w-full flex flex-row justify-between items-center`}
|
||||
>
|
||||
<div className="flex flex-wrap gap-2 max-w-[65%]">
|
||||
{course &&
|
||||
@ -156,7 +166,9 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
)}
|
||||
</CardContent>
|
||||
<CardDescription
|
||||
className={`${isMobile ? 'w-full p-3' : 'p-6'} py-2 pt-0 text-base text-neutral-50/90 dark:text-neutral-900/90 overflow-hidden min-h-[4em] flex items-center max-w-[100%]`}
|
||||
className={`${
|
||||
isMobile ? 'w-full p-3' : 'p-6'
|
||||
} py-2 pt-0 text-base text-neutral-50/90 dark:text-neutral-900/90 overflow-hidden min-h-[4em] flex items-center max-w-[100%]`}
|
||||
style={{
|
||||
overflow: 'hidden',
|
||||
display: '-webkit-box',
|
||||
@ -173,7 +185,9 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
</p>
|
||||
</CardDescription>
|
||||
<CardFooter
|
||||
className={`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 border-t border-gray-700 pt-4 ${isMobile ? 'px-3' : ''}`}
|
||||
className={`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 border-t border-gray-700 pt-4 ${
|
||||
isMobile ? 'px-3' : ''
|
||||
}`}
|
||||
>
|
||||
<p className="text-sm text-gray-300">
|
||||
{course?.published_at && course.published_at !== ''
|
||||
@ -194,22 +208,20 @@ export function CourseTemplate({ course, showMetaTags = true }) {
|
||||
(!course?.price ||
|
||||
course.price === 0 ||
|
||||
session?.user?.role?.subscribed ||
|
||||
session?.user?.purchased?.some(
|
||||
(purchase) => purchase.resourceId === course.d
|
||||
)) && (
|
||||
session?.user?.purchased?.some(purchase => purchase.resourceId === course.d)) && (
|
||||
<div className="px-4 pb-4">
|
||||
{nsec || npub ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={nsec || npub || null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
/>
|
||||
) : (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={npub}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
/>
|
||||
)}
|
||||
|
@ -1,25 +1,25 @@
|
||||
import React, { useEffect, useState, useRef } from "react";
|
||||
import axios from "axios";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { Tag } from "primereact/tag";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/router";
|
||||
import ResourcePaymentButton from "@/components/bitcoinConnect/ResourcePaymentButton";
|
||||
import ZapDisplay from "@/components/zaps/ZapDisplay";
|
||||
import GenericButton from "@/components/buttons/GenericButton";
|
||||
import { useImageProxy } from "@/hooks/useImageProxy";
|
||||
import { useZapsSubscription } from "@/hooks/nostrQueries/zaps/useZapsSubscription";
|
||||
import { getTotalFromZaps } from "@/utils/lightning";
|
||||
import { useSession } from "next-auth/react";
|
||||
import useWindowWidth from "@/hooks/useWindowWidth";
|
||||
import dynamic from "next/dynamic";
|
||||
import { Toast } from "primereact/toast";
|
||||
import MoreOptionsMenu from "@/components/ui/MoreOptionsMenu";
|
||||
import ZapThreadsWrapper from "@/components/ZapThreadsWrapper";
|
||||
import appConfig from "@/config/appConfig";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import axios from 'axios';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/router';
|
||||
import ResourcePaymentButton from '@/components/bitcoinConnect/ResourcePaymentButton';
|
||||
import ZapDisplay from '@/components/zaps/ZapDisplay';
|
||||
import GenericButton from '@/components/buttons/GenericButton';
|
||||
import { useImageProxy } from '@/hooks/useImageProxy';
|
||||
import { useZapsSubscription } from '@/hooks/nostrQueries/zaps/useZapsSubscription';
|
||||
import { getTotalFromZaps } from '@/utils/lightning';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import useWindowWidth from '@/hooks/useWindowWidth';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import MoreOptionsMenu from '@/components/ui/MoreOptionsMenu';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
import appConfig from '@/config/appConfig';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
const MDDisplay = dynamic(() => import("@uiw/react-markdown-preview"), {
|
||||
const MDDisplay = dynamic(() => import('@uiw/react-markdown-preview'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
@ -57,65 +57,57 @@ const CombinedDetails = ({
|
||||
try {
|
||||
const response = await axios.delete(`/api/resources/${processedEvent.d}`);
|
||||
if (response.status === 204) {
|
||||
showToast("success", "Success", "Resource deleted successfully.");
|
||||
router.push("/");
|
||||
showToast('success', 'Success', 'Resource deleted successfully.');
|
||||
router.push('/');
|
||||
}
|
||||
} catch (error) {
|
||||
if (
|
||||
error.response?.data?.error?.includes(
|
||||
"Invalid `prisma.resource.delete()`"
|
||||
)
|
||||
) {
|
||||
if (error.response?.data?.error?.includes('Invalid `prisma.resource.delete()`')) {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Resource cannot be deleted because it is part of a course, delete the course first."
|
||||
'error',
|
||||
'Error',
|
||||
'Resource cannot be deleted because it is part of a course, delete the course first.'
|
||||
);
|
||||
} else {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Failed to delete resource. Please try again."
|
||||
);
|
||||
showToast('error', 'Error', 'Failed to delete resource. Please try again.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const authorMenuItems = [
|
||||
{
|
||||
label: "Edit",
|
||||
icon: "pi pi-pencil",
|
||||
label: 'Edit',
|
||||
icon: 'pi pi-pencil',
|
||||
command: () => router.push(`/details/${processedEvent.id}/edit`),
|
||||
},
|
||||
{
|
||||
label: "Delete",
|
||||
icon: "pi pi-trash",
|
||||
label: 'Delete',
|
||||
icon: 'pi pi-trash',
|
||||
command: handleDelete,
|
||||
},
|
||||
{
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
window.open(`https://habla.news/a/${nAddress}`, "_blank");
|
||||
window.open(`https://habla.news/a/${nAddress}`, '_blank');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const userMenuItems = [
|
||||
{
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
window.open(`https://habla.news/a/${nAddress}`, "_blank");
|
||||
window.open(`https://habla.news/a/${nAddress}`, '_blank');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (course) {
|
||||
userMenuItems.unshift({
|
||||
label: isMobileView ? "Course" : "Open Course",
|
||||
icon: "pi pi-external-link",
|
||||
command: () => window.open(`/course/${course}`, "_blank"),
|
||||
label: isMobileView ? 'Course' : 'Open Course',
|
||||
icon: 'pi pi-external-link',
|
||||
command: () => window.open(`/course/${course}`, '_blank'),
|
||||
});
|
||||
}
|
||||
|
||||
@ -123,13 +115,13 @@ const CombinedDetails = ({
|
||||
if (isLesson) {
|
||||
axios
|
||||
.get(`/api/resources/${processedEvent.d}`)
|
||||
.then((res) => {
|
||||
.then(res => {
|
||||
if (res.data && res.data.lessons[0]?.courseId) {
|
||||
setCourse(res.data.lessons[0]?.courseId);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("err", err);
|
||||
.catch(err => {
|
||||
console.error('err', err);
|
||||
});
|
||||
}
|
||||
}, [processedEvent.d, isLesson]);
|
||||
@ -143,7 +135,7 @@ const CombinedDetails = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, "hex");
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
@ -154,7 +146,7 @@ const CombinedDetails = ({
|
||||
if (session?.user?.role?.subscribed && decryptedContent) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip="You are subscribed so you can access all paid content"
|
||||
icon="pi pi-check"
|
||||
label="Subscribed"
|
||||
@ -169,14 +161,14 @@ const CombinedDetails = ({
|
||||
if (
|
||||
isLesson &&
|
||||
course &&
|
||||
session?.user?.purchased?.some((purchase) => purchase.courseId === course)
|
||||
session?.user?.purchased?.some(purchase => purchase.courseId === course)
|
||||
) {
|
||||
const coursePurchase = session?.user?.purchased?.find(
|
||||
(purchase) => purchase.courseId === course
|
||||
purchase => purchase.courseId === course
|
||||
);
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You have this lesson through purchasing the course it belongs to. You paid ${coursePurchase?.course?.price} sats for the course.`}
|
||||
icon="pi pi-check"
|
||||
label={`Paid ${coursePurchase?.course?.price} sats`}
|
||||
@ -207,14 +199,10 @@ const CombinedDetails = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
paidResource &&
|
||||
author &&
|
||||
processedEvent?.pubkey === session?.user?.pubkey
|
||||
) {
|
||||
if (paidResource && author && processedEvent?.pubkey === session?.user?.pubkey) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You created this paid content, users must pay ${processedEvent.price} sats to access it`}
|
||||
icon="pi pi-check"
|
||||
label={`Price ${processedEvent.price} sats`}
|
||||
@ -231,12 +219,7 @@ const CombinedDetails = ({
|
||||
|
||||
const renderContent = () => {
|
||||
if (decryptedContent) {
|
||||
return (
|
||||
<MDDisplay
|
||||
className="p-2 rounded-lg w-full"
|
||||
source={decryptedContent}
|
||||
/>
|
||||
);
|
||||
return <MDDisplay className="p-2 rounded-lg w-full" source={decryptedContent} />;
|
||||
}
|
||||
|
||||
if (paidResource && !decryptedContent) {
|
||||
@ -264,12 +247,7 @@ const CombinedDetails = ({
|
||||
}
|
||||
|
||||
if (processedEvent?.content) {
|
||||
return (
|
||||
<MDDisplay
|
||||
className="p-4 rounded-lg w-full"
|
||||
source={processedEvent.content}
|
||||
/>
|
||||
);
|
||||
return <MDDisplay className="p-4 rounded-lg w-full" source={processedEvent.content} />;
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -279,12 +257,7 @@ const CombinedDetails = ({
|
||||
<div className="w-full">
|
||||
<Toast ref={toastRef} />
|
||||
<div className="relative w-full h-[400px] mb-8">
|
||||
<Image
|
||||
alt="background image"
|
||||
src={returnImageProxy(image)}
|
||||
fill
|
||||
className="object-cover"
|
||||
/>
|
||||
<Image alt="background image" src={returnImageProxy(image)} fill className="object-cover" />
|
||||
<div className="absolute inset-0 bg-black bg-opacity-20"></div>
|
||||
</div>
|
||||
<div className="w-full mx-auto px-4 py-8 -mt-32 relative z-10 max-mob:px-0 max-tab:px-0">
|
||||
@ -301,11 +274,9 @@ const CombinedDetails = ({
|
||||
{topics?.map((topic, index) => (
|
||||
<Tag className="text-[#f8f8ff]" key={index} value={topic} />
|
||||
))}
|
||||
{isLesson && (
|
||||
<Tag size="small" className="text-[#f8f8ff]" value="lesson" />
|
||||
)}
|
||||
{isLesson && <Tag size="small" className="text-[#f8f8ff]" value="lesson" />}
|
||||
</div>
|
||||
{summary?.split("\n").map((line, index) => (
|
||||
{summary?.split('\n').map((line, index) => (
|
||||
<p key={index}>{line}</p>
|
||||
))}
|
||||
<div className="flex items-center justify-between mt-8">
|
||||
@ -318,7 +289,7 @@ const CombinedDetails = ({
|
||||
className="rounded-full mr-4"
|
||||
/>
|
||||
<p className="text-lg text-white">
|
||||
By{" "}
|
||||
By{' '}
|
||||
<a
|
||||
rel="noreferrer noopener"
|
||||
target="_blank"
|
||||
@ -339,21 +310,19 @@ const CombinedDetails = ({
|
||||
<div className="w-full mt-4">{renderPaymentMessage()}</div>
|
||||
{nAddress && (
|
||||
<div className="mt-8">
|
||||
{!paidResource ||
|
||||
decryptedContent ||
|
||||
session?.user?.role?.subscribed ? (
|
||||
{!paidResource || decryptedContent || session?.user?.role?.subscribed ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={session?.user ? nsec || npub : null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
isAuthorized={true}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center p-4 bg-gray-800/50 rounded-lg">
|
||||
<p className="text-gray-400">
|
||||
Comments are only available to content purchasers,
|
||||
subscribers, and the content creator.
|
||||
Comments are only available to content purchasers, subscribers, and the content
|
||||
creator.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
@ -21,6 +21,7 @@ import WelcomeModal from '@/components/onboarding/WelcomeModal';
|
||||
import { ProgressSpinner } from 'primereact/progressspinner';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import MoreOptionsMenu from '@/components/ui/MoreOptionsMenu';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
|
||||
export default function CourseDetails({
|
||||
processedEvent,
|
||||
@ -122,7 +123,7 @@ export default function CourseDetails({
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, "hex");
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
@ -130,14 +131,10 @@ export default function CourseDetails({
|
||||
}, [session]);
|
||||
|
||||
const renderPaymentMessage = () => {
|
||||
if (
|
||||
session?.user &&
|
||||
session.user?.role?.subscribed &&
|
||||
decryptionPerformed
|
||||
) {
|
||||
if (session?.user && session.user?.role?.subscribed && decryptionPerformed) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You are subscribed so you can access all paid content`}
|
||||
icon="pi pi-check"
|
||||
label="Subscribed"
|
||||
@ -291,15 +288,15 @@ export default function CourseDetails({
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={session?.user ? nsec || npub : null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
isAuthorized={true}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center p-4 bg-gray-800/50 rounded-lg">
|
||||
<p className="text-gray-400">
|
||||
Comments are only available to course purchasers,
|
||||
subscribers, and the course creator.
|
||||
Comments are only available to course purchasers, subscribers, and the course
|
||||
creator.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
@ -308,7 +305,7 @@ export default function CourseDetails({
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={session?.user ? nsec || npub : null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
isAuthorized={true}
|
||||
/>
|
||||
|
@ -1,38 +1,32 @@
|
||||
import React, { useEffect, useState, useRef } from "react";
|
||||
import { Tag } from "primereact/tag";
|
||||
import Image from "next/image";
|
||||
import { useImageProxy } from "@/hooks/useImageProxy";
|
||||
import { getTotalFromZaps } from "@/utils/lightning";
|
||||
import ZapDisplay from "@/components/zaps/ZapDisplay";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useZapsQuery } from "@/hooks/nostrQueries/zaps/useZapsQuery";
|
||||
import { Toast } from "primereact/toast";
|
||||
import useTrackDocumentLesson from "@/hooks/tracking/useTrackDocumentLesson";
|
||||
import useWindowWidth from "@/hooks/useWindowWidth";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import appConfig from "@/config/appConfig";
|
||||
import MoreOptionsMenu from "@/components/ui/MoreOptionsMenu";
|
||||
import { useSession } from "next-auth/react";
|
||||
import ZapThreadsWrapper from "@/components/ZapThreadsWrapper";
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import Image from 'next/image';
|
||||
import { useImageProxy } from '@/hooks/useImageProxy';
|
||||
import { getTotalFromZaps } from '@/utils/lightning';
|
||||
import ZapDisplay from '@/components/zaps/ZapDisplay';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { useZapsQuery } from '@/hooks/nostrQueries/zaps/useZapsQuery';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import useTrackDocumentLesson from '@/hooks/tracking/useTrackDocumentLesson';
|
||||
import useWindowWidth from '@/hooks/useWindowWidth';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import appConfig from '@/config/appConfig';
|
||||
import MoreOptionsMenu from '@/components/ui/MoreOptionsMenu';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
|
||||
const MDDisplay = dynamic(() => import("@uiw/react-markdown-preview"), {
|
||||
const MDDisplay = dynamic(() => import('@uiw/react-markdown-preview'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
const CourseLesson = ({
|
||||
lesson,
|
||||
course,
|
||||
decryptionPerformed,
|
||||
isPaid,
|
||||
setCompleted,
|
||||
}) => {
|
||||
const CourseLesson = ({ lesson, course, decryptionPerformed, isPaid, setCompleted }) => {
|
||||
const [zapAmount, setZapAmount] = useState(0);
|
||||
const [nAddress, setNAddress] = useState(null);
|
||||
const [nsec, setNsec] = useState(null);
|
||||
const [npub, setNpub] = useState(null);
|
||||
const { zaps, zapsLoading, zapsError } = useZapsQuery({
|
||||
event: lesson,
|
||||
type: "lesson",
|
||||
type: 'lesson',
|
||||
});
|
||||
const { returnImageProxy } = useImageProxy();
|
||||
const menuRef = useRef(null);
|
||||
@ -41,46 +35,42 @@ const CourseLesson = ({
|
||||
const isMobileView = windowWidth <= 768;
|
||||
const { data: session } = useSession();
|
||||
|
||||
const readTime = lesson?.content
|
||||
? Math.max(30, Math.ceil(lesson.content.length / 20))
|
||||
: 60;
|
||||
const readTime = lesson?.content ? Math.max(30, Math.ceil(lesson.content.length / 20)) : 60;
|
||||
|
||||
const { isCompleted, isTracking, markLessonAsCompleted } =
|
||||
useTrackDocumentLesson({
|
||||
lessonId: lesson?.d,
|
||||
courseId: course?.d,
|
||||
readTime,
|
||||
paidCourse: isPaid,
|
||||
decryptionPerformed,
|
||||
});
|
||||
const { isCompleted, isTracking, markLessonAsCompleted } = useTrackDocumentLesson({
|
||||
lessonId: lesson?.d,
|
||||
courseId: course?.d,
|
||||
readTime,
|
||||
paidCourse: isPaid,
|
||||
decryptionPerformed,
|
||||
});
|
||||
|
||||
const buildMenuItems = () => {
|
||||
const items = [];
|
||||
|
||||
const hasAccess =
|
||||
session?.user &&
|
||||
(!isPaid || decryptionPerformed || session.user.role?.subscribed);
|
||||
session?.user && (!isPaid || decryptionPerformed || session.user.role?.subscribed);
|
||||
|
||||
if (hasAccess) {
|
||||
items.push({
|
||||
label: "Mark as completed",
|
||||
icon: "pi pi-check-circle",
|
||||
label: 'Mark as completed',
|
||||
icon: 'pi pi-check-circle',
|
||||
command: async () => {
|
||||
try {
|
||||
await markLessonAsCompleted();
|
||||
setCompleted && setCompleted(lesson.id);
|
||||
toastRef.current.show({
|
||||
severity: "success",
|
||||
summary: "Success",
|
||||
detail: "Lesson marked as completed",
|
||||
severity: 'success',
|
||||
summary: 'Success',
|
||||
detail: 'Lesson marked as completed',
|
||||
life: 3000,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to mark lesson as completed:", error);
|
||||
console.error('Failed to mark lesson as completed:', error);
|
||||
toastRef.current.show({
|
||||
severity: "error",
|
||||
summary: "Error",
|
||||
detail: "Failed to mark lesson as completed",
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to mark lesson as completed',
|
||||
life: 3000,
|
||||
});
|
||||
}
|
||||
@ -89,16 +79,16 @@ const CourseLesson = ({
|
||||
}
|
||||
|
||||
items.push({
|
||||
label: "Open lesson",
|
||||
icon: "pi pi-arrow-up-right",
|
||||
label: 'Open lesson',
|
||||
icon: 'pi pi-arrow-up-right',
|
||||
command: () => {
|
||||
window.open(`/details/${lesson.id}`, "_blank");
|
||||
window.open(`/details/${lesson.id}`, '_blank');
|
||||
},
|
||||
});
|
||||
|
||||
items.push({
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
if (lesson?.d) {
|
||||
const addr = nip19.naddrEncode({
|
||||
@ -107,7 +97,7 @@ const CourseLesson = ({
|
||||
identifier: lesson.d,
|
||||
relays: appConfig.defaultRelayUrls || [],
|
||||
});
|
||||
window.open(`https://habla.news/a/${addr}`, "_blank");
|
||||
window.open(`https://habla.news/a/${addr}`, '_blank');
|
||||
}
|
||||
},
|
||||
});
|
||||
@ -131,7 +121,7 @@ const CourseLesson = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, "hex");
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
@ -152,9 +142,7 @@ const CourseLesson = ({
|
||||
|
||||
const renderContent = () => {
|
||||
if (isPaid && decryptionPerformed) {
|
||||
return (
|
||||
<MDDisplay className="p-4 rounded-lg w-full" source={lesson.content} />
|
||||
);
|
||||
return <MDDisplay className="p-4 rounded-lg w-full" source={lesson.content} />;
|
||||
}
|
||||
if (isPaid && !decryptionPerformed) {
|
||||
return (
|
||||
@ -164,9 +152,7 @@ const CourseLesson = ({
|
||||
);
|
||||
}
|
||||
if (lesson?.content) {
|
||||
return (
|
||||
<MDDisplay className="p-4 rounded-lg w-full" source={lesson.content} />
|
||||
);
|
||||
return <MDDisplay className="p-4 rounded-lg w-full" source={lesson.content} />;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@ -179,28 +165,20 @@ const CourseLesson = ({
|
||||
<div className="flex flex-col items-start max-w-[45vw] max-tab:max-w-[100vw] max-mob:max-w-[100vw]">
|
||||
<div className="flex flex-row items-center justify-between w-full">
|
||||
<h1 className="text-4xl">{lesson?.title}</h1>
|
||||
<ZapDisplay
|
||||
zapAmount={zapAmount}
|
||||
event={lesson}
|
||||
zapsLoading={zapsLoading}
|
||||
/>
|
||||
<ZapDisplay zapAmount={zapAmount} event={lesson} zapsLoading={zapsLoading} />
|
||||
</div>
|
||||
<div className="pt-2 flex flex-row justify-start w-full mt-2 mb-4">
|
||||
{lesson &&
|
||||
lesson.topics &&
|
||||
lesson.topics.length > 0 &&
|
||||
lesson.topics.map((topic, index) => (
|
||||
<Tag
|
||||
className="mr-2 text-white"
|
||||
key={index}
|
||||
value={topic}
|
||||
></Tag>
|
||||
<Tag className="mr-2 text-white" key={index} value={topic}></Tag>
|
||||
))}
|
||||
</div>
|
||||
<div className="text-xl mt-6">
|
||||
{lesson?.summary && (
|
||||
<div className="text-xl mt-4">
|
||||
{lesson.summary.split("\n").map((line, index) => (
|
||||
{lesson.summary.split('\n').map((line, index) => (
|
||||
<p key={index}>{line}</p>
|
||||
))}
|
||||
</div>
|
||||
@ -210,16 +188,13 @@ const CourseLesson = ({
|
||||
<div className="flex flex-row w-fit items-center">
|
||||
<Image
|
||||
alt="avatar thumbnail"
|
||||
src={returnImageProxy(
|
||||
lesson.author?.avatar,
|
||||
lesson.author?.pubkey
|
||||
)}
|
||||
src={returnImageProxy(lesson.author?.avatar, lesson.author?.pubkey)}
|
||||
width={50}
|
||||
height={50}
|
||||
className="rounded-full mr-4"
|
||||
/>
|
||||
<p className="text-lg">
|
||||
Created by{" "}
|
||||
Created by{' '}
|
||||
<a
|
||||
rel="noreferrer noopener"
|
||||
target="_blank"
|
||||
@ -256,26 +231,25 @@ const CourseLesson = ({
|
||||
<div className="w-[75vw] mx-auto mt-12 p-12 border-t-2 border-gray-300 max-tab:p-0 max-mob:p-0 max-tab:max-w-[100vw] max-mob:max-w-[100vw]">
|
||||
{renderContent()}
|
||||
</div>
|
||||
{nAddress !== null &&
|
||||
(!isPaid || decryptionPerformed || session?.user?.role?.subscribed) && (
|
||||
<div className="px-4">
|
||||
{nsec || npub ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={nsec || npub || null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
disable="zaps"
|
||||
/>
|
||||
) : (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={npub}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
disable="zaps"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{nAddress !== null && (!isPaid || decryptionPerformed || session?.user?.role?.subscribed) && (
|
||||
<div className="px-4">
|
||||
{nsec || npub ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={nsec || npub || null}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
/>
|
||||
) : (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={npub}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
@ -1,25 +1,25 @@
|
||||
import React, { useEffect, useState, useRef } from "react";
|
||||
import axios from "axios";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { Tag } from "primereact/tag";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/router";
|
||||
import ResourcePaymentButton from "@/components/bitcoinConnect/ResourcePaymentButton";
|
||||
import ZapDisplay from "@/components/zaps/ZapDisplay";
|
||||
import GenericButton from "@/components/buttons/GenericButton";
|
||||
import { useImageProxy } from "@/hooks/useImageProxy";
|
||||
import { useZapsSubscription } from "@/hooks/nostrQueries/zaps/useZapsSubscription";
|
||||
import { getTotalFromZaps } from "@/utils/lightning";
|
||||
import { useSession } from "next-auth/react";
|
||||
import useWindowWidth from "@/hooks/useWindowWidth";
|
||||
import dynamic from "next/dynamic";
|
||||
import { Toast } from "primereact/toast";
|
||||
import MoreOptionsMenu from "@/components/ui/MoreOptionsMenu";
|
||||
import ZapThreadsWrapper from "@/components/ZapThreadsWrapper";
|
||||
import appConfig from "@/config/appConfig";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import axios from 'axios';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/router';
|
||||
import ResourcePaymentButton from '@/components/bitcoinConnect/ResourcePaymentButton';
|
||||
import ZapDisplay from '@/components/zaps/ZapDisplay';
|
||||
import GenericButton from '@/components/buttons/GenericButton';
|
||||
import { useImageProxy } from '@/hooks/useImageProxy';
|
||||
import { useZapsSubscription } from '@/hooks/nostrQueries/zaps/useZapsSubscription';
|
||||
import { getTotalFromZaps } from '@/utils/lightning';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import useWindowWidth from '@/hooks/useWindowWidth';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import MoreOptionsMenu from '@/components/ui/MoreOptionsMenu';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
import appConfig from '@/config/appConfig';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
const MDDisplay = dynamic(() => import("@uiw/react-markdown-preview"), {
|
||||
const MDDisplay = dynamic(() => import('@uiw/react-markdown-preview'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
@ -59,71 +59,63 @@ const DocumentDetails = ({
|
||||
try {
|
||||
const response = await axios.delete(`/api/resources/${processedEvent.d}`);
|
||||
if (response.status === 204) {
|
||||
showToast("success", "Success", "Resource deleted successfully.");
|
||||
router.push("/");
|
||||
showToast('success', 'Success', 'Resource deleted successfully.');
|
||||
router.push('/');
|
||||
}
|
||||
} catch (error) {
|
||||
if (
|
||||
error.response &&
|
||||
error.response.data &&
|
||||
error.response.data.error.includes("Invalid `prisma.resource.delete()`")
|
||||
error.response.data.error.includes('Invalid `prisma.resource.delete()`')
|
||||
) {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Resource cannot be deleted because it is part of a course, delete the course first."
|
||||
'error',
|
||||
'Error',
|
||||
'Resource cannot be deleted because it is part of a course, delete the course first.'
|
||||
);
|
||||
} else if (
|
||||
error.response &&
|
||||
error.response.data &&
|
||||
error.response.data.error
|
||||
) {
|
||||
showToast("error", "Error", error.response.data.error);
|
||||
} else if (error.response && error.response.data && error.response.data.error) {
|
||||
showToast('error', 'Error', error.response.data.error);
|
||||
} else {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Failed to delete resource. Please try again."
|
||||
);
|
||||
showToast('error', 'Error', 'Failed to delete resource. Please try again.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const authorMenuItems = [
|
||||
{
|
||||
label: "Edit",
|
||||
icon: "pi pi-pencil",
|
||||
label: 'Edit',
|
||||
icon: 'pi pi-pencil',
|
||||
command: () => router.push(`/details/${processedEvent.id}/edit`),
|
||||
},
|
||||
{
|
||||
label: "Delete",
|
||||
icon: "pi pi-trash",
|
||||
label: 'Delete',
|
||||
icon: 'pi pi-trash',
|
||||
command: handleDelete,
|
||||
},
|
||||
{
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
window.open(`https://habla.news/a/${nAddress}`, "_blank");
|
||||
window.open(`https://habla.news/a/${nAddress}`, '_blank');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const userMenuItems = [
|
||||
{
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
window.open(`https://habla.news/a/${nAddress}`, "_blank");
|
||||
window.open(`https://habla.news/a/${nAddress}`, '_blank');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (course) {
|
||||
userMenuItems.unshift({
|
||||
label: isMobileView ? "Course" : "Open Course",
|
||||
icon: "pi pi-external-link",
|
||||
command: () => window.open(`/course/${course}`, "_blank"),
|
||||
label: isMobileView ? 'Course' : 'Open Course',
|
||||
icon: 'pi pi-external-link',
|
||||
command: () => window.open(`/course/${course}`, '_blank'),
|
||||
});
|
||||
}
|
||||
|
||||
@ -138,20 +130,20 @@ const DocumentDetails = ({
|
||||
if (isLesson) {
|
||||
axios
|
||||
.get(`/api/resources/${processedEvent.d}`)
|
||||
.then((res) => {
|
||||
.then(res => {
|
||||
if (res.data && res.data.lessons[0]?.courseId) {
|
||||
setCourse(res.data.lessons[0]?.courseId);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("err", err);
|
||||
.catch(err => {
|
||||
console.error('err', err);
|
||||
});
|
||||
}
|
||||
}, [processedEvent.d, isLesson]);
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, "hex");
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
@ -162,7 +154,7 @@ const DocumentDetails = ({
|
||||
if (session?.user && session.user?.role?.subscribed && decryptedContent) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You are subscribed so you can access all paid content`}
|
||||
icon="pi pi-check"
|
||||
label="Subscribed"
|
||||
@ -178,15 +170,13 @@ const DocumentDetails = ({
|
||||
if (
|
||||
isLesson &&
|
||||
course &&
|
||||
session?.user?.purchased?.some((purchase) => purchase.courseId === course)
|
||||
session?.user?.purchased?.some(purchase => purchase.courseId === course)
|
||||
) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You have this lesson through purchasing the course it belongs to. You paid ${
|
||||
session?.user?.purchased?.find(
|
||||
(purchase) => purchase.courseId === course
|
||||
)?.course?.price
|
||||
session?.user?.purchased?.find(purchase => purchase.courseId === course)?.course?.price
|
||||
} sats for the course.`}
|
||||
icon="pi pi-check"
|
||||
label={`Paid`}
|
||||
@ -213,20 +203,16 @@ const DocumentDetails = ({
|
||||
outlined
|
||||
size="small"
|
||||
tooltip={`You paid ${processedEvent.price} sats to access this content (or potentially less if a discount was applied)`}
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
className="cursor-default hover:opacity-100 hover:bg-transparent focus:ring-0"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
paidResource &&
|
||||
author &&
|
||||
processedEvent?.pubkey === session?.user?.pubkey
|
||||
) {
|
||||
if (paidResource && author && processedEvent?.pubkey === session?.user?.pubkey) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You created this paid content, users must pay ${processedEvent.price} sats to access it`}
|
||||
icon="pi pi-check"
|
||||
label={`Price ${processedEvent.price} sats`}
|
||||
@ -243,12 +229,7 @@ const DocumentDetails = ({
|
||||
|
||||
const renderContent = () => {
|
||||
if (decryptedContent) {
|
||||
return (
|
||||
<MDDisplay
|
||||
className="p-2 rounded-lg w-full"
|
||||
source={decryptedContent}
|
||||
/>
|
||||
);
|
||||
return <MDDisplay className="p-2 rounded-lg w-full" source={decryptedContent} />;
|
||||
}
|
||||
if (paidResource && !decryptedContent) {
|
||||
return (
|
||||
@ -274,12 +255,7 @@ const DocumentDetails = ({
|
||||
);
|
||||
}
|
||||
if (processedEvent?.content) {
|
||||
return (
|
||||
<MDDisplay
|
||||
className="p-4 rounded-lg w-full"
|
||||
source={processedEvent.content}
|
||||
/>
|
||||
);
|
||||
return <MDDisplay className="p-4 rounded-lg w-full" source={processedEvent.content} />;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@ -312,11 +288,9 @@ const DocumentDetails = ({
|
||||
topics.map((topic, index) => (
|
||||
<Tag className="text-[#f8f8ff]" key={index} value={topic}></Tag>
|
||||
))}
|
||||
{isLesson && (
|
||||
<Tag size="small" className="text-[#f8f8ff]" value="lesson" />
|
||||
)}
|
||||
{isLesson && <Tag size="small" className="text-[#f8f8ff]" value="lesson" />}
|
||||
</div>
|
||||
{summary?.split("\n").map((line, index) => (
|
||||
{summary?.split('\n').map((line, index) => (
|
||||
<p key={index}>{line}</p>
|
||||
))}
|
||||
<div className="flex items-center justify-between mt-8">
|
||||
@ -329,7 +303,7 @@ const DocumentDetails = ({
|
||||
className="rounded-full mr-4"
|
||||
/>
|
||||
<p className="text-lg text-white">
|
||||
By{" "}
|
||||
By{' '}
|
||||
<a
|
||||
rel="noreferrer noopener"
|
||||
target="_blank"
|
||||
@ -350,21 +324,19 @@ const DocumentDetails = ({
|
||||
<div className="w-full mt-4">{renderPaymentMessage()}</div>
|
||||
{nAddress && (
|
||||
<div className="mt-8">
|
||||
{!paidResource ||
|
||||
decryptedContent ||
|
||||
session?.user?.role?.subscribed ? (
|
||||
{!paidResource || decryptedContent || session?.user?.role?.subscribed ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={session?.user ? nsec || npub : null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
isAuthorized={true}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center p-4 bg-gray-800/50 rounded-lg">
|
||||
<p className="text-gray-400">
|
||||
Comments are only available to content purchasers,
|
||||
subscribers, and the content creator.
|
||||
Comments are only available to content purchasers, subscribers, and the content
|
||||
creator.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
@ -1,25 +1,25 @@
|
||||
import React, { useEffect, useState, useRef } from "react";
|
||||
import axios from "axios";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { Tag } from "primereact/tag";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/router";
|
||||
import ResourcePaymentButton from "@/components/bitcoinConnect/ResourcePaymentButton";
|
||||
import ZapDisplay from "@/components/zaps/ZapDisplay";
|
||||
import GenericButton from "@/components/buttons/GenericButton";
|
||||
import { useImageProxy } from "@/hooks/useImageProxy";
|
||||
import { useZapsSubscription } from "@/hooks/nostrQueries/zaps/useZapsSubscription";
|
||||
import { getTotalFromZaps } from "@/utils/lightning";
|
||||
import { useSession } from "next-auth/react";
|
||||
import useWindowWidth from "@/hooks/useWindowWidth";
|
||||
import dynamic from "next/dynamic";
|
||||
import { Toast } from "primereact/toast";
|
||||
import MoreOptionsMenu from "@/components/ui/MoreOptionsMenu";
|
||||
import ZapThreadsWrapper from "@/components/ZapThreadsWrapper";
|
||||
import appConfig from "@/config/appConfig";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import React, { useEffect, useState, useRef } from 'react';
|
||||
import axios from 'axios';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/router';
|
||||
import ResourcePaymentButton from '@/components/bitcoinConnect/ResourcePaymentButton';
|
||||
import ZapDisplay from '@/components/zaps/ZapDisplay';
|
||||
import GenericButton from '@/components/buttons/GenericButton';
|
||||
import { useImageProxy } from '@/hooks/useImageProxy';
|
||||
import { useZapsSubscription } from '@/hooks/nostrQueries/zaps/useZapsSubscription';
|
||||
import { getTotalFromZaps } from '@/utils/lightning';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import useWindowWidth from '@/hooks/useWindowWidth';
|
||||
import dynamic from 'next/dynamic';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import MoreOptionsMenu from '@/components/ui/MoreOptionsMenu';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
import appConfig from '@/config/appConfig';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
const MDDisplay = dynamic(() => import("@uiw/react-markdown-preview"), {
|
||||
const MDDisplay = dynamic(() => import('@uiw/react-markdown-preview'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
@ -59,71 +59,63 @@ const VideoDetails = ({
|
||||
try {
|
||||
const response = await axios.delete(`/api/resources/${processedEvent.d}`);
|
||||
if (response.status === 204) {
|
||||
showToast("success", "Success", "Resource deleted successfully.");
|
||||
router.push("/");
|
||||
showToast('success', 'Success', 'Resource deleted successfully.');
|
||||
router.push('/');
|
||||
}
|
||||
} catch (error) {
|
||||
if (
|
||||
error.response &&
|
||||
error.response.data &&
|
||||
error.response.data.error.includes("Invalid `prisma.resource.delete()`")
|
||||
error.response.data.error.includes('Invalid `prisma.resource.delete()`')
|
||||
) {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Resource cannot be deleted because it is part of a course, delete the course first."
|
||||
'error',
|
||||
'Error',
|
||||
'Resource cannot be deleted because it is part of a course, delete the course first.'
|
||||
);
|
||||
} else if (
|
||||
error.response &&
|
||||
error.response.data &&
|
||||
error.response.data.error
|
||||
) {
|
||||
showToast("error", "Error", error.response.data.error);
|
||||
} else if (error.response && error.response.data && error.response.data.error) {
|
||||
showToast('error', 'Error', error.response.data.error);
|
||||
} else {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Failed to delete resource. Please try again."
|
||||
);
|
||||
showToast('error', 'Error', 'Failed to delete resource. Please try again.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const authorMenuItems = [
|
||||
{
|
||||
label: "Edit",
|
||||
icon: "pi pi-pencil",
|
||||
label: 'Edit',
|
||||
icon: 'pi pi-pencil',
|
||||
command: () => router.push(`/details/${processedEvent.id}/edit`),
|
||||
},
|
||||
{
|
||||
label: "Delete",
|
||||
icon: "pi pi-trash",
|
||||
label: 'Delete',
|
||||
icon: 'pi pi-trash',
|
||||
command: handleDelete,
|
||||
},
|
||||
{
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
window.open(`https://habla.news/a/${nAddress}`, "_blank");
|
||||
window.open(`https://habla.news/a/${nAddress}`, '_blank');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const userMenuItems = [
|
||||
{
|
||||
label: "View Nostr note",
|
||||
icon: "pi pi-globe",
|
||||
label: 'View Nostr note',
|
||||
icon: 'pi pi-globe',
|
||||
command: () => {
|
||||
window.open(`https://habla.news/a/${nAddress}`, "_blank");
|
||||
window.open(`https://habla.news/a/${nAddress}`, '_blank');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (course) {
|
||||
userMenuItems.unshift({
|
||||
label: isMobileView ? "Course" : "Open Course",
|
||||
icon: "pi pi-external-link",
|
||||
command: () => window.open(`/course/${course}`, "_blank"),
|
||||
label: isMobileView ? 'Course' : 'Open Course',
|
||||
icon: 'pi pi-external-link',
|
||||
command: () => window.open(`/course/${course}`, '_blank'),
|
||||
});
|
||||
}
|
||||
|
||||
@ -131,13 +123,13 @@ const VideoDetails = ({
|
||||
if (isLesson) {
|
||||
axios
|
||||
.get(`/api/resources/${processedEvent.d}`)
|
||||
.then((res) => {
|
||||
.then(res => {
|
||||
if (res.data && res.data.lessons[0]?.courseId) {
|
||||
setCourse(res.data.lessons[0]?.courseId);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("err", err);
|
||||
.catch(err => {
|
||||
console.error('err', err);
|
||||
});
|
||||
}
|
||||
}, [processedEvent.d, isLesson]);
|
||||
@ -151,7 +143,7 @@ const VideoDetails = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, "hex");
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
@ -162,7 +154,7 @@ const VideoDetails = ({
|
||||
if (session?.user && session.user?.role?.subscribed && decryptedContent) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You are subscribed so you can access all paid content`}
|
||||
icon="pi pi-check"
|
||||
label="Subscribed"
|
||||
@ -177,21 +169,17 @@ const VideoDetails = ({
|
||||
if (
|
||||
isLesson &&
|
||||
course &&
|
||||
session?.user?.purchased?.some((purchase) => purchase.courseId === course)
|
||||
session?.user?.purchased?.some(purchase => purchase.courseId === course)
|
||||
) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You have this lesson through purchasing the course it belongs to. You paid ${
|
||||
session?.user?.purchased?.find(
|
||||
(purchase) => purchase.courseId === course
|
||||
)?.course?.price
|
||||
session?.user?.purchased?.find(purchase => purchase.courseId === course)?.course?.price
|
||||
} sats for the course.`}
|
||||
icon="pi pi-check"
|
||||
label={`Paid ${
|
||||
session?.user?.purchased?.find(
|
||||
(purchase) => purchase.courseId === course
|
||||
)?.course?.price
|
||||
session?.user?.purchased?.find(purchase => purchase.courseId === course)?.course?.price
|
||||
} sats`}
|
||||
severity="success"
|
||||
outlined
|
||||
@ -220,14 +208,10 @@ const VideoDetails = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
paidResource &&
|
||||
author &&
|
||||
processedEvent?.pubkey === session?.user?.pubkey
|
||||
) {
|
||||
if (paidResource && author && processedEvent?.pubkey === session?.user?.pubkey) {
|
||||
return (
|
||||
<GenericButton
|
||||
tooltipOptions={{ position: "top" }}
|
||||
tooltipOptions={{ position: 'top' }}
|
||||
tooltip={`You created this paid content, users must pay ${processedEvent.price} sats to access it`}
|
||||
icon="pi pi-check"
|
||||
label={`Price ${processedEvent.price} sats`}
|
||||
@ -244,12 +228,7 @@ const VideoDetails = ({
|
||||
|
||||
const renderContent = () => {
|
||||
if (decryptedContent) {
|
||||
return (
|
||||
<MDDisplay
|
||||
className="p-0 rounded-lg w-full"
|
||||
source={decryptedContent}
|
||||
/>
|
||||
);
|
||||
return <MDDisplay className="p-0 rounded-lg w-full" source={decryptedContent} />;
|
||||
}
|
||||
if (paidResource && !decryptedContent) {
|
||||
return (
|
||||
@ -258,8 +237,8 @@ const VideoDetails = ({
|
||||
className="absolute inset-0 opacity-50"
|
||||
style={{
|
||||
backgroundImage: `url(${image})`,
|
||||
backgroundSize: "cover",
|
||||
backgroundPosition: "center",
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
}}
|
||||
></div>
|
||||
<div className="absolute inset-0 bg-black bg-opacity-50"></div>
|
||||
@ -282,12 +261,7 @@ const VideoDetails = ({
|
||||
);
|
||||
}
|
||||
if (processedEvent?.content) {
|
||||
return (
|
||||
<MDDisplay
|
||||
className="p-0 rounded-lg w-full"
|
||||
source={processedEvent.content}
|
||||
/>
|
||||
);
|
||||
return <MDDisplay className="p-0 rounded-lg w-full" source={processedEvent.content} />;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@ -297,9 +271,7 @@ const VideoDetails = ({
|
||||
<Toast ref={toastRef} />
|
||||
{renderContent()}
|
||||
<div className="bg-gray-800/90 rounded-lg p-4 m-4 max-mob:m-0 max-tab:m-0 max-mob:rounded-t-none max-tab:rounded-t-none">
|
||||
<div
|
||||
className={`w-full flex flex-col items-start justify-start mt-2 px-2`}
|
||||
>
|
||||
<div className={`w-full flex flex-col items-start justify-start mt-2 px-2`}>
|
||||
<div className="flex flex-col items-start gap-2 w-full">
|
||||
<div className="flex flex-row items-center justify-between gap-2 w-full">
|
||||
<h1 className="text-4xl flex-grow">{title}</h1>
|
||||
@ -313,18 +285,14 @@ const VideoDetails = ({
|
||||
{topics &&
|
||||
topics.length > 0 &&
|
||||
topics.map((topic, index) => (
|
||||
<Tag
|
||||
className="mt-2 text-white"
|
||||
key={index}
|
||||
value={topic}
|
||||
></Tag>
|
||||
<Tag className="mt-2 text-white" key={index} value={topic}></Tag>
|
||||
))}
|
||||
{isLesson && <Tag className="mt-2 text-white" value="lesson" />}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-row items-center justify-between w-full">
|
||||
<div className="my-4 max-mob:text-base max-tab:text-base">
|
||||
{summary?.split("\n").map((line, index) => (
|
||||
{summary?.split('\n').map((line, index) => (
|
||||
<p key={index}>{line}</p>
|
||||
))}
|
||||
</div>
|
||||
@ -339,7 +307,7 @@ const VideoDetails = ({
|
||||
className="rounded-full mr-4"
|
||||
/>
|
||||
<p className="text-lg text-white">
|
||||
By{" "}
|
||||
By{' '}
|
||||
<a
|
||||
rel="noreferrer noopener"
|
||||
target="_blank"
|
||||
@ -358,26 +326,22 @@ const VideoDetails = ({
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full flex justify-start mt-4">
|
||||
{renderPaymentMessage()}
|
||||
</div>
|
||||
<div className="w-full flex justify-start mt-4">{renderPaymentMessage()}</div>
|
||||
{nAddress && (
|
||||
<div className="mt-8">
|
||||
{!paidResource ||
|
||||
decryptedContent ||
|
||||
session?.user?.role?.subscribed ? (
|
||||
{!paidResource || decryptedContent || session?.user?.role?.subscribed ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddress}
|
||||
user={session?.user ? nsec || npub : null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
isAuthorized={true}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center p-4 bg-gray-800/50 rounded-lg">
|
||||
<p className="text-gray-400">
|
||||
Comments are only available to content purchasers,
|
||||
subscribers, and the content creator.
|
||||
Comments are only available to content purchasers, subscribers, and the content
|
||||
creator.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
@ -12,6 +12,7 @@ const appConfig = {
|
||||
authorPubkeys: [
|
||||
'f33c8a9617cb15f705fc70cd461cfd6eaf22f9e24c33eabad981648e5ec6f741',
|
||||
'c67cd3e1a83daa56cff16f635db2fdb9ed9619300298d4701a58e68e84098345',
|
||||
'b9f4c34dc25b2ddd785c007bf6e12619bb1c9b8335b8d75d37bf76e97d1a0e31',
|
||||
],
|
||||
customLightningAddresses: [
|
||||
{
|
||||
|
@ -81,10 +81,12 @@ export default async function handler(req, res) {
|
||||
},
|
||||
}
|
||||
);
|
||||
res.status(200).json({
|
||||
pr: response.data.invoice,
|
||||
verify: `${BACKEND_URL}/api/lightning-address/verify/${slug}/${response.data.payment_hash}`,
|
||||
});
|
||||
res
|
||||
.status(200)
|
||||
.json({
|
||||
pr: response.data.invoice,
|
||||
verify: `${BACKEND_URL}/api/lightning-address/verify/${slug}/${response.data.payment_hash}`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ error: 'Failed to generate invoice' });
|
||||
|
@ -1,24 +1,24 @@
|
||||
import React, { useEffect, useState, useCallback } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
import { parseCourseEvent, parseEvent, findKind0Fields } from "@/utils/nostr";
|
||||
import CourseDetails from "@/components/content/courses/CourseDetails";
|
||||
import VideoLesson from "@/components/content/courses/VideoLesson";
|
||||
import DocumentLesson from "@/components/content/courses/DocumentLesson";
|
||||
import CombinedLesson from "@/components/content/courses/CombinedLesson";
|
||||
import { useNDKContext } from "@/context/NDKContext";
|
||||
import { useSession } from "next-auth/react";
|
||||
import axios from "axios";
|
||||
import { nip04, nip19 } from "nostr-tools";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { ProgressSpinner } from "primereact/progressspinner";
|
||||
import { Accordion, AccordionTab } from "primereact/accordion";
|
||||
import { Tag } from "primereact/tag";
|
||||
import { useDecryptContent } from "@/hooks/encryption/useDecryptContent";
|
||||
import dynamic from "next/dynamic";
|
||||
import ZapThreadsWrapper from "@/components/ZapThreadsWrapper";
|
||||
import appConfig from "@/config/appConfig";
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { parseCourseEvent, parseEvent, findKind0Fields } from '@/utils/nostr';
|
||||
import CourseDetails from '@/components/content/courses/CourseDetails';
|
||||
import VideoLesson from '@/components/content/courses/VideoLesson';
|
||||
import DocumentLesson from '@/components/content/courses/DocumentLesson';
|
||||
import CombinedLesson from '@/components/content/courses/CombinedLesson';
|
||||
import { useNDKContext } from '@/context/NDKContext';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import axios from 'axios';
|
||||
import { nip04, nip19 } from 'nostr-tools';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { ProgressSpinner } from 'primereact/progressspinner';
|
||||
import { Accordion, AccordionTab } from 'primereact/accordion';
|
||||
import { Tag } from 'primereact/tag';
|
||||
import { useDecryptContent } from '@/hooks/encryption/useDecryptContent';
|
||||
import dynamic from 'next/dynamic';
|
||||
import ZapThreadsWrapper from '@/components/ZapThreadsWrapper';
|
||||
import appConfig from '@/config/appConfig';
|
||||
|
||||
const MDDisplay = dynamic(() => import("@uiw/react-markdown-preview"), {
|
||||
const MDDisplay = dynamic(() => import('@uiw/react-markdown-preview'), {
|
||||
ssr: false,
|
||||
});
|
||||
|
||||
@ -36,10 +36,10 @@ const useCourseData = (ndk, fetchAuthor, router) => {
|
||||
let id;
|
||||
|
||||
const fetchCourseId = async () => {
|
||||
if (slug.includes("naddr")) {
|
||||
if (slug.includes('naddr')) {
|
||||
const { data } = nip19.decode(slug);
|
||||
if (!data?.identifier) {
|
||||
showToast("error", "Error", "Resource not found");
|
||||
showToast('error', 'Error', 'Resource not found');
|
||||
return null;
|
||||
}
|
||||
return data.identifier;
|
||||
@ -48,21 +48,19 @@ const useCourseData = (ndk, fetchAuthor, router) => {
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCourse = async (courseId) => {
|
||||
const fetchCourse = async courseId => {
|
||||
try {
|
||||
await ndk.connect();
|
||||
const event = await ndk.fetchEvent({ "#d": [courseId] });
|
||||
const event = await ndk.fetchEvent({ '#d': [courseId] });
|
||||
if (!event) return null;
|
||||
|
||||
const author = await fetchAuthor(event.pubkey);
|
||||
const lessonIds = event.tags
|
||||
.filter((tag) => tag[0] === "a")
|
||||
.map((tag) => tag[1].split(":")[2]);
|
||||
const lessonIds = event.tags.filter(tag => tag[0] === 'a').map(tag => tag[1].split(':')[2]);
|
||||
|
||||
const parsedCourse = { ...parseCourseEvent(event), author };
|
||||
return { parsedCourse, lessonIds };
|
||||
} catch (error) {
|
||||
console.error("Error fetching event:", error);
|
||||
console.error('Error fetching event:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@ -97,11 +95,11 @@ const useLessons = (ndk, fetchAuthor, lessonIds, pubkey) => {
|
||||
const { showToast } = useToast();
|
||||
useEffect(() => {
|
||||
if (lessonIds.length > 0) {
|
||||
const fetchLesson = async (lessonId) => {
|
||||
const fetchLesson = async lessonId => {
|
||||
try {
|
||||
await ndk.connect();
|
||||
const filter = {
|
||||
"#d": [lessonId],
|
||||
'#d': [lessonId],
|
||||
kinds: [30023, 30402],
|
||||
authors: [pubkey],
|
||||
};
|
||||
@ -109,11 +107,9 @@ const useLessons = (ndk, fetchAuthor, lessonIds, pubkey) => {
|
||||
if (event) {
|
||||
const author = await fetchAuthor(event.pubkey);
|
||||
const parsedLesson = { ...parseEvent(event), author };
|
||||
setLessons((prev) => {
|
||||
setLessons(prev => {
|
||||
// Check if the lesson already exists in the array
|
||||
const exists = prev.some(
|
||||
(lesson) => lesson.id === parsedLesson.id
|
||||
);
|
||||
const exists = prev.some(lesson => lesson.id === parsedLesson.id);
|
||||
if (!exists) {
|
||||
return [...prev, parsedLesson];
|
||||
}
|
||||
@ -121,16 +117,16 @@ const useLessons = (ndk, fetchAuthor, lessonIds, pubkey) => {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching event:", error);
|
||||
console.error('Error fetching event:', error);
|
||||
}
|
||||
};
|
||||
lessonIds.forEach((lessonId) => fetchLesson(lessonId));
|
||||
lessonIds.forEach(lessonId => fetchLesson(lessonId));
|
||||
}
|
||||
}, [lessonIds, ndk, fetchAuthor, pubkey]);
|
||||
|
||||
useEffect(() => {
|
||||
const newUniqueLessons = Array.from(
|
||||
new Map(lessons.map((lesson) => [lesson.id, lesson])).values()
|
||||
new Map(lessons.map(lesson => [lesson.id, lesson])).values()
|
||||
);
|
||||
setUniqueLessons(newUniqueLessons);
|
||||
}, [lessons]);
|
||||
@ -148,16 +144,14 @@ const useDecryption = (session, paidCourse, course, lessons, setLessons) => {
|
||||
if (session?.user && paidCourse && !decryptionPerformed) {
|
||||
setLoading(true);
|
||||
const canAccess =
|
||||
session.user.purchased?.some(
|
||||
(purchase) => purchase.courseId === course?.d
|
||||
) ||
|
||||
session.user.purchased?.some(purchase => purchase.courseId === course?.d) ||
|
||||
session.user?.role?.subscribed ||
|
||||
session.user?.pubkey === course?.pubkey;
|
||||
|
||||
if (canAccess && lessons.length > 0) {
|
||||
try {
|
||||
const decryptedLessons = await Promise.all(
|
||||
lessons.map(async (lesson) => {
|
||||
lessons.map(async lesson => {
|
||||
const decryptedContent = await decryptContent(lesson.content);
|
||||
return { ...lesson, content: decryptedContent };
|
||||
})
|
||||
@ -165,7 +159,7 @@ const useDecryption = (session, paidCourse, course, lessons, setLessons) => {
|
||||
setLessons(decryptedLessons);
|
||||
setDecryptionPerformed(true);
|
||||
} catch (error) {
|
||||
console.error("Error decrypting lessons:", error);
|
||||
console.error('Error decrypting lessons:', error);
|
||||
}
|
||||
}
|
||||
setLoading(false);
|
||||
@ -189,12 +183,12 @@ const Course = () => {
|
||||
const [nsec, setNsec] = useState(null);
|
||||
const [npub, setNpub] = useState(null);
|
||||
|
||||
const setCompleted = useCallback((lessonId) => {
|
||||
setCompletedLessons((prev) => [...prev, lessonId]);
|
||||
const setCompleted = useCallback(lessonId => {
|
||||
setCompletedLessons(prev => [...prev, lessonId]);
|
||||
}, []);
|
||||
|
||||
const fetchAuthor = useCallback(
|
||||
async (pubkey) => {
|
||||
async pubkey => {
|
||||
const author = await ndk.getUser({ pubkey });
|
||||
const profile = await author.fetchProfile();
|
||||
const fields = await findKind0Fields(profile);
|
||||
@ -237,7 +231,7 @@ const Course = () => {
|
||||
useEffect(() => {
|
||||
if (uniqueLessons.length > 0) {
|
||||
const addresses = {};
|
||||
uniqueLessons.forEach((lesson) => {
|
||||
uniqueLessons.forEach(lesson => {
|
||||
const addr = nip19.naddrEncode({
|
||||
pubkey: lesson.pubkey,
|
||||
kind: lesson.kind,
|
||||
@ -252,49 +246,37 @@ const Course = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (session?.user?.privkey) {
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, "hex");
|
||||
const privkeyBuffer = Buffer.from(session.user.privkey, 'hex');
|
||||
setNsec(nip19.nsecEncode(privkeyBuffer));
|
||||
} else if (session?.user?.pubkey) {
|
||||
setNpub(nip19.npubEncode(session.user.pubkey));
|
||||
}
|
||||
}, [session]);
|
||||
|
||||
const handleAccordionChange = (e) => {
|
||||
const handleAccordionChange = e => {
|
||||
const newIndex = e.index === expandedIndex ? null : e.index;
|
||||
setExpandedIndex(newIndex);
|
||||
|
||||
if (newIndex !== null) {
|
||||
router.push(
|
||||
`/course/${router.query.slug}?active=${newIndex}`,
|
||||
undefined,
|
||||
{ shallow: true }
|
||||
);
|
||||
router.push(`/course/${router.query.slug}?active=${newIndex}`, undefined, { shallow: true });
|
||||
} else {
|
||||
router.push(`/course/${router.query.slug}`, undefined, { shallow: true });
|
||||
}
|
||||
};
|
||||
|
||||
const handlePaymentSuccess = async (response) => {
|
||||
const handlePaymentSuccess = async response => {
|
||||
if (response && response?.preimage) {
|
||||
const updated = await update();
|
||||
showToast(
|
||||
"success",
|
||||
"Payment Success",
|
||||
"You have successfully purchased this course"
|
||||
);
|
||||
showToast('success', 'Payment Success', 'You have successfully purchased this course');
|
||||
} else {
|
||||
showToast(
|
||||
"error",
|
||||
"Error",
|
||||
"Failed to purchase course. Please try again."
|
||||
);
|
||||
showToast('error', 'Error', 'Failed to purchase course. Please try again.');
|
||||
}
|
||||
};
|
||||
|
||||
const handlePaymentError = (error) => {
|
||||
const handlePaymentError = error => {
|
||||
showToast(
|
||||
"error",
|
||||
"Payment Error",
|
||||
'error',
|
||||
'Payment Error',
|
||||
`Failed to purchase course. Please try again. Error: ${error}`
|
||||
);
|
||||
};
|
||||
@ -307,11 +289,8 @@ const Course = () => {
|
||||
);
|
||||
}
|
||||
|
||||
const renderLesson = (lesson) => {
|
||||
if (
|
||||
lesson.topics?.includes("video") &&
|
||||
lesson.topics?.includes("document")
|
||||
) {
|
||||
const renderLesson = lesson => {
|
||||
if (lesson.topics?.includes('video') && lesson.topics?.includes('document')) {
|
||||
return (
|
||||
<CombinedLesson
|
||||
lesson={lesson}
|
||||
@ -321,10 +300,7 @@ const Course = () => {
|
||||
setCompleted={setCompleted}
|
||||
/>
|
||||
);
|
||||
} else if (
|
||||
lesson.type === "video" &&
|
||||
!lesson.topics?.includes("document")
|
||||
) {
|
||||
} else if (lesson.type === 'video' && !lesson.topics?.includes('document')) {
|
||||
return (
|
||||
<VideoLesson
|
||||
lesson={lesson}
|
||||
@ -334,10 +310,7 @@ const Course = () => {
|
||||
setCompleted={setCompleted}
|
||||
/>
|
||||
);
|
||||
} else if (
|
||||
lesson.type === "document" &&
|
||||
!lesson.topics?.includes("video")
|
||||
) {
|
||||
} else if (lesson.type === 'document' && !lesson.topics?.includes('video')) {
|
||||
return (
|
||||
<DocumentLesson
|
||||
lesson={lesson}
|
||||
@ -372,11 +345,11 @@ const Course = () => {
|
||||
<AccordionTab
|
||||
key={index}
|
||||
pt={{
|
||||
root: { className: "border-none" },
|
||||
header: { className: "border-none" },
|
||||
headerAction: { className: "border-none" },
|
||||
content: { className: "border-none max-mob:px-0 max-tab:px-0" },
|
||||
accordiontab: { className: "border-none" },
|
||||
root: { className: 'border-none' },
|
||||
header: { className: 'border-none' },
|
||||
headerAction: { className: 'border-none' },
|
||||
content: { className: 'border-none max-mob:px-0 max-tab:px-0' },
|
||||
accordiontab: { className: 'border-none' },
|
||||
}}
|
||||
header={
|
||||
<div className="flex align-items-center justify-between w-full">
|
||||
@ -394,21 +367,19 @@ const Course = () => {
|
||||
{renderLesson(lesson)}
|
||||
{nAddresses[lesson.id] && (
|
||||
<div className="mt-8">
|
||||
{!paidCourse ||
|
||||
decryptionPerformed ||
|
||||
session?.user?.role?.subscribed ? (
|
||||
{!paidCourse || decryptionPerformed || session?.user?.role?.subscribed ? (
|
||||
<ZapThreadsWrapper
|
||||
anchor={nAddresses[lesson.id]}
|
||||
user={session?.user ? nsec || npub : null}
|
||||
relays={appConfig.defaultRelayUrls.join(",")}
|
||||
relays={appConfig.defaultRelayUrls.join(',')}
|
||||
disable="zaps"
|
||||
isAuthorized={true}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-center p-4 bg-gray-800/50 rounded-lg">
|
||||
<p className="text-gray-400">
|
||||
Comments are only available to course purchasers,
|
||||
subscribers, and the course creator.
|
||||
Comments are only available to course purchasers, subscribers, and the
|
||||
course creator.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
@ -419,9 +390,7 @@ const Course = () => {
|
||||
))}
|
||||
</Accordion>
|
||||
<div className="mx-auto my-6">
|
||||
{course?.content && (
|
||||
<MDDisplay className="p-4 rounded-lg" source={course.content} />
|
||||
)}
|
||||
{course?.content && <MDDisplay className="p-4 rounded-lg" source={course.content} />}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user