Skip to content

Commit

Permalink
Fix for him (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-ismagilov authored Apr 23, 2024
1 parent 9da2435 commit 397ed19
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 29 deletions.
6 changes: 5 additions & 1 deletion src/components/Body/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ const Body = () => {
}, [data.fullscreenPhotoId]);

const handleRotationRight = () => {
handleClick(photosList[fullscreenIndex + 1].id);
let newIndex = fullscreenIndex + 1;
if (newIndex >= photosList.length) {
newIndex = 0;
}
handleClick(photosList[newIndex].id);
};

const handleRotationLeft = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Body/MyModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MyModal = ({
return (
<div className="overlay dismiss" onClick={handleClick}>
{isSlideShow
? <Slideshow photo={photo} handleRotationRight={handleRotationRight} rightArrow={rightArrow} />
? <Slideshow photo={photo} handleRotationRight={handleRotationRight} />
: <Lightbox photo={photo} handleRotationRight={handleRotationRight} handleRotationLeft={handleRotationLeft}
leftArrow={leftArrow} rightArrow={rightArrow} />}
</div>
Expand Down
32 changes: 6 additions & 26 deletions src/components/Body/Slideshow.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,19 @@
import React from "react";

import { useAppContext } from "../AppContext";

import Control from "./Control";

import "../../styles/Body.css";

const Slideshow = ({ photo, handleRotationRight, rightArrow }) => {
const timeoutRef = React.useRef(null);

const { setIsSlideShow } = useAppContext();

function resetTimeout() {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
}

const Slideshow = ({ photo, handleRotationRight }) => {
React.useEffect(() => {
resetTimeout();
timeoutRef.current = setTimeout(
() => {
if (rightArrow) {
handleRotationRight();
} else {
setIsSlideShow(false);
}
},
3000
);
const interval = setInterval(() => {
handleRotationRight();
}, 3000);

return () => {
resetTimeout();
clearInterval(interval);
};
}, [photo]);
}, [handleRotationRight]);

return (
<div className="dismiss">
Expand Down
2 changes: 1 addition & 1 deletion src/styles/theme-variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--mainBGColor: #1A1A1A;
--mainColor: white;
--additionalColor: #8A8A8A;
--opacityBGColor: rgba(27, 27, 27, 0.5);
--opacityBGColor: #000000;
--additionalBGColor: #2E2E2E;
--colorRectangle: yellow;
--borderRectangle: yellow;
Expand Down

0 comments on commit 397ed19

Please sign in to comment.