mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
Fix infinite loop lmao
This commit is contained in:
parent
67b7905e66
commit
23d30fa351
@ -30,15 +30,21 @@ const Details = () => {
|
||||
const { showToast } = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
axios.get('/api/lessons').then(res => {
|
||||
if (res.data) {
|
||||
res.data.forEach(lesson => {
|
||||
setLessons(prev => [...prev, { resourceId: lesson?.resourceId, courseId: lesson?.courseId || null }]);
|
||||
});
|
||||
const fetchLessons = async () => {
|
||||
try {
|
||||
const res = await axios.get('/api/lessons');
|
||||
if (res.data) {
|
||||
const lessonData = res.data.map(lesson => ({
|
||||
resourceId: lesson?.resourceId,
|
||||
courseId: lesson?.courseId || null
|
||||
}));
|
||||
setLessons(lessonData);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('err', err);
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('err', err);
|
||||
});
|
||||
};
|
||||
fetchLessons();
|
||||
}, []);
|
||||
|
||||
const fetchAuthor = useCallback(async (pubkey) => {
|
||||
@ -106,21 +112,7 @@ const Details = () => {
|
||||
const parsedEvent = parseEvent(event);
|
||||
setEvent(parsedEvent);
|
||||
await fetchAuthor(event.pubkey);
|
||||
|
||||
const isAuthor = session?.user?.pubkey === event.pubkey;
|
||||
setAuthorView(isAuthor);
|
||||
|
||||
if (parsedEvent.price || (isAuthor && event.kind === 30402)) {
|
||||
const shouldDecrypt = isAuthor ||
|
||||
session?.user?.role?.subscribed ||
|
||||
session?.user?.purchased?.some(purchase => purchase.resourceId === parsedEvent.d) ||
|
||||
lessons.some(lesson => lesson.resourceId === parsedEvent.d && session?.user?.purchased?.some(purchase => purchase.courseId === lesson.courseId));
|
||||
|
||||
if (shouldDecrypt) {
|
||||
const decrypted = await decryptContent(event.content);
|
||||
setDecryptedContent(decrypted);
|
||||
}
|
||||
}
|
||||
setAuthorView(session?.user?.pubkey === event.pubkey);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching event:', error);
|
||||
@ -131,7 +123,34 @@ const Details = () => {
|
||||
};
|
||||
|
||||
fetchAndProcessEvent();
|
||||
}, [router.isReady, router.query, ndk, session, decryptContent, fetchAuthor, showToast]);
|
||||
}, [router.isReady, router.query, ndk, session?.user?.pubkey, fetchAuthor, showToast]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleDecryption = async () => {
|
||||
if (!event || !session || !lessons.length) return;
|
||||
|
||||
const isAuthor = session?.user?.pubkey === event.pubkey;
|
||||
|
||||
if (event.price || (isAuthor && event.kind === 30402)) {
|
||||
const shouldDecrypt = isAuthor ||
|
||||
session?.user?.role?.subscribed ||
|
||||
session?.user?.purchased?.some(purchase => purchase.resourceId === event.d) ||
|
||||
lessons.some(lesson =>
|
||||
lesson.resourceId === event.d &&
|
||||
session?.user?.purchased?.some(purchase =>
|
||||
purchase.courseId === lesson.courseId
|
||||
)
|
||||
);
|
||||
|
||||
if (shouldDecrypt) {
|
||||
const decrypted = await decryptContent(event.content);
|
||||
setDecryptedContent(decrypted);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
handleDecryption();
|
||||
}, [event, session, lessons, decryptContent]);
|
||||
|
||||
const handlePaymentSuccess = (response) => {
|
||||
if (response && response?.preimage) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user