Skip to content
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

IssueId #221316 feat Add Lazy Routing in ALL [React] #90

Open
wants to merge 6 commits into
base: all-1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
href="https://fonts.googleapis.com/css2?family=Quicksand&display=swap"
rel="stylesheet"
/>
<link href="https://fonts.cdnfonts.com/css/bad-comic" rel="stylesheet" />
<script src="./js/jquery-3.7.0.min.js" defer></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<title>EkStep</title>
Expand Down
70 changes: 70 additions & 0 deletions public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Define the name for the cache
const CACHE_NAME = 'my-cache-v1';

// Event listener for installation of the service worker
self.addEventListener('install', event => {
// Perform installation steps
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Opened cache');
// No need to pre-cache any resources during installation
})
);
});

// Event listener for fetching assets
self.addEventListener('fetch', event => {
event.respondWith(
caches.open(CACHE_NAME).then(cache => {
return cache.match(event.request).then(response => {
if (response) {
// Resource is in cache, return it
// console.log('Resource is cached:', event.request.url);
return response;
}

// Resource is not in cache, fetch it from network and cache it
return fetch(event.request).then(networkResponse => {
// Check if fetched response is valid
if (!networkResponse || networkResponse.status !== 200 || networkResponse.type !== 'basic') {
return networkResponse;
}

// Clone the response because it's a stream that can only be consumed once
const responseToCache = networkResponse.clone();

// Cache the fetched response
caches.open(CACHE_NAME).then(cache => {
cache.put(event.request, responseToCache);
});

// console.log('Resource is fetched from network and cached:', event.request.url);
return networkResponse;
}).catch(error => {
// Fetch failed, return a fallback response
console.error('Fetch failed:', error);
// You can return a custom offline page or a fallback response here
});
});
})
);
});

// Event listener for activation of the service worker
self.addEventListener('activate', event => {
const cacheWhitelist = [CACHE_NAME];

event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
// Delete caches not in cacheWhitelist
return caches.delete(cacheName);
}
})
);
})
);
});
17 changes: 15 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ import { startEvent } from './services/callTelemetryIntract';
import '@project-sunbird/telemetry-sdk/index.js';

const App = () => {
const ranonce = useRef(false);
const ranonce = useRef(false);

useEffect(() => {
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/service-worker.js').then((registration) => {
console.log('Service Worker registered:', registration);
}).catch((error) => {
console.log('Service Worker registration failed:', error);
});
});
}
}, []);

useEffect(() => {
const initService = async () => {
var did;
Expand Down Expand Up @@ -69,7 +82,7 @@ const App = () => {
};

setFp();
}, []);
}, []);

