Skip to content

Commit

Permalink
Make sure that in-progress resources are up-to-date after navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
MisRob committed Oct 19, 2021
1 parent 91f439a commit 48b1c97
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions kolibri/core/assets/src/api-resources/contentNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export default new Resource({
fetchRecommendationsFor(id, getParams) {
return this.fetchDetailCollection('recommendations_for', id, getParams);
},
fetchResume(getParams) {
return this.fetchDetailCollection('resume', Store.getters.currentUserId, getParams);
fetchResume(getParams, force) {
return this.fetchDetailCollection('resume', Store.getters.currentUserId, getParams, force);
},
fetchPopular(getParams) {
return this.fetchListCollection('popular', getParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,20 @@ export default function useLearnerResources() {
* Fetches resumable content nodes with their progress data
* and saves data to this composable's store
*
* @param {Boolean} force Cache won't be used when `true`
* @returns {Promise}
* @public
*/
function fetchResumableContentNodes() {
return ContentNodeResource.fetchResume().then(contentNodes => {
function fetchResumableContentNodes({ force = false } = {}) {
return ContentNodeResource.fetchResume({}, force).then(contentNodes => {
if (!contentNodes || !contentNodes.length) {
return [];
}
set(_resumableContentNodes, contentNodes);
const contentNodesIds = contentNodes.map(contentNode => contentNode.id);
return ContentNodeProgressResource.fetchCollection({
getParams: { ids: contentNodesIds },
force,
}).then(progresses => {
if (progresses) {
set(_resumableContentNodesProgresses, progresses);
Expand Down
5 changes: 4 additions & 1 deletion kolibri/plugins/learn/assets/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ export default [
component: HomePage,
handler() {
let promises = [fetchChannels()];
// force resumable content nodes request to make sure that the home
// page is up-to-date in regards to in-progress resources
// when navigating to other 'Learn' pages and then back to the home page
if (get(isUserLoggedIn)) {
promises = [...promises, fetchClasses(), fetchResumableContentNodes()];
promises = [...promises, fetchClasses(), fetchResumableContentNodes({ force: true })];
}
return store.dispatch('loading').then(() => {
return Promise.all(promises)
Expand Down

0 comments on commit 48b1c97

Please sign in to comment.