Skip to content

Commit dfaf29a

Browse files
committed
Local storage
Missions are now loaded in local storage
1 parent 94e639c commit dfaf29a

File tree

7 files changed

+55
-39
lines changed

7 files changed

+55
-39
lines changed

src/actions/actionTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export const SUBMIT_ANSWER = 'SUBMIT_ANSWER'
5959
export const SUBMIT_ASSESSMENT = 'SUBMIT_ASSESSMENT'
6060
export const SUBMIT_GRADING = 'SUBMIT_GRADING'
6161
export const UPDATE_HISTORY_HELPERS = 'UPDATE_HISTORY_HELPERS'
62-
export const UPDATE_ASSESSMENT_OVERVIEW = 'UPDATE_ASSESSMENT_OVERVIEW'
6362
export const UPDATE_ASSESSMENT_OVERVIEWS = 'UPDATE_ASSESSMENT_OVERVIEWS'
6463
export const UPDATE_ASSESSMENT = 'UPDATE_ASSESSMENT'
6564
export const UPDATE_GRADING_OVERVIEWS = 'UPDATE_GRADING_OVERVIEWS'

src/actions/session.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ export const updateHistoryHelpers: ActionCreator<actionTypes.IAction> = (loc: st
9999
payload: loc
100100
})
101101

