Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
Shreya Bhandari committed Sep 7, 2024
1 parent 3311563 commit 5f812fe
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/components/problem-layout/Problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { withStyles } from "@material-ui/core/styles";
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import ProblemCard from "./ProblemCard";
import ProblemCardWrapper from "./ProblemCardWrapper";
import Grid from "@material-ui/core/Grid";
import { animateScroll as scroll, Element, scroller } from "react-scroll";
import update from "../../models/BKT/BKT-brain.js";
Expand Down Expand Up @@ -39,7 +39,7 @@ class Problem extends React.Component {
constructor(props, context) {
super(props);

const { setLanguage } = this.props;
const { setLanguage } = props;
if (props.lesson.courseName == "Matematik 4") {
setLanguage('se')
}
Expand Down Expand Up @@ -464,7 +464,7 @@ class Problem extends React.Component {
name={idx.toString()}
key={`${problem.id}-${step.id}`}
>
<ProblemCard
<ProblemCardWrapper
problemID={problem.id}
step={step}
index={idx}
Expand Down
1 change: 1 addition & 0 deletions src/components/problem-layout/ProblemCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ProblemCard extends React.Component {
constructor(props, context) {
super(props);
// console.log("problem lesson props:", props);

this.translate = props.translate
this.step = props.step;
this.index = props.index;
Expand Down
11 changes: 11 additions & 0 deletions src/components/problem-layout/ProblemCardWrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { LocalizationConsumer } from '../../util/LocalizationContext';
import ProblemCard from './ProblemCard';

const ProblemCardWrapper = (props) => (
<LocalizationConsumer>
{({ setLanguage }) => <ProblemCard {...props} setLanguage={setLanguage} />}
</LocalizationConsumer>
);

export default ProblemCardWrapper;
8 changes: 8 additions & 0 deletions src/platform-logic/Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class Platform extends React.Component {
}

componentDidMount() {
const { setLanguage } = this.props;
if (this.props.lessonID == 5) {
setLanguage('se')
} else {
const defaultLocale = localStorage.getItem('defaultLocale');
setLanguage(defaultLocale)
}

this._isMounted = true;
if (this.props.lessonID != null) {
console.log("calling selectLesson from componentDidMount...")
Expand Down
4 changes: 2 additions & 2 deletions src/util/useTranslation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import translationsEs from "../locales/es.json";
import translationsSe from "../locales/se.json";

export const useTranslation = () => {
const { language } = useLocalization();
const { language, setLanguage } = useLocalization();

const translationsMap = {
en: translationsEn,
Expand All @@ -19,5 +19,5 @@ export const useTranslation = () => {
return key.split(".").reduce((obj, k) => (obj || {})[k], translations);
};

return translate;
return { translate, setLanguage };
};
4 changes: 2 additions & 2 deletions src/util/withTranslation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useTranslation } from './useTranslation';

const withTranslation = (WrappedComponent) => {
return (props) => {
const translate = useTranslation();
return <WrappedComponent translate={translate} {...props} />;
const { translate, setLanguage } = useTranslation();
return <WrappedComponent translate={translate} setLanguage={setLanguage} {...props} />;
};
};

Expand Down

0 comments on commit 5f812fe

Please sign in to comment.