Skip to content

Commit

Permalink
Fix UK switch in stories (#323)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Starosta <[email protected]>
  • Loading branch information
martin-starosta and Martin Starosta committed Jun 26, 2023
1 parent bb944df commit 2122797
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions components/basecomponents/StoryReader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const StoryReader = ({ titleCurrent, titleOther, id, phrases }: StoryReaderProps
const handleLanguageChange = (language: Language) => {
const ukCurrent = language === 'uk';
const currentTime = audio.current?.currentTime || 0;

if (phrases.length === 0) {
console.log('No phrases provided to StoryReader.');
return;
}

if ((ukCurrent && currentTime < phrases[0].start_uk) || (!ukCurrent && currentTime < phrases[0].start_cs)) {
/*if this function is launched before the first phrase starts, which is usually at about fifteenth second, we want to
play the story from the beginning, and that is why we use this condition */
Expand Down
3 changes: 2 additions & 1 deletion pages/kids/stories/[story].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ export const getStaticPaths: GetStaticPaths<UrlParams> = async () => {
export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
const storyId = params?.story ?? '';
const story = stories.find((s) => s.slug === storyId);
const storyLocale = getCountryVariant();

const phrases = await getStoryData((locale as Language) ?? 'cs', String(story?.slug));
const phrases = await getStoryData(storyLocale ?? 'cs', String(story?.slug));

return {
props: { story, phrases, ...(await serverSideTranslations(locale ?? 'cs', ['common'])) },
Expand Down
3 changes: 2 additions & 1 deletion pages/kids/stories/pdf/[storyId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const getStaticPaths: GetStaticPaths<UrlParams> = async () => {
export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
const storyId = params?.storyId ?? '';
const story = stories.find((s) => s.slug === storyId);
const storyLocale = getCountryVariant();

if (!story) {
return {
Expand All @@ -119,7 +120,7 @@ export const getStaticProps: GetStaticProps = async ({ params, locale }) => {

let storyData: StoryPhrase[] = [];
try {
storyData = await getStoryData((locale as Language) ?? 'cs', story.slug);
storyData = await getStoryData(storyLocale ?? 'cs', String(story?.slug));
} catch (err) {
console.error(err);
}
Expand Down
3 changes: 2 additions & 1 deletion pages/kiosk/stories/[story].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ export const getStaticPaths: GetStaticPaths<UrlParams> = async () => {
export const getStaticProps: GetStaticProps = async ({ params, locale }) => {
const storyId = params?.story ?? '';
const story = stories.find((s) => s.slug === storyId);
const storyLocale = getCountryVariant();

const phrases = await getStoryData((locale as Language) ?? 'cs', String(story?.slug));
const phrases = await getStoryData(storyLocale ?? 'cs', String(story?.slug));

return {
props: { story, phrases, ...(await serverSideTranslations(locale ?? 'cs', ['common'])) },
Expand Down

0 comments on commit 2122797

Please sign in to comment.