mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-06 18:31:00 +00:00
Fix infinite loop lmao
This commit is contained in:
parent
67b7905e66
commit
23d30fa351
@ -30,15 +30,21 @@ const Details = () => {
|
|||||||
const { showToast } = useToast();
|
const { showToast } = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
axios.get('/api/lessons').then(res => {
|
const fetchLessons = async () => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get('/api/lessons');
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
res.data.forEach(lesson => {
|
const lessonData = res.data.map(lesson => ({
|
||||||
setLessons(prev => [...prev, { resourceId: lesson?.resourceId, courseId: lesson?.courseId || null }]);
|
resourceId: lesson?.resourceId,
|
||||||
});
|
courseId: lesson?.courseId || null
|
||||||
|
}));
|
||||||
|
setLessons(lessonData);
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
} catch (err) {
|
||||||
console.error('err', err);
|
console.error('err', err);
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
fetchLessons();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchAuthor = useCallback(async (pubkey) => {
|
const fetchAuthor = useCallback(async (pubkey) => {
|
||||||
@ -106,21 +112,7 @@ const Details = () => {
|
|||||||
const parsedEvent = parseEvent(event);
|
const parsedEvent = parseEvent(event);
|
||||||
setEvent(parsedEvent);
|
setEvent(parsedEvent);
|
||||||
await fetchAuthor(event.pubkey);
|
await fetchAuthor(event.pubkey);
|
||||||
|
setAuthorView(session?.user?.pubkey === 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching event:', error);
|
console.error('Error fetching event:', error);
|
||||||
@ -131,7 +123,34 @@ const Details = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchAndProcessEvent();
|
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) => {
|
const handlePaymentSuccess = (response) => {
|
||||||
if (response && response?.preimage) {
|
if (response && response?.preimage) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user