mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
fix for memory leak
This commit is contained in:
parent
ccda05df96
commit
403948f7b2
@ -93,6 +93,7 @@ const useCourseDecryption = (session, paidCourse, course, lessons, setLessons, r
|
|||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
decryptTimeoutRef.current = null;
|
decryptTimeoutRef.current = null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
// If timeout or network error, schedule a retry
|
// If timeout or network error, schedule a retry
|
||||||
retryTimeoutRef.current = setTimeout(() => {
|
retryTimeoutRef.current = setTimeout(() => {
|
||||||
processingRef.current = false;
|
processingRef.current = false;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState, useCallback } from 'react';
|
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { findKind0Fields } from '@/utils/nostr';
|
import { findKind0Fields } from '@/utils/nostr';
|
||||||
import { useNDKContext } from '@/context/NDKContext';
|
import { useNDKContext } from '@/context/NDKContext';
|
||||||
@ -35,7 +35,6 @@ const Course = () => {
|
|||||||
const [nsec, setNsec] = useState(null);
|
const [nsec, setNsec] = useState(null);
|
||||||
const [npub, setNpub] = useState(null);
|
const [npub, setNpub] = useState(null);
|
||||||
const [nAddress, setNAddress] = useState(null);
|
const [nAddress, setNAddress] = useState(null);
|
||||||
const [isDecrypting, setIsDecrypting] = useState(false);
|
|
||||||
const windowWidth = useWindowWidth();
|
const windowWidth = useWindowWidth();
|
||||||
const isMobileView = windowWidth <= 968;
|
const isMobileView = windowWidth <= 968;
|
||||||
const navbarHeight = 60; // Match the height from Navbar component
|
const navbarHeight = 60; // Match the height from Navbar component
|
||||||
@ -140,18 +139,12 @@ const Course = () => {
|
|||||||
activeIndex
|
activeIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
// Replace useState + useEffect with useMemo for derived state
|
||||||
if (paidCourse && uniqueLessons.length > 0) {
|
const isDecrypting = useMemo(() => {
|
||||||
const currentLesson = uniqueLessons[activeIndex];
|
if (!paidCourse || uniqueLessons.length === 0) return false;
|
||||||
if (currentLesson && !decryptedLessonIds[currentLesson.id]) {
|
const current = uniqueLessons[activeIndex];
|
||||||
setIsDecrypting(true);
|
return current && !decryptedLessonIds[current.id];
|
||||||
} else {
|
}, [paidCourse, uniqueLessons, activeIndex, decryptedLessonIds]);
|
||||||
setIsDecrypting(false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setIsDecrypting(false);
|
|
||||||
}
|
|
||||||
}, [activeIndex, uniqueLessons, decryptedLessonIds, paidCourse]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (uniqueLessons.length > 0) {
|
if (uniqueLessons.length > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user