Skip to content

Commit

Permalink
feat(PictureView): press S to start slideshow
Browse files Browse the repository at this point in the history
  • Loading branch information
japsu committed Sep 27, 2024
1 parent a6f55df commit f0f1352
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions frontend/src/components/PictureView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp
const [isContactDialogOpen, setContactDialogOpen] = React.useState(false);

const goTo = React.useCallback(
(direction: Direction) => () => {
(direction: Direction, state: unknown = undefined) => () => {
// TODO hairy due to refactoring .album away from picture, ameliorate
const destination = direction === 'album' ? album : picture[direction];
if (destination) {
Expand All @@ -49,10 +49,10 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp
history.goBack();
} else {
// arrived using direct link
history.push(destination.path);
history.push(destination.path, state);
}
} else {
history.replace(destination.path);
history.replace(destination.path, state);
}
}
},
Expand All @@ -72,6 +72,9 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp
if (event.key === 'r' || event.key === 'R') {
history.push('/random');
return;
} else if (event.key === 's' || event.key === 'S') {
startSlideshow();
return;
}

const direction = keyMap[event.code];
Expand Down Expand Up @@ -120,9 +123,20 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp
window.open(picture.original.src);
}, [picture]);

const startSlideshow = React.useCallback(() => {
setTimeout(() => {
goTo('next', { slideshow: true })();
}, 5000);
}, [goTo]);

React.useEffect(() => {
preloadPreviousAndNext(picture);
document.addEventListener('keydown', onKeyDown);

if ((history.location.state as any).slideshow) {
startSlideshow();
}

return () => {
document.removeEventListener('keydown', onKeyDown);
};
Expand Down

0 comments on commit f0f1352

Please sign in to comment.