Skip to content

Commit 3f83b24

Browse files
committed
send the lesson id when creating a lesson project
1 parent e69dad8 commit 3f83b24

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎src/lib/ct-url-flags.js‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ const parseFlags = params => ({
5353
lesson: parseBooleanParam(params, LESSON_PARAM, false)
5454
});
5555

56-
const flags = parseFlags(readSearchParams());
56+
const urlParams = readSearchParams();
57+
const flags = parseFlags(urlParams);
58+
// ?lessonId=<path>/<unit>/<lesson> names the Learning Path lesson the editor is embedded in.
59+
const lessonId = flags.lesson ? (urlParams.get('lessonId') || '') : '';
5760

5861
/**
5962
* @returns {boolean} True if the URL explicitly asked for the compiler to be off.
@@ -75,6 +78,11 @@ const isCursorChatEnabled = () => flags.chat;
7578
*/
7679
const isLessonMode = () => flags.lesson;
7780

81+
/**
82+
* @returns {string} Global id of the lesson the editor is embedded in, or '' when unknown.
83+
*/
84+
const getLessonId = () => lessonId;
85+
7886
/**
7987
* Re-apply the flags that have to survive any in-editor rewrite of the query string.
8088
* @param {URLSearchParams} searchParams Search parameters that are about to be written to the URL
@@ -97,6 +105,7 @@ export {
97105
isMinimalMode,
98106
isCursorChatEnabled,
99107
isLessonMode,
108+
getLessonId,
100109
applyPersistentFlags,
101110
MINIMAL_PARAM,
102111
LESSON_PARAM

‎src/lib/project-saver-hoc.jsx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import storage from '../lib/storage';
1010
import dataURItoBlob from '../lib/data-uri-to-blob';
1111
import saveProjectToServer from '../lib/save-project-to-server';
1212
import {reportLessonSaveResult} from '../lib/ct-lesson-messages';
13+
import {getLessonId} from '../lib/ct-url-flags';
1314

1415
import {
1516
showAlertWithTimeout,
@@ -173,9 +174,11 @@ const ProjectSaverHOC = function (WrappedComponent) {
173174
}
174175
createNewProjectToStorage () {
175176
// In a lesson the project already has its lesson title, which the server should keep.
176-
const requestParams = this.props.lessonMode && this.props.reduxProjectTitle ?
177-
{title: this.props.reduxProjectTitle} :
178-
null;
177+
const requestParams = {};
178+
if (this.props.lessonMode) {
179+
if (this.props.reduxProjectTitle) requestParams.title = this.props.reduxProjectTitle;
180+
if (getLessonId()) requestParams.lesson = getLessonId();
181+
}
179182
return this.storeProject(null, requestParams)
180183
.then(response => {
181184
const projectId = response.id.toString();

‎src/lib/save-project-to-server.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import storage from '../lib/storage';
1313
* @property {?boolean} params.isCopy a flag indicating if this save is creating a copy.
1414
* @property {?boolean} params.isRemix a flag indicating if this save is creating a remix.
1515
* @property {?string} params.title the title of the project.
16+
* @property {?string} params.lesson the Learning Path lesson a new project is created for.
1617
* @return {Promise} A promise that resolves when the network request resolves.
1718
*/
1819
export default function (projectId, vmState, params) {
@@ -31,6 +32,7 @@ export default function (projectId, vmState, params) {
3132
if (Object.prototype.hasOwnProperty.call(params, 'isRemix')) queryParams.is_remix = params.isRemix;
3233
if (Object.prototype.hasOwnProperty.call(params, 'title')) queryParams.title = params.title;
3334
if (Object.prototype.hasOwnProperty.call(params, 'source')) queryParams.source = params.source;
35+
if (Object.prototype.hasOwnProperty.call(params, 'lesson')) queryParams.lesson = params.lesson;
3436

3537
let qs = queryString.stringify(queryParams);
3638
if (qs) qs = `?${qs}`;

0 commit comments

Comments
 (0)