Skip to content

Commit

Permalink
fix: onNext being called when story ends
Browse files Browse the repository at this point in the history
  • Loading branch information
Edoardo Odorico committed Jun 19, 2023
1 parent 70148ec commit 462078e
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/components/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,9 @@ export default function () {

const handleKeyDown = (e: KeyboardEvent) => {
if (e.key === "ArrowLeft") {
if(onPrevious != undefined){
onPrevious();
}
previous();
} else if (e.key === "ArrowRight") {
if(onNext != undefined){
onNext();
}
next();
next(true);
}
};

Expand All @@ -92,10 +86,16 @@ export default function () {
};

const previous = () => {
if (onPrevious != undefined) {
onPrevious();
}
setCurrentIdWrapper((prev) => (prev > 0 ? prev - 1 : prev));
};

const next = () => {
const next = (isSkippedByUser?: boolean) => {
if (onNext != undefined && isSkippedByUser) {
onNext();
}
// Check if component is mounted - for issue #130 (https://github.com/mohitk05/react-insta-stories/issues/130)
if (isMounted()) {
if (loop) {
Expand Down Expand Up @@ -137,17 +137,7 @@ export default function () {
if (pause) {
toggleState("play");
} else {
if(type === "next"){
if(onNext != undefined){
onNext();
}
next();
}else{
if(onPrevious != undefined){
onPrevious();
}
previous();
}
type === "next" ? next(true) : previous();
}
};

Expand Down

0 comments on commit 462078e

Please sign in to comment.