-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
641 add sequence navigation buttons (#642)
* Add picture sequence navigation buttons * Prefetch picture sequence neighbors * Fix ambiguous selector in test * Small refactorings
- Loading branch information
Showing
5 changed files
with
169 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
import { useEffect } from 'react'; | ||
import { useGetPictureInfoLazyQuery } from '../graphql/APIConnector'; | ||
import { PictureIds } from '../components/views/picture/PictureView'; | ||
import { | ||
getNextPictureId, | ||
getPreviousPictureId, | ||
} from '../components/views/picture/helpers/next-prev-picture'; | ||
import { useGetPictureInfoLazyQuery } from '../graphql/APIConnector'; | ||
|
||
const usePrefetchPictureHook = (id: string, siblings?: string[]) => { | ||
const [previousQuery] = useGetPictureInfoLazyQuery(); | ||
const [nextQuery] = useGetPictureInfoLazyQuery(); | ||
const usePrefetchPictureHook = ( | ||
{ pictureInSiblingsId, pictureInSequenceId }: PictureIds, | ||
siblings?: string[], | ||
pictureSequenceIds?: string[] | ||
) => { | ||
const [previousInSiblingsQuery] = useGetPictureInfoLazyQuery(); | ||
const [nextInSiblingsQuery] = useGetPictureInfoLazyQuery(); | ||
const [previousInSequenceQuery] = useGetPictureInfoLazyQuery(); | ||
const [nextInSequenceQuery] = useGetPictureInfoLazyQuery(); | ||
|
||
useEffect(() => { | ||
if (siblings?.includes(id)) { | ||
const previousId = getPreviousPictureId(id, siblings); | ||
if (siblings?.includes(pictureInSiblingsId)) { | ||
const previousId = getPreviousPictureId(pictureInSiblingsId, siblings); | ||
if (previousId) { | ||
previousInSiblingsQuery({ | ||
variables: { | ||
pictureId: previousId, | ||
}, | ||
}); | ||
} | ||
const nextId = getNextPictureId(pictureInSiblingsId, siblings); | ||
if (nextId) { | ||
nextInSiblingsQuery({ | ||
variables: { | ||
pictureId: nextId, | ||
}, | ||
}); | ||
} | ||
} | ||
if (pictureSequenceIds?.includes(pictureInSequenceId)) { | ||
const previousId = getPreviousPictureId(pictureInSequenceId, pictureSequenceIds); | ||
if (previousId) { | ||
previousQuery({ | ||
previousInSequenceQuery({ | ||
variables: { | ||
pictureId: previousId, | ||
}, | ||
}); | ||
} | ||
const nextId = getNextPictureId(id, siblings); | ||
const nextId = getNextPictureId(pictureInSequenceId, pictureSequenceIds); | ||
if (nextId) { | ||
nextQuery({ | ||
nextInSequenceQuery({ | ||
variables: { | ||
pictureId: nextId, | ||
}, | ||
}); | ||
} | ||
} | ||
}, [id, siblings, previousQuery, nextQuery]); | ||
}, [ | ||
pictureInSiblingsId, | ||
siblings, | ||
previousInSiblingsQuery, | ||
nextInSiblingsQuery, | ||
pictureSequenceIds, | ||
pictureInSequenceId, | ||
previousInSequenceQuery, | ||
nextInSequenceQuery, | ||
]); | ||
}; | ||
|
||
export default usePrefetchPictureHook; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters