diff --git a/functions/index.js b/functions/index.js index f0806ad..5c64863 100644 --- a/functions/index.js +++ b/functions/index.js @@ -20,8 +20,8 @@ exports.moduleCount = functions.database.ref('/stories/{storyId}') }); exports.orderOfNewModule = functions.database.ref("/stories/{storyId}/modules/{moduleId}") - .onCreate((snap, context) => { - let storyRef = snap + .onCreate((moduleSnap, context) => { + let storyRef = moduleSnap .ref .parent // module .parent; // storyId; @@ -36,10 +36,10 @@ exports.orderOfNewModule = functions.database.ref("/stories/{storyId}/modules/{m .catch(err => reject(err)) .then(count => { Promise.all([ - snap.ref.child("order").set(count), + moduleSnap.ref.child("order").set(count), storyRef.ref.child("moduleCount").set(count + 1), - snap.ref.child("id").set(context.params.moduleId) - ]).then((x) => resolve(x)) + moduleSnap.ref.child("id").set(context.params.moduleId) + ]).then(resolve) .catch(err => reject(err)); }) .catch(err => reject(err)); diff --git a/src/components/ModuleEditCard/ModuleEditCard.js b/src/components/ModuleEditCard/ModuleEditCard.js index e271af7..84442eb 100644 --- a/src/components/ModuleEditCard/ModuleEditCard.js +++ b/src/components/ModuleEditCard/ModuleEditCard.js @@ -13,7 +13,7 @@ export default class ModuleEditCard extends React.Component { order, onOrderDown, deleteDisabled, - onEdit, + editUrl, orderDisabled, text } = this.props; @@ -30,7 +30,7 @@ export default class ModuleEditCard extends React.Component { if (window.confirm("This is IRREVERSIBLE!")) onDelete(e); }}> - +
onOrderUp(e)}> onOrderDown(e)}> diff --git a/src/components/ModuleList/ModuleList.js b/src/components/ModuleList/ModuleList.js index 62b7d1b..fac41f1 100644 --- a/src/components/ModuleList/ModuleList.js +++ b/src/components/ModuleList/ModuleList.js @@ -14,7 +14,7 @@ export default class ModuleList extends React.Component { upOrder, downOrder, onSaveOrder, - onEdit, + getEditUrl, modules } = this.props; @@ -41,7 +41,7 @@ export default class ModuleList extends React.Component { return onEdit(module.id)} + editUrl={getEditUrl(module.id)} orderDisabled={!canChangeOrder} onDelete={() => onDelete(module.id)} onOrderUp={() => upOrder(module.id)} diff --git a/src/containers/views/AddFunfact/AddFunfact.js b/src/containers/views/AddFunfact/AddFunfact.js index 8103e98..90b60a2 100644 --- a/src/containers/views/AddFunfact/AddFunfact.js +++ b/src/containers/views/AddFunfact/AddFunfact.js @@ -8,6 +8,7 @@ import Button from '../../../components/button/Button'; import Navbar from '../../../components/nav/Navbar'; import Footer from '../../../components/footer/Footer'; import { Link } from 'react-router-dom'; +import { resolve } from '../../../../node_modules/url'; class AddFunfact extends React.Component { render() { @@ -26,15 +27,21 @@ class AddFunfact extends React.Component {
{ - return firebaseDatabase + return new Promise((resolve, reject) => { + firebaseDatabase .ref('stories/') .child(storyId) .child("modules") .push({ text, contentType: "funfact" - }).then(() => history.push(`/teacher/dashboard/${storyId}`)); }) + .then(snap => snap.ref.child("id").set(snap.key)) + .then(resolve) + .catch(reject) + .then(() => history.push(`/teacher/dashboard/${storyId}`)); + }) + }) }>

Add weetje for { storyId }

diff --git a/src/containers/views/AddImageQuiz/AddImageQuiz.js b/src/containers/views/AddImageQuiz/AddImageQuiz.js index ba6fe1b..7640dba 100644 --- a/src/containers/views/AddImageQuiz/AddImageQuiz.js +++ b/src/containers/views/AddImageQuiz/AddImageQuiz.js @@ -49,18 +49,22 @@ class AddImageQuiz extends React.Component { contentType: "imagequiz" }).then(snap => { let moduleId = snap.key; - Promise.all( - [correctImage, otherImage1, otherImage2] - .map((file, index) => { - return firebaseStorage() - .ref() - .child(user.uid) - .child("story") - .child(storyId) - .child(moduleId) - .child(names[index]) - .put(file) - })).then(tasks => { + let promises = [correctImage, otherImage1, otherImage2] + .map((file, index) => { + return firebaseStorage() + .ref() + .child(user.uid) + .child("story") + .child(storyId) + .child(moduleId) + .child(names[index]) + .put(file) + }); + promises.push(snap.ref.child("id").set(snap.key)) // this promise + // dont give a task + Promise.all(promises).then(tasks => { + // so let's pop it's result there + tasks.pop(); let urlArray = tasks.map(t => t.metadata.downloadURLs[0]); firebaseDatabase .ref("stories/") diff --git a/src/containers/views/AddQuiz/AddQuiz.js b/src/containers/views/AddQuiz/AddQuiz.js index f3ab18f..d20e3c8 100644 --- a/src/containers/views/AddQuiz/AddQuiz.js +++ b/src/containers/views/AddQuiz/AddQuiz.js @@ -29,11 +29,12 @@ class AddQuiz extends React.Component {

Add quiz for {storyId}

{ - let o = firebaseDatabase + ({correct, other1, other2, ...fields}) => { + return new Promise(resolve => { + firebaseDatabase .ref('stories/') - .child(storyId); - o.child("modules") + .child(storyId) + .child("modules") .push({ contentType: "quiz", options: { @@ -42,8 +43,9 @@ class AddQuiz extends React.Component { other2 }, ...fields - }) + }).then(snap => snap.ref.child("id").set(snap.key).then(resolve)) .then(() => history.push(`/teacher/dashboard/${storyId}`)) + }) }) }>
diff --git a/src/containers/views/AddTextBlock/AddTextBlock.js b/src/containers/views/AddTextBlock/AddTextBlock.js index 45eb41e..cfcbdf1 100644 --- a/src/containers/views/AddTextBlock/AddTextBlock.js +++ b/src/containers/views/AddTextBlock/AddTextBlock.js @@ -24,14 +24,14 @@ class AddImageQuiz extends React.Component { return (
- +

Add textblock for {storyId}

{ - let promise = new Promise((resolve, reject) => { + let promise = new Promise(resolve => { firebaseDatabase .ref('stories/') .child(storyId) @@ -41,7 +41,9 @@ class AddImageQuiz extends React.Component { contentType: "textblock" }).then(snap => { let moduleId = snap.key; - firebaseStorage() + let setIdPromise = snap.ref.child("id").set(moduleId); + let imagePromise = new Promise(imageResolve => { + firebaseStorage() .ref() .child(user.uid) .child("story") @@ -60,10 +62,11 @@ class AddImageQuiz extends React.Component { .child(moduleId) .child("resource") .set(task.metadata.downloadURLs[0]) - .catch(reject) - .then(resolve) + .then(imageResolve) }) - .catch(reject) + }); + Promise.all([setIdPromise, imagePromise]) + .then(resolve) }) }); diff --git a/src/containers/views/StoryDashboard/StoryDashboard.js b/src/containers/views/StoryDashboard/StoryDashboard.js index 0ba1acf..e241a9e 100644 --- a/src/containers/views/StoryDashboard/StoryDashboard.js +++ b/src/containers/views/StoryDashboard/StoryDashboard.js @@ -110,9 +110,7 @@ class StoryDashboard extends React.Component {
{ - let route = `/teacher/dashboard/${story.id}/edit/${story.modules[moduleId].contentType}/${moduleId}`; - history.push(route)}} + getEditUrl={moduleId => `/teacher/dashboard/${story.id}/edit/${story.modules[moduleId].contentType}/${moduleId}`} canDelete={!isDirty && !isModuleLoading} canChangeOrder={!isModuleLoading && !isUploadingModules} canSaveOrReset={isDirty && !isUploadingModules}