102-
export const updateAssessmentOverview = (overview: IAssessmentOverview) => ({
103-
type: actionTypes.UPDATE_ASSESSMENT_OVERVIEW,
104-
payload: overview
105-
})
106-
107102
export const updateAssessmentOverviews = (overviews: IAssessmentOverview[]) => ({
108103
type: actionTypes.UPDATE_ASSESSMENT_OVERVIEWS,
109104
payload: overviews

src/components/academy/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const assessmentRenderFactory = (cat: AssessmentCategory) => (
2626
routerProps: RouteComponentProps<any>
2727
) => <AssessmentContainer assessmentCategory={cat} />
2828

29-
const assessmentRegExp = ':assessmentId(\\d+)?/:questionId(\\d+)?'
29+
const assessmentRegExp = ':assessmentId(-?\\d+)?/:questionId(\\d+)?'
3030
const gradingRegExp = ':submissionId(\\d+)?/:questionId(\\d+)?'
3131

3232
export const Academy: React.SFC<IAcademyProps> = props => (

src/components/assessment/index.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,20 @@ class Assessment extends React.Component<IAssessmentProps, State> {
8787
public render() {
8888
const assessmentId: number | null = stringParamToInt(this.props.match.params.assessmentId)
8989
const questionId: number =
90-
stringParamToInt(this.props.match.params.questionId) || DEFAULT_QUESTION_ID
90+
stringParamToInt(this.props.match.params.questionId) || DEFAULT_QUESTION_ID;
91+
92+
// If mission for testing is to render, create workspace
93+
const editingOverview = localStorage.getItem("MissionEditingOverviewSA");
94+
if (assessmentId === -1 && editingOverview) {
95+
const overview = JSON.parse(editingOverview)
96+
const assessmentProps: AssessmentProps = {
97+
assessmentId,
98+
questionId,
99+
notAttempted: overview.status === AssessmentStatuses.not_attempted,
100+
closeDate: overview.closeAt
101+
}
102+
return <AssessmentWorkspaceContainer {...assessmentProps} />
103+
}
91104

92105
// If there is an assessment to render, create a workspace. The assessment
93106
// overviews must still be loaded for this, to send the due date.
@@ -136,6 +149,17 @@ class Assessment extends React.Component<IAssessmentProps, State> {
136149
makeOverviewCard(overview, index, this.setBetchaAssessment, true, true)
137150
)
138151

152+
/** Mission editing card, stored in local storage and have index of -1. */
153+
const missionEditingCard = editingOverview ?
154+
makeOverviewCard(
155+
JSON.parse(editingOverview),
156+
-1,
157+
this.setBetchaAssessment,
158+
true,
159+
false
160+
) :
161+
null;
162+
139163
/** Render cards */
140164
const upcomingCardsCollapsible =
141165
upcomingCards.length > 0 ? (
@@ -168,10 +192,11 @@ class Assessment extends React.Component<IAssessmentProps, State> {
168192
) : null
169193
display = (
170194
<>
195+
<ImportFromFileComponent />
196+
{missionEditingCard}
171197
{upcomingCardsCollapsible}
172198
{openedCardsCollapsible}
173199
{closedCardsCollapsible}
174-
<ImportFromFileComponent />
175200
</>
176201
)
177202
}

src/components/commons/ImportFromFileComponent.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import * as React from 'react'
22
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux'
33
import { bindActionCreators, Dispatch } from 'redux'
44
import { parseString } from 'xml2js'
5-
import { updateAssessment, updateAssessmentOverview } from '../../actions/session'
5+
import { updateAssessment } from '../../actions/session'
66
import {
77
IAssessment,
88
IAssessmentOverview,
99
} from '../../components/assessment/assessmentShape'
1010
import { makeAssessment, makeAssessmentOverview } from '../../utils/xmlParser'
11-
// import { IDispatchProps } from '../../components/assessment'
1211

1312
export interface IDispatchProps {
1413
newAssessment: (assessment: IAssessment) => void
15-
newAssessmentOverview: (overview: IAssessmentOverview) => void
1614
}
1715

1816
const mapStateToProps: MapStateToProps<{}, any, {}> = (_, ownProps) => ownProps
@@ -21,7 +19,6 @@ const mapDispatchToProps: MapDispatchToProps<IDispatchProps, {}> = (dispatch: Di
2119
bindActionCreators(
2220
{
2321
newAssessment: updateAssessment,
24-
newAssessmentOverview: updateAssessmentOverview
2522
},
2623
dispatch
2724
)
@@ -34,6 +31,13 @@ export class ImportFromFileComponent extends React.Component<any, any> {
3431
this.handleChangeFile = this.handleChangeFile.bind(this)
3532
}
3633

34+
public componentDidMount(){
35+
const assessment = localStorage.getItem("MissionEditingAssessmentSA");
36+
if (assessment) {
37+
this.props.newAssessment(JSON.parse(assessment));
38+
}
39+
}
40+
3741
public render() {
3842
return (
3943
<div>
@@ -50,8 +54,10 @@ export class ImportFromFileComponent extends React.Component<any, any> {
5054
// tslint:disable-next-line:no-console
5155
console.dir(task)
5256
const overview: IAssessmentOverview = makeAssessmentOverview(result)
53-
this.props.newAssessmentOverview(overview)
57+
localStorage.setItem("MissionEditingOverviewSA", JSON.stringify(overview));
58+
5459
const assessment: IAssessment = makeAssessment(result)
60+
localStorage.setItem("MissionEditingAssessmentSA", JSON.stringify(assessment));
5561
this.props.newAssessment(assessment)
5662
})
5763
}

src/reducers/session.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
SET_TOKENS,
77
SET_USER,
88
UPDATE_ASSESSMENT,
9-
UPDATE_ASSESSMENT_OVERVIEW,
109
UPDATE_ASSESSMENT_OVERVIEWS,
1110
UPDATE_GRADING,
1211
UPDATE_GRADING_OVERVIEWS,
@@ -50,29 +49,11 @@ export const reducer: Reducer<ISessionState> = (state = defaultSession, action:
5049
...state,
5150
assessments: newAssessments
5251
}
53-
case UPDATE_ASSESSMENT_OVERVIEW:
54-
const newOverviews = Object.assign([], state.assessmentOverviews)
55-
newOverviews.push(action.payload)
56-
return {
57-
...state,
58-
assessmentOverviews: newOverviews
59-
}
6052
case UPDATE_ASSESSMENT_OVERVIEWS:
61-
// if (state.assessmentOverviews){
62-
// const updatedOverviews = Object.assign([], action.payload);
63-
// const usedIDs = new Set();
64-
// action.payload.forEach((x: any) => {usedIDs.add(x.id)});
65-
// state.assessmentOverviews.forEach((x: any) => {if (!usedIDs.has(x.id)) {updatedOverviews.push(x)}})
66-
// return {
67-
// ...state,
68-
// assessmentOverviews: updatedOverviews
69-
// }
70-
// } else{
7153
return {
7254
...state,
7355
assessmentOverviews: action.payload
7456
}
75-
// }
7657
case UPDATE_GRADING:
7758
const newGradings = new Map(state.gradings)
7859
newGradings.set(action.payload.submissionId, action.payload.grading)

src/utils/xmlParser.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
IXmlParseStrTask
2020
} from '../utils/xmlParseStrShapes';
2121

22+
const editingId = -1;
2223

2324
const capitalizeFirstLetter = (str: string) => {
2425
return str.charAt(0).toUpperCase() + str.slice(1)
@@ -32,7 +33,7 @@ export const makeAssessmentOverview = (result: any) : IAssessmentOverview => {
3233
closeAt: rawOverview.duedate,
3334
coverImage: rawOverview.coverimage,
3435
grade: 1,
35-
id: 7,
36+
id: editingId,
3637
maxGrade: 3000,
3738
maxXp: 1000,
3839
openAt: rawOverview.startdate,
@@ -50,7 +51,7 @@ export const makeAssessment = (result: any) : IAssessment => {
5051
const rawOverview : IXmlParseStrOverview = task.$;
5152
return {
5253
category: capitalizeFirstLetter(rawOverview.kind) as AssessmentCategories,
53-
id: 7,
54+
id: editingId,
5455
longSummary: task.TEXT[0],
5556
missionPDF: 'google.com',
5657
questions: makeQuestions(task),
@@ -63,27 +64,36 @@ const altEval = (str: string) : any => {
6364
}
6465

6566
const makeLibrary = (task: IXmlParseStrTask) : Library => {
66-
const symbolsVal : string[] = task.DEPLOYMENT[0].EXTERNAL[0].SYMBOL || [];
67-
const globalsVal = task.GLOBAL.map((x) => [x.IDENTIFIER[0], altEval(x.VALUE[0])]) as Array<[string, any]>;
67+
const external = task.DEPLOYMENT[0].EXTERNAL;
68+
const nameVal = external ?
69+
external[0].$.name
70+
: "NONE";
71+
const symbolsVal : string[] = external ?
72+
external[0].SYMBOL
73+
: [];
74+
const globalsVal = task.GLOBAL ?
75+
task.GLOBAL.map((x) => [x.IDENTIFIER[0], altEval(x.VALUE[0])]) as Array<[string, any]>
76+
: [];
6877
return {
6978
chapter: parseInt(task.DEPLOYMENT[0].$.interpreter, 10),
7079
external: {
71-
name: task.DEPLOYMENT[0].EXTERNAL[0].$.name,
80+
name: nameVal,
7281
symbols: symbolsVal
7382
},
7483
globals: globalsVal,
7584
}
7685
}
7786

7887
const makeQuestions = (task: IXmlParseStrTask) : IQuestion[] => {
88+
const libraryVal = makeLibrary(task);
7989
const questions: Array<IProgrammingQuestion | IMCQQuestion> = []
8090
task.PROBLEMS[0].PROBLEM.forEach((problem: IXmlParseStrProblem, curId: number) => {
8191
const question: IQuestion = {
8292
answer: null,
8393
comment: null,
8494
content: problem.TEXT[0],
8595
id: curId,
86-
library: makeLibrary(task),
96+
library: libraryVal,
8797
type: problem.$.type,
8898
grader: {
8999
name: 'fake person',

0 commit comments

Comments
 (0)