-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
All 1.3.1 dev #249
All 1.3.1 dev #249
Changes from all commits
f324858
5a40064
a63217d
c660319
15b6002
ce83cc2
f29d6d3
3a2f7fe
06257e6
6731267
7fc647e
588a916
958c4ef
03895ff
5d738ca
4c4d63d
ecfc492
c0d07ce
f1958f4
b9648b7
01c71e8
afa7073
2126a0b
adcb97b
6398cdb
21a8e23
d65b3cd
f23c9a7
17240c5
7e0e930
64624c4
7795733
c1e540e
2db6ecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: ALL tn dev Deployment | |
on: | ||
push: | ||
branches: | ||
- all-1.2-tn-dev | ||
- all-1.3.1-dev | ||
|
||
jobs: | ||
deploy: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,27 +163,70 @@ const MainLayout = (props) => { | |
} | ||
}; | ||
|
||
const [audioCache, setAudioCache] = useState({}); | ||
|
||
useEffect(() => { | ||
const preloadAudio = async () => { | ||
try { | ||
const urls = [LevelCompleteAudio, gameLoseAudio]; | ||
const cache = {}; | ||
|
||
for (const url of urls) { | ||
const response = await fetch(url); | ||
const audioBlob = await response.blob(); | ||
const audioUrl = URL.createObjectURL(audioBlob); | ||
cache[url] = audioUrl; | ||
} | ||
|
||
setAudioCache(cache); | ||
} catch (error) { | ||
console.error("Error preloading audio:", error); | ||
} | ||
}; | ||
|
||
preloadAudio(); | ||
|
||
// Cleanup cached audio URLs on unmount | ||
return () => { | ||
Object.values(audioCache).forEach((audioUrl) => | ||
URL.revokeObjectURL(audioUrl) | ||
); | ||
}; | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (isShowCase && gameOverData) { | ||
setShake(gameOverData ? gameOverData.userWon : true); | ||
setShake(gameOverData.userWon ?? true); | ||
|
||
let audio = ""; | ||
let audioSrc; | ||
if (gameOverData) { | ||
audio = new Audio( | ||
gameOverData.userWon ? LevelCompleteAudio : gameLoseAudio | ||
); | ||
audioSrc = gameOverData.userWon | ||
? audioCache[LevelCompleteAudio] | ||
: audioCache[gameLoseAudio]; | ||
} else { | ||
audioSrc = audioCache[LevelCompleteAudio]; | ||
} | ||
|
||
if (audioSrc) { | ||
const audio = new Audio(audioSrc); | ||
audio.play().catch((error) => { | ||
console.error("Error playing audio:", error); | ||
}); | ||
|
||
if (!gameOverData?.userWon) { | ||
callConfettiSnow(); | ||
} | ||
} else { | ||
audio = new Audio(LevelCompleteAudio); | ||
} | ||
audio.play(); | ||
setTimeout(() => { | ||
|
||
const shakeTimeout = setTimeout(() => { | ||
setShake(false); | ||
}, 4000); | ||
|
||
return () => { | ||
clearTimeout(shakeTimeout); | ||
}; | ||
} | ||
}, [startShowCase, isShowCase, gameOverData]); | ||
}, [startShowCase, isShowCase, gameOverData, audioCache]); | ||
|
||
let currentPracticeStep = progressData?.currentPracticeStep; | ||
let currentPracticeProgress = progressData?.currentPracticeProgress || 0; | ||
|
@@ -752,7 +795,7 @@ const MainLayout = (props) => { | |
> | ||
<Stack justifyContent="center" alignItems="center"> | ||
<img | ||
src={gameLost} | ||
src={`https://raw.githubusercontent.com/Sunbird-ALL/all-learner-ai-app/refs/heads/all-1.3/src/assets/images/gameLost.svg`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Replace hardcoded image URL with imported asset The Apply this diff to replace the hardcoded URL with an imported asset: + import gameLost from "../../assets/images/gameLost.svg";
...
- src={`https://raw.githubusercontent.com/Sunbird-ALL/all-learner-ai-app/refs/heads/all-1.3/src/assets/images/gameLost.svg`}
+ src={gameLost}
|
||
alt="gameLost" | ||
style={{ height: 340 }} | ||
/> | ||
|
@@ -1196,6 +1239,9 @@ MainLayout.propTypes = { | |
storedData: PropTypes.array, | ||
resetStoredData: PropTypes.func, | ||
pageName: PropTypes.string, | ||
gameOverData: PropTypes.shape({ | ||
userWon: PropTypes.bool, | ||
}), | ||
}; | ||
|
||
export default MainLayout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix potential memory leak due to stale
audioCache
in cleanup functionThe cleanup function in the
useEffect
depends onaudioCache
, but sinceaudioCache
is not included in the dependency array, the cleanup function may reference a stale value ofaudioCache
. This can lead to the preloaded audio URLs not being revoked properly, resulting in memory leaks.Apply this diff to fix the issue by using a
ref
to store theaudioCache
, ensuring the cleanup function has access to the latest values: