Skip to content

Commit

Permalink
added waiting spinners
Browse files Browse the repository at this point in the history
  • Loading branch information
shivalagisetty committed Apr 21, 2024
1 parent ee673f7 commit 4f16b7a
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 29 deletions.
147 changes: 145 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"epubjs": "^0.3.93",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-loader-spinner": "^6.1.6",
"react-reader": "^2.0.9"
},
"devDependencies": {
Expand Down
37 changes: 30 additions & 7 deletions src/common/audioCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,37 @@ export default function AudioCard({ pageContent }) {
let utter;

React.useEffect(() => {
if(synth.speaking){
synth.cancel()
if(isPlaying){
if(synth.speaking){
synth.cancel()
setProgress(0)
}
utter = new SpeechSynthesisUtterance(pageContent);
synth.speak(utter)
setIsPlaying(true)
}
utter = new SpeechSynthesisUtterance(pageContent);
synth.speak(utter)
setIsPlaying(true)

}, [pageContent])
const [progress, setProgress] = React.useState(0);
const intervalRef = React.useRef(null); // Reference to store the interval

React.useEffect(() => {
if (isPlaying) {
intervalRef.current = setInterval(() => {
setProgress((prevProgress) => {
if (prevProgress === 100) {
clearInterval(intervalRef.current);
return 100;
} else {
return prevProgress + 1;
}
});
}, 600);
} else {
clearInterval(intervalRef.current);
}

return () => clearInterval(intervalRef.current);
}, [isPlaying]);

return (
<Card sx={{
Expand All @@ -67,7 +90,7 @@ export default function AudioCard({ pageContent }) {
</Typography>
</div>
</CardContent>
<LinearProgress variant="determinate" color="inherit" value={50} sx={{ ml: 1, mr: 1, borderRadius: 10 }} />
<LinearProgress variant="determinate" color="inherit" value={progress} sx={{ ml: 1, mr: 1, borderRadius: 10 }} />
<Box sx={{ display: 'flex', alignItems: 'center', pl: 1, pb: 1, justifyContent: 'center' }}>
<IconButton aria-label="previous">
<Replay10Icon />
Expand Down
24 changes: 24 additions & 0 deletions src/common/hourglassLoader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Hourglass } from "react-loader-spinner";
import BootstrapDialog from "./botstrapDialog";
import { DialogContent } from "@mui/material";

export default function HourglassLoader({open}) {

return (
<BootstrapDialog maxWidth="sm" open={open}>
<DialogContent sx={{display:'flex', flexDirection: 'column'}}>
<div style={{alignSelf: "center", padding: '2rem'}}>
<Hourglass
visible={open}
height="80"
width="80"
ariaLabel="hourglass-loading"
wrapperStyle={{}}
wrapperClass=""
colors={['#306cce', '#72a1ed']}
/>
</div>
</DialogContent>
</BootstrapDialog>
)
}
Loading

0 comments on commit 4f16b7a

Please sign in to comment.