return (
<StyledEngineProvider injectFirst>
Expand Down
9 changes: 5 additions & 4 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ export const MessageDialog = ({
>
<Box sx={{ position: "absolute", left: 10, bottom: 0 }}>
{isError ? (
<img src={cryPanda} alt="cryPanda" />
<img src={cryPanda} alt="cryPanda" loading="lazy" />
) : (
<img src={panda} alt="panda" />
<img src={panda} alt="panda" loading="lazy" />
)}
</Box>

Expand Down Expand Up @@ -381,7 +381,7 @@ export const ProfileHeader = ({
{handleBack && (
<Box ml={{ xs: "10px", sm: "94px" }}>
<IconButton onClick={handleBack}>
<img src={back} alt="back" style={{ height: "30px" }} />
<img src={back} alt="back" style={{ height: "30px" }} loading="lazy" />
</IconButton>
</Box>
)}
Expand All @@ -392,7 +392,7 @@ export const ProfileHeader = ({
sx={{ cursor: "pointer" }}
onClick={handleProfileBack}
>
<img src={profilePic} alt="profile-pic" style={{ height: "30px" }} />
<img src={profilePic} alt="profile-pic" style={{ height: "30px", width:'30px' }} loading="lazy" />
</Box>
<Box ml="12px">
<span
Expand Down Expand Up @@ -553,6 +553,7 @@ const Assesment = ({ discoverStart }) => {
getMilestoneDetails?.data.data?.milestone_level?.replace("m", "")
)
);

let sessionId = getLocalData("sessionId");

if (!sessionId || sessionId === 'null'){
Expand Down
4 changes: 3 additions & 1 deletion src/components/DiscoverEnd/DiscoverEnd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,23 @@ const SpeakSentenceComponent = () => {
}}
>
<IconButton>
<img src={back} alt="back" style={{ height: "30px" }} />
<img src={back} alt="back" style={{ height: "30px" }} loading="lazy" />
</IconButton>
<Card sx={sectionStyle}>
<Box sx={{ position: "absolute", left: "3px", bottom: "0px" }}>
<img
src={discoverEndLeft}
alt="timer"
className={shake && "shakeImage"}
loading="lazy"
/>
</Box>
<Box sx={{ position: "absolute", right: "3px", bottom: "0px" }}>
<img
src={discoverEndRight}
alt="timer"
className={shake && "shakeImage"}
loading="lazy"
/>
</Box>
<Box>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DiscoverSentance/DiscoverSentance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const SpeakSentenceComponent = () => {
setVoiceText("");
setEnableNext(false);
}
if (voiceText == "success") {
if (voiceText === "success") {
// go_to_result(voiceText);
setVoiceText("");
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/Layouts.jsx/MainLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const MainLayout = (props) => {
<img
src={levelsImages?.[LEVEL]?.backgroundAddOn}
alt="backgroundAddOn"
loading="lazy"
/>
</Box>
)}
Expand Down Expand Up @@ -256,6 +257,7 @@ const MainLayout = (props) => {
src={catLoading}
alt="catLoading"
// sx={{ height: "58px", width: "58px" }}
loading="lazy"
/>
</Box>
</Card>
Expand Down Expand Up @@ -294,6 +296,7 @@ const MainLayout = (props) => {
src={timer}
alt="timer"
sx={{ height: "58px", width: "58px" }}
loading="lazy"
/>
</Box>
)}
Expand All @@ -312,6 +315,7 @@ const MainLayout = (props) => {
const showGreen = step + 1 <= currentStep;
return (
<Box
key={index}
index={index}
sx={{
height: "8px",
Expand Down Expand Up @@ -684,6 +688,7 @@ const MainLayout = (props) => {
src={clouds}
alt="clouds"
style={{ zIndex: 222 }}
loading="lazy"
/>
)}
</Box>
Expand All @@ -699,6 +704,7 @@ const MainLayout = (props) => {
src={gameWon}
alt="gameWon"
style={{ zIndex: 9999, height: 340 }}
loading="lazy"
/>
) : (
<Stack justifyContent="center"
Expand All @@ -707,6 +713,7 @@ const MainLayout = (props) => {
src={gameLost}
alt="gameLost"
style={{ height: 340 }}
loading="lazy"
/>
<Typography
sx={{ mb: 1, mt: 1, textAlign: "center" }}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Mechanism/WordsOrImage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ const WordsOrImage = ({
maxHeight: "130px",
marginBottom: "40px",
}}
loading="lazy"
alt="img"
/>
</Box>
) : type === "phonics" ? (
Expand Down
10 changes: 5 additions & 5 deletions src/components/Practice/Mechanics1.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ const Mechanics1 = ({page, setPage}) => {
return (
<Box sx={sectionStyle}>
<IconButton>
<img src={back} alt='back' style={{ height: '30px' }} />
<img src={back} alt='back' style={{ height: '30px' }} loading="lazy" />
</IconButton>

<Card sx={{ width: '85vw', height: '80vh', borderRadius: '15px', display:'flex', flexDirection:'column', justifyContent:'space-between' }}>
<CardContent>
<img src={timer} alt='timer' height='40px'/>
<img src={timer} alt='timer' height='40px' loading="lazy" />

<Typography variant="h5" component="h4" sx={{ mb: 4, mt: 4, fontSize: '20px', color: '#333F61', textAlign: 'center', fontFamily:'Quicksand' }}>
Speak the below word
Expand All @@ -40,10 +40,10 @@ const Mechanics1 = ({page, setPage}) => {

<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button variant="contained" sx={{ background: 'linear-gradient(45deg, #A856FF 30%, #710EDC 90%)', color: 'white', m: 1, textTransform: 'none', width: '100px' }}>
<img src={listen} alt='listen' height='15px' /><span style={{marginLeft:'4px', fontFamily:'Quicksand'}}>Listen</span>
<img src={listen} alt='listen' height='15px' loading="lazy" /><span style={{marginLeft:'4px', fontFamily:'Quicksand'}}>Listen</span>
</Button>
<Button variant="contained" sx={{ background: 'linear-gradient(45deg, #84F630 30%, #409500 90%)', color: 'white', m: 1, textTransform: 'none', width: '100px' }}>
<img src={speak} alt='speak' height='15px' /><span style={{marginLeft:'4px', fontFamily:'Quicksand'}}>Speak</span>
<img src={speak} alt='speak' height='15px' loading="lazy" /><span style={{marginLeft:'4px', fontFamily:'Quicksand'}}>Speak</span>
</Button>
</Box>
</CardContent>
Expand All @@ -54,7 +54,7 @@ const Mechanics1 = ({page, setPage}) => {
<img src={level} alt='level' height='100px'/>
</Box>
<Button variant="contained" onClick={()=> setPage(page+1)} sx={{ background: 'linear-gradient(45deg, #FF9050 30%, #E15404 90%)', color: 'white', mt: 4,mr:4, textTransform: 'none', width: '90px', height:'35px' }}>
<span style={{marginRight:'4px'}}>Next</span><img src={arrow} alt='arrow' height='15px' />
<span style={{marginRight:'4px'}}>Next</span><img src={arrow} alt='arrow' height='15px' loading="lazy" />
</Button>
</Box>
</Box>
Expand Down
12 changes: 6 additions & 6 deletions src/components/Practice/Mechanics2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ const Mechanics2 = ({page, setPage}) => {
return (
<Box sx={sectionStyle}>
<IconButton>
<img src={back} alt='back' style={{ height: '30px' }} />
<img src={back} alt='back' style={{ height: '30px' }} loading="lazy" />
</IconButton>

<Card sx={{ width: '85vw', height: '80vh', borderRadius: '15px', display:'flex', flexDirection:'column', justifyContent:'space-between' }}>
<CardContent>
<img src={timer} alt='timer' height='40px'/>
<img src={timer} alt='timer' height='40px' loading="lazy" />
<Typography variant="h5" component="h4" sx={{ mb:2, fontSize: '20px', color: '#333F61', textAlign: 'center' }}>
Guess the below image
</Typography>

<Box sx={{display:'flex', justifyContent:'center', mb:4}}>
<img src={elephant} alt='elephant' height='120px' />
<img src={elephant} alt='elephant' height='120px' loading="lazy" />
</Box>

<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button variant="contained" sx={{ background: 'linear-gradient(45deg, #84F630 30%, #409500 90%)', color: 'white', m: 1, textTransform: 'none', width: '100px' }}>
<img src={speak} alt='speak' height='15px' /><span style={{marginLeft:'4px'}}>Speak</span>
<img src={speak} alt='speak' height='15px' loading="lazy" /><span style={{marginLeft:'4px'}}>Speak</span>
</Button>
</Box>
</CardContent>
<Box>
<Divider />
<Box sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Box sx={{position:'relative', right:'60px'}}>
<img src={level} alt='level' height='100px'/>
<img src={level} alt='level' height='100px'loading="lazy" />
</Box>
<Button variant="contained" onClick={()=> setPage(page+1)} sx={{ background: 'linear-gradient(45deg, #FF9050 30%, #E15404 90%)', color: 'white', mt: 4,mr:4, textTransform: 'none', width: '90px', height:'35px' }}>
<span style={{marginRight:'4px'}}>Next</span><img src={arrow} alt='arrow' height='15px' />
<span style={{marginRight:'4px'}}>Next</span><img src={arrow} alt='arrow' height='15px' loading="lazy" />
</Button>
</Box>
</Box>
Expand Down
7 changes: 4 additions & 3 deletions src/components/Practice/Mechanics3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ const Mechanics2 = ({
setWords(randomizeArray(wordsArr));
} else {
let wordsToShow = [];
if (type == "audio") {
if (type === "audio") {
wordsToShow = allWords?.filter((elem) => elem != wordToSimilar);
}
if (type == "fillInTheBlank") {
if (type === "fillInTheBlank") {
Comment on lines +111 to +114
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor conditional blocks for better readability and performance.

- if (type === "audio") {
-   wordsToShow = allWords?.filter((elem) => elem != wordToSimilar);
- }
- if (type === "fillInTheBlank") {
-   wordsToShow = allWords
-     ?.join(" ")
-     ?.split(" ")
-     .filter((elem) => elem !== wordToSimilar && elem.length > 2);
- }
+ wordsToShow = type === "audio" ? allWords?.filter((elem) => elem != wordToSimilar)
+   : allWords
+     ?.join(" ")
+     ?.split(" ")
+     .filter((elem) => elem !== wordToSimilar && elem.length > 2);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (type === "audio") {
wordsToShow = allWords?.filter((elem) => elem != wordToSimilar);
}
if (type == "fillInTheBlank") {
if (type === "fillInTheBlank") {
wordsToShow = type === "audio" ? allWords?.filter((elem) => elem != wordToSimilar)
: allWords
?.join(" ")
?.split(" ")
.filter((elem) => elem !== wordToSimilar && elem.length > 2);

wordsToShow = allWords
?.join(" ")
?.split(" ")
Expand Down Expand Up @@ -383,8 +383,9 @@ const Mechanics2 = ({
marginBottom: "30px",
}}
>
{words?.map((elem) => (
{words?.map((elem,index) => (
<Box
key={index}
className={`${
type === "audio" && selectedWord === elem
? selectedWord === parentWords
Expand Down
6 changes: 4 additions & 2 deletions src/components/Practice/Mechanics4.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const Mechanics4 = ({
paddingX: type === "word" ? 0 : "20px",
}}
>
{selectedWords?.map((elem) => (
{selectedWords?.map((elem, index) => (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure all elements in lists have a unique key prop.

+ key={`word-${index}`}

Adding a unique key prop to each element in a list helps React maintain state and identity across re-renders, improving performance and preventing bugs.

Also applies to: 186-186, 194-194, 211-211

<span
onClick={() => handleWords(elem, true)}
style={{
Expand All @@ -183,14 +183,15 @@ const Mechanics4 = ({
cursor: "pointer",
marginLeft: type === "word" ? 0 : "20px",
}}
key={index}
>
{elem}
</span>
))}
</Box>
</Box>
<Box sx={{ display: "flex", justifyContent: "center", mb: 3 }}>
{words?.map((elem) => (
{words?.map((elem,index) => (
<>
{type === "word" ? (
<Box
Expand All @@ -207,6 +208,7 @@ const Mechanics4 = ({
borderRadius: "12px",
border: "5px solid #10618E",
}}
key={index}
>
<span
style={{
Expand Down
4 changes: 2 additions & 2 deletions src/components/Practice/Mechanics5.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ const Mechanics5 = ({ page, setPage, setVoiceText, setRecordedAudio, setVoiceAni
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Grid container sx={{ width: '80%', justifyContent: 'center', mb: 2, mt: 8 }}>
<Grid xs={5}>
<img src={seePictureAndTell} style={{ borderRadius: '20px' }} alt='' />
<img src={seePictureAndTell} style={{ borderRadius: '20px' }} alt='seePictureAndTell' loading="lazy" />
</Grid>
<Grid xs={7}>
{sentences?.map((elem, i) => (
<Box mt={i > 0 && 3} sx={{ display: 'flex' }}>
<Box mt={i > 0 && 3} sx={{ display: 'flex' }} key={i}>
<audio
ref={audioRef}
preload="metadata"
Expand Down
Loading