Skip to content

Commit 57697a9

Browse files
committed
handle variant urls
1 parent 2420db0 commit 57697a9

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

src/components/Application.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,26 @@ import Contributors from './contributors';
1616
import NavigationBar from './NavigationBar';
1717
import NotFound from './NotFound';
1818

19+
import { Variant } from 'js-slang/dist/types';
20+
1921
export interface IApplicationProps extends IDispatchProps, IStateProps, RouteComponentProps<{}> {}
2022

2123
export interface IStateProps {
2224
accessToken?: string;
2325
currentPlaygroundChapter: number;
26+
currentPlaygroundVariant: Variant;
2427
role?: Role;
2528
title: string;
2629
name?: string;
2730
currentExternalLibrary: ExternalLibraryName;
2831
}
2932

3033
export interface IDispatchProps {
31-
handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) => void;
34+
handleClearContext: (
35+
chapter: number,
36+
variant: Variant,
37+
externalLibraryName: ExternalLibraryName
38+
) => void;
3239
handleEditorValueChange: (val: string) => void;
3340
handleEditorUpdateBreakpoints: (breakpoints: string[]) => void;
3441
handleEnsureLibrariesLoaded: () => void;
@@ -90,12 +97,13 @@ const toLogin = (props: IApplicationProps) => () => (
9097
const parsePlayground = (props: IApplicationProps) => {
9198
const prgrm = parsePrgrm(props);
9299
const chapter = parseChapter(props) || props.currentPlaygroundChapter;
100+
const variant = parseVariant(props) || props.currentPlaygroundVariant;
93101
const externalLibraryName = parseExternalLibrary(props) || props.currentExternalLibrary;
94102
const execTime = parseExecTime(props);
95103
if (prgrm) {
96104
props.handleEditorValueChange(prgrm);
97105
props.handleEnsureLibrariesLoaded();
98-
props.handleClearContext(chapter, externalLibraryName);
106+
props.handleClearContext(chapter, variant, externalLibraryName);
99107
props.handleExternalLibrarySelect(externalLibraryName);
100108
props.handleSetExecTime(execTime);
101109
}
@@ -112,13 +120,24 @@ const parsePrgrm = (props: RouteComponentProps<{}>) => {
112120

113121
const parseChapter = (props: RouteComponentProps<{}>) => {
114122
const chapQuery = qs.parse(props.location.hash).chap;
123+
115124
const chap: number = sourceURLNames.has(chapQuery)
116-
? sourceURLNames.get(chapQuery)!
125+
? sourceURLNames.get(chapQuery)!.chapter
117126
: chapQuery === undefined
118127
? NaN
119128
: parseInt(chapQuery, 10);
120129

121-
return chap;
130+
return chap ? chap : undefined;
131+
};
132+
133+
const parseVariant = (props: RouteComponentProps<{}>) => {
134+
const chapQuery = qs.parse(props.location.hash).chap;
135+
136+
const variant: Variant = sourceURLNames.has(chapQuery)
137+
? sourceURLNames.get(chapQuery)!.variant
138+
: 'default';
139+
140+
return variant;
122141
};
123142

124143
const parseExternalLibrary = (props: RouteComponentProps<{}>) => {

src/components/__tests__/Application.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ import { mockRouterProps } from '../../mocks/components';
55
import Application, { IApplicationProps } from '../Application';
66
import { ExternalLibraryName, ExternalLibraryNames } from '../assessment/assessmentShape';
77

8+
import { Variant } from 'js-slang/dist/types';
9+
810
test('Application renders correctly', () => {
911
const props: IApplicationProps = {
1012
...mockRouterProps('/academy', {}),
1113
title: 'Cadet',
1214
currentPlaygroundChapter: 2,
15+
currentPlaygroundVariant: 'default',
1316
handleLogOut: () => {},
1417
currentExternalLibrary: ExternalLibraryNames.NONE,
15-
handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) => {},
18+
handleClearContext: (
19+
chapter: number,
20+
variant: Variant,
21+
externalLibraryName: ExternalLibraryName
22+
) => {},
1623
handleEditorValueChange: (val: string) => {},
1724
handleEditorUpdateBreakpoints: (breakpoints: string[]) => {},
1825
handleEnsureLibrariesLoaded: () => {},

src/components/assessment/assessmentShape.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ type ExternalLibrary = {
164164
symbols: string[];
165165
};
166166

167+
export type Variant = 'lazy' | 'non-det' | 'default'
168+
167169
export type Library = {
168170
chapter: number;
169171
variant?: Variant;

src/components/missionControl/editingWorkspaceSideContent/DeploymentTab.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IconNames } from '@blueprintjs/icons';
33
import { ItemRenderer, Select } from '@blueprintjs/select';
44
import * as React from 'react';
55
import { externalLibraries } from '../../../reducers/externalLibraries';
6-
import { sourceLanguages, styliseChapter } from '../../../reducers/states';
6+
import { sourceLanguages, styliseChapter } from '../../../reducers/states';
77

88
import { ExternalLibraryName, IAssessment, Library } from '../../assessment/assessmentShape';
99
import { controlButton } from '../../commons';
@@ -242,7 +242,11 @@ const altEval = (str: string): any => {
242242
return Function('"use strict";return (' + str + ')')();
243243
};
244244

245-
const chapters = sourceLanguages.map(lang => ({ chapter: lang.chapter, variant: lang.variant, displayName: styliseChapter(lang.chapter, lang.variant) }));
245+
const chapters = sourceLanguages.map(lang => ({
246+
chapter: lang.chapter,
247+
variant: lang.variant,
248+
displayName: styliseChapter(lang.chapter, lang.variant)
249+
}));
246250

247251
const chapterSelect = (
248252
currentChap: number,

src/containers/ApplicationContainer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { ExternalLibraryName } from '../components/assessment/assessmentShape';
1313
import { externalLibraries } from '../reducers/externalLibraries';
1414
import { IState } from '../reducers/states';
1515

16+
import { Variant } from 'js-slang/dist/types';
17+
1618
/**
1719
* Provides the title of the application for display.
1820
* An object with the relevant properties must be
@@ -26,6 +28,7 @@ const mapStateToProps: MapStateToProps<IStateProps, {}, IState> = state => ({
2628
role: state.session.role,
2729
name: state.session.name,
2830
currentPlaygroundChapter: state.workspaces.playground.context.chapter,
31+
currentPlaygroundVariant: state.workspaces.playground.context.variant,
2932
currentExternalLibrary: state.workspaces.playground.externalLibrary
3033
});
3134

@@ -34,10 +37,15 @@ const workspaceLocation = WorkspaceLocations.playground;
3437
const mapDispatchToProps: MapDispatchToProps<IDispatchProps, {}> = (dispatch: Dispatch<any>) =>
3538
bindActionCreators(
3639
{
37-
handleClearContext: (chapter: number, externalLibraryName: ExternalLibraryName) =>
40+
handleClearContext: (
41+
chapter: number,
42+
variant: Variant,
43+
externalLibraryName: ExternalLibraryName
44+
) =>
3845
beginClearContext(
3946
{
4047
chapter,
48+
variant,
4149
external: {
4250
name: externalLibraryName,
4351
symbols: externalLibraries.get(externalLibraryName)!

0 commit comments

Comments
 (0)