Skip to content

Commit

Permalink
fix(frontend/PictureView): keyboard navigation broken by slideshow
Browse files Browse the repository at this point in the history
  • Loading branch information
japsu committed Nov 8, 2024
1 parent 2c5de47 commit 12d7e95
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontend/src/components/PictureView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type PictureViewProps = RouteComponentProps<{ path: string }> & {
fromAlbumView?: boolean;
};

const slideshowMilliseconds = 3000;

function PictureView({ album, picture, fromAlbumView, history }: PictureViewProps): JSX.Element {
const t = T(r => r.PictureView);
const { preview, title } = picture;
Expand All @@ -38,7 +40,7 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp
const [isContactDialogOpen, setContactDialogOpen] = React.useState(false);

const goTo = React.useCallback(
(direction: Direction, state: unknown = undefined) => () => {
(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 Down Expand Up @@ -125,8 +127,8 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp

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

React.useEffect(() => {
Expand All @@ -153,7 +155,7 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp

{picture.previous ? (
<div
onClick={goTo('previous')}
onClick={() => goTo('previous')}
className="PictureView-nav PictureView-nav-previous"
title={t(r => r.previousPicture)}
>
Expand All @@ -165,7 +167,7 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp

{picture.next ? (
<div
onClick={goTo('next')}
onClick={() => goTo('next')}
className="PictureView-nav PictureView-nav-next"
title={t(r => r.nextPicture)}
>
Expand All @@ -176,7 +178,7 @@ function PictureView({ album, picture, fromAlbumView, history }: PictureViewProp
) : null}

<div
onClick={goTo('album')}
onClick={() => goTo('album')}
className="PictureView-action PictureView-action-exit"
title={t(r => r.backToAlbum)}
>
Expand Down

0 comments on commit 12d7e95

Please sign in to comment.