Skip to content

Commit

Permalink
Merge pull request #146 from Program-AR/prevNextButtons
Browse files Browse the repository at this point in the history
Botones desafio anterior y siguiente
  • Loading branch information
danielferro69 authored Dec 5, 2023
2 parents e459653 + 16b289a commit 12addc9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
4 changes: 4 additions & 0 deletions locales/en-us/others.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"previousChallenge": "Previous challenge",
"nextChallenge": "Next challenge"
}
4 changes: 4 additions & 0 deletions locales/es-ar/others.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"previousChallenge": "Desafío anterior",
"nextChallenge": "Desafío siguiente"
}
4 changes: 4 additions & 0 deletions locales/pt-br/others.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"previousChallenge": "Desafio anterior",
"nextChallenge": "Próximo desafio"
}
29 changes: 24 additions & 5 deletions src/components/ChallengeView.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
import { Typography, useMediaQuery } from "@mui/material";
import { Stack, Typography, useMediaQuery } from "@mui/material";
import { Link, useParams, useSearchParams } from "react-router-dom";
import { Challenge, getChallengeWithName, getPathToChallenge, PathToChallenge } from "../staticData/challenges";
import { EmberView } from "./emberView/EmberView";
import HomeIcon from '@mui/icons-material/Home';
import { Header } from "./header/Header";
import { useTranslation } from "react-i18next";
import { PBreadcrumbs } from "./PBreadcrumbs";
import KeyboardDoubleArrowLeftIcon from '@mui/icons-material/KeyboardDoubleArrowLeft';
import KeyboardDoubleArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowRight';
import { IconButtonTooltip } from "./creator/Editor/SceneEdition/IconButtonTooltip";
import { useThemeContext } from "../theme/ThemeContext";


const ChallengeBreadcrumb = (path: PathToChallenge) => {

const { t } = useTranslation(["books", "challenges", "chapters", "groups"])
const { t } = useTranslation(["books", "challenges", "chapters", "groups", "others"])
const {theme} = useThemeContext()
const isSmallScreen: boolean = useMediaQuery('(max-width:1100px)');
const isVerySmallScreen: boolean = useMediaQuery('(max-width:700px)');

const shouldShowGroup = path.book.id === 1 && !isVerySmallScreen
const shouldShowChapter = !isSmallScreen
const hasPrevChallenge = path.group.previousChallenge(path.challenge)
const hasNextChallenge = path.group.nextChallenge(path.challenge)

return <>
return <Stack direction="row" alignItems="center">
<PBreadcrumbs>

<Link to="/">
Expand All @@ -39,10 +47,21 @@ const ChallengeBreadcrumb = (path: PathToChallenge) => {
<Typography>{t(`${path.challenge.id}.title`, { ns: "challenges" })}</Typography>

</PBreadcrumbs>
</>
<Stack marginLeft={theme.spacing(5)} direction='row'>
{hasPrevChallenge &&
<Link to={`/desafio/${hasPrevChallenge!.id}`}>
<IconButtonTooltip icon={<KeyboardDoubleArrowLeftIcon />} tooltip={t('previousChallenge', { ns: "others" })} />
</Link>
}
{hasNextChallenge &&
<Link to={`/desafio/${hasNextChallenge!.id}`}>
<IconButtonTooltip icon={<KeyboardDoubleArrowRightIcon />} tooltip={t('nextChallenge', { ns: "others" })} />
</Link>
}
</Stack>
</Stack>
}


type ChallengeViewProps = {
challengeId: number
}
Expand Down
14 changes: 14 additions & 0 deletions src/staticData/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export class Group {
return this.challenges.length === 1
}

indexInGroup(challenge: Challenge) {
return this.challenges.findIndex(findChallenge => findChallenge.id === challenge.id)
}

nextChallenge(challenge: Challenge) {
const index = this.indexInGroup(challenge)
return (index === this.challenges.length - 1 ? undefined : this.challenges[index + 1])
}

previousChallenge(challenge: Challenge) {
const index = this.indexInGroup(challenge)
return (index === 0 ? undefined : this.challenges[index - 1])
}

includes(challenge: Challenge) {
return this.challenges.some(otherChallenge => otherChallenge.id === challenge.id)
}
Expand Down

0 comments on commit 12addc9

Please sign in to comment.