Skip to content

Commit 6031a71

Browse files
committed
Refactor playground language switching
1 parent 563ae6d commit 6031a71

File tree

10 files changed

+66
-253
lines changed

10 files changed

+66
-253
lines changed

src/commons/application/Application.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type DispatchProps = {
2828
handleLogOut: () => void;
2929
handleGitHubLogIn: () => void;
3030
handleGitHubLogOut: () => void;
31-
fetchUserAndCourse: (updateSublanguage: boolean) => void;
31+
fetchUserAndCourse: () => void;
3232
updateLatestViewedCourse: (courseId: number) => void;
3333
handleCreateCourse: (courseConfig: UpdateCourseConfiguration) => void;
3434
};
@@ -55,17 +55,7 @@ const Application: React.FC<ApplicationProps> = props => {
5555
// if the user was previously logged in
5656
React.useEffect(() => {
5757
if (props.name) {
58-
// Do not update the sublanguage in the Playground context to the fetched course configuration
59-
// if it is a shared link with chapter
60-
if (
61-
props.location.pathname === '/playground' &&
62-
props.location.hash &&
63-
parseQuery(props.location.hash).chap
64-
) {
65-
props.fetchUserAndCourse(false);
66-
} else {
67-
props.fetchUserAndCourse(true);
68-
}
58+
props.fetchUserAndCourse();
6959
}
7060
// eslint-disable-next-line react-hooks/exhaustive-deps
7161
}, []);

src/commons/application/actions/SessionActions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ import {
7070
export const fetchAuth = (code: string, providerId?: string) =>
7171
action(FETCH_AUTH, { code, providerId });
7272

73-
export const fetchUserAndCourse = (updateSublanguage: boolean) =>
74-
action(FETCH_USER_AND_COURSE, updateSublanguage);
73+
export const fetchUserAndCourse = () => action(FETCH_USER_AND_COURSE);
7574

7675
export const fetchCourseConfig = () => action(FETCH_COURSE_CONFIG);
7776

src/commons/application/actions/__tests__/SessionActions.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ test('fetchAuth generates correct action object', () => {
108108
});
109109

110110
test('fetchUserAndCourse generates correct action object', () => {
111-
const updateSublanguage: boolean = true;
112-
const action = fetchUserAndCourse(updateSublanguage);
111+
const action = fetchUserAndCourse();
113112
expect(action).toEqual({
114-
type: FETCH_USER_AND_COURSE,
115-
payload: updateSublanguage
113+
type: FETCH_USER_AND_COURSE
116114
});
117115
});
118116

src/commons/application/types/SessionTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export type SessionState = {
8989
readonly enableGame?: boolean;
9090
readonly enableAchievements?: boolean;
9191
readonly enableSourcecast?: boolean;
92+
readonly sourceChapter?: number;
93+
readonly sourceVariant?: Variant;
9294
readonly moduleHelpText?: string;
9395

9496
readonly assessmentConfigurations?: AssessmentConfiguration[];

src/commons/sagas/BackendSaga.ts

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { call, put, select } from 'redux-saga/effects';
55
import { ADD_NEW_USERS_TO_COURSE, CREATE_COURSE } from 'src/features/academy/AcademyTypes';
66
import { UsernameRoleGroup } from 'src/pages/academy/adminPanel/subcomponents/AddUserPanel';
77

8-
import { OverallState, Role, styliseSublanguage } from '../../commons/application/ApplicationTypes';
8+
import { OverallState, Role } from '../../commons/application/ApplicationTypes';
99
import {
1010
Assessment,
1111
AssessmentConfiguration,
@@ -168,16 +168,6 @@ function* BackendSaga(): SagaIterator {
168168
yield put(actions.setCourseRegistration(courseRegistration));
169169
yield put(actions.setCourseConfiguration(courseConfiguration));
170170
yield put(actions.setAssessmentConfigurations(assessmentConfigurations));
171-
yield put(
172-
actions.updateSublanguage({
173-
chapter: courseConfiguration.sourceChapter,
174-
variant: courseConfiguration.sourceVariant,
175-
displayName: styliseSublanguage(
176-
courseConfiguration.sourceChapter,
177-
courseConfiguration.sourceVariant
178-
)
179-
})
180-
);
181171
}
182172
yield history.push('/academy');
183173
});
@@ -187,13 +177,6 @@ function* BackendSaga(): SagaIterator {
187177
function* (action: ReturnType<typeof actions.fetchUserAndCourse>): any {
188178
const tokens = yield selectTokens();
189179

190-
/**
191-
* The updateSublanguage boolean is used to determine whether to update the sublanguage
192-
* in the Playground context to match the latest course configuration. We do not want to
193-
* update it when the user is accessing the Playground via a shared link.
194-
*/
195-
const updateSublanguage: boolean = action.payload;
196-
197180
const {
198181
user,
199182
courseRegistration,
@@ -222,18 +205,6 @@ function* BackendSaga(): SagaIterator {
222205
yield put(actions.setCourseRegistration(courseRegistration));
223206
yield put(actions.setCourseConfiguration(courseConfiguration));
224207
yield put(actions.setAssessmentConfigurations(assessmentConfigurations));
225-
if (updateSublanguage) {
226-
yield put(
227-
actions.updateSublanguage({
228-
chapter: courseConfiguration.sourceChapter,
229-
variant: courseConfiguration.sourceVariant,
230-
displayName: styliseSublanguage(
231-
courseConfiguration.sourceChapter,
232-
courseConfiguration.sourceVariant
233-
)
234-
})
235-
);
236-
}
237208
}
238209
}
239210
);
@@ -243,13 +214,6 @@ function* BackendSaga(): SagaIterator {
243214
const { config }: { config: CourseConfiguration | null } = yield call(getCourseConfig, tokens);
244215
if (config) {
245216
yield put(actions.setCourseConfiguration(config));
246-
yield put(
247-
actions.updateSublanguage({
248-
chapter: config.sourceChapter,
249-
variant: config.sourceVariant,
250-
displayName: styliseSublanguage(config.sourceChapter, config.sourceVariant)
251-
})
252-
);
253217
}
254218
});
255219

@@ -619,7 +583,6 @@ function* BackendSaga(): SagaIterator {
619583
sourceVariant: sublang.variant
620584
})
621585
);
622-
yield put(actions.updateSublanguage(sublang));
623586
yield call(showSuccessMessage, 'Updated successfully!', 1000);
624587
}
625588
);
@@ -653,16 +616,6 @@ function* BackendSaga(): SagaIterator {
653616
yield put(actions.setCourseRegistration(courseRegistration));
654617
yield put(actions.setCourseConfiguration(courseConfiguration));
655618
yield put(actions.setAssessmentConfigurations(assessmentConfigurations));
656-
yield put(
657-
actions.updateSublanguage({
658-
chapter: courseConfiguration.sourceChapter,
659-
variant: courseConfiguration.sourceVariant,
660-
displayName: styliseSublanguage(
661-
courseConfiguration.sourceChapter,
662-
courseConfiguration.sourceVariant
663-
)
664-
})
665-
);
666619
yield call(showSuccessMessage, `Switched to ${courseConfiguration.courseName}!`, 5000);
667620
yield history.push('/academy');
668621
}
@@ -792,16 +745,6 @@ function* BackendSaga(): SagaIterator {
792745
return yield handleResponseError(resp);
793746
}
794747
yield put(actions.setAssessmentConfigurations(placeholderAssessmentConfig));
795-
yield put(
796-
actions.updateSublanguage({
797-
chapter: courseConfiguration.sourceChapter,
798-
variant: courseConfiguration.sourceVariant,
799-
displayName: styliseSublanguage(
800-
courseConfiguration.sourceChapter,
801-
courseConfiguration.sourceVariant
802-
)
803-
})
804-
);
805748
yield call(showSuccessMessage, 'Successfully created your new course!');
806749
yield history.push('/academy');
807750
});

0 commit comments

Comments
 (0)