-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from ubilabs/feat/showcase
feat(showcase): add autoplay for stories and slides
- Loading branch information
Showing
11 changed files
with
151 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {FunctionComponent} from 'react'; | ||
import {useInterval} from '../../hooks/use-interval'; | ||
import {useHistory} from 'react-router-dom'; | ||
|
||
interface Props { | ||
autoPlayLink: string | null; | ||
} | ||
|
||
const Autoplay: FunctionComponent<Props> = ({autoPlayLink}) => { | ||
const history = useHistory(); | ||
|
||
useInterval(() => { | ||
history.replace(`${autoPlayLink}`); | ||
}, 5000); | ||
|
||
return null; | ||
}; | ||
|
||
export default Autoplay; |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {useEffect, useRef} from 'react'; | ||
|
||
export const useInterval = (callback: () => void, delay: number) => { | ||
const savedCallback = useRef<() => void | undefined>(); | ||
|
||
// Remember the latest callback. | ||
useEffect(() => { | ||
savedCallback.current = callback; | ||
}, [callback]); | ||
|
||
// Set up the interval. | ||
useEffect(() => { | ||
function tick() { | ||
savedCallback.current && savedCallback.current(); | ||
} | ||
|
||
if (delay !== null) { | ||
const id = setInterval(tick, delay); | ||
return () => clearInterval(id); | ||
} | ||
|
||
return () => {}; | ||
}, [delay]); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {StoryMode} from '../types/story-mode'; | ||
|
||
interface Params { | ||
mode: StoryMode; | ||
slideIndex: number; | ||
storyIndex: number; | ||
storyId?: string | null; | ||
storyIds?: string; | ||
numberOfSlides?: number; | ||
} | ||
|
||
export const getNavigationData = ({ | ||
mode, | ||
slideIndex, | ||
storyIndex, | ||
storyId, | ||
storyIds, | ||
numberOfSlides | ||
}: Params) => { | ||
let autoPlayLink = null; | ||
let nextSlideLink = null; | ||
let previousSlideLink = null; | ||
|
||
if (!numberOfSlides) { | ||
return {autoPlayLink, nextSlideLink, previousSlideLink}; | ||
} | ||
|
||
const previousSlideIndex = slideIndex - 1; | ||
if (previousSlideIndex >= 0) { | ||
previousSlideLink = `/${mode}/${storyId}/${previousSlideIndex}`; | ||
} | ||
const nextSlideIndex = slideIndex + 1; | ||
if (nextSlideIndex < numberOfSlides) { | ||
nextSlideLink = `/${mode}/${storyId}/${nextSlideIndex}`; | ||
} | ||
|
||
if (storyIds) { | ||
const stories = storyIds.split('&'); | ||
const nextStoryIndex = storyIndex + 1; | ||
|
||
// go through all slides of one story | ||
if (slideIndex + 1 < numberOfSlides) { | ||
autoPlayLink = `/showcase/${storyIds}/${storyIndex}/${nextSlideIndex}`; | ||
// when no slides are left, go to first slide of next story | ||
} else if (nextStoryIndex < stories.length) { | ||
autoPlayLink = `/showcase/${storyIds}/${nextStoryIndex}/0`; | ||
// after the last story, return to the beginning | ||
} else { | ||
autoPlayLink = `/showcase/${storyIds}/0/0`; | ||
} | ||
} | ||
|
||
return {autoPlayLink, nextSlideLink, previousSlideLink}; | ||
}; |
This file was deleted.
Oops, something went wrong.
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