Re-enable the celebration modal (#123)
It got accidentally disabled during a refactor. Also, try a little harder to make sure it doesn't re-appear during the same browsing session.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
import { AlertList } from '../../generic/user-messages';
|
||||
@@ -52,8 +53,9 @@ function Course({
|
||||
verifiedMode,
|
||||
} = course;
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const celebrateFirstSection = celebrations && celebrations.firstSection;
|
||||
const celebrationOpen = shouldCelebrateOnSectionLoad(courseId, sequenceId, unitId, celebrateFirstSection);
|
||||
const celebrationOpen = shouldCelebrateOnSectionLoad(courseId, sequenceId, unitId, celebrateFirstSection, dispatch);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
|
||||
|
||||
import { postFirstSectionCelebrationComplete } from './data/api';
|
||||
import { clearLocalStorage, getLocalStorage, setLocalStorage } from '../../../data/localStorage';
|
||||
import { updateModel } from '../../../generic/model-store';
|
||||
|
||||
const CELEBRATION_LOCAL_STORAGE_KEY = 'CelebrationModal.showOnSectionLoad';
|
||||
|
||||
@@ -29,7 +30,7 @@ function recordFirstSectionCelebration(courseId) {
|
||||
|
||||
// Looks at local storage to see whether we just came from the end of a section.
|
||||
// Note! This does have side effects (will clear some local storage and may start an api call).
|
||||
function shouldCelebrateOnSectionLoad(courseId, sequenceId, unitId, celebrateFirstSection) {
|
||||
function shouldCelebrateOnSectionLoad(courseId, sequenceId, unitId, celebrateFirstSection, dispatch) {
|
||||
const celebrationIds = getLocalStorage(CELEBRATION_LOCAL_STORAGE_KEY);
|
||||
if (!celebrationIds) {
|
||||
return false;
|
||||
@@ -46,6 +47,17 @@ function shouldCelebrateOnSectionLoad(courseId, sequenceId, unitId, celebrateFir
|
||||
if (sequenceId !== prevSequenceId && !onTargetUnit) {
|
||||
// Don't clear until we move off of current/prev sequence
|
||||
clearLocalStorage(CELEBRATION_LOCAL_STORAGE_KEY);
|
||||
|
||||
// Update our local copy of course data from LMS
|
||||
dispatch(updateModel({
|
||||
modelType: 'courses',
|
||||
model: {
|
||||
id: courseId,
|
||||
celebrations: {
|
||||
firstSection: false,
|
||||
},
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
return shouldCelebrate;
|
||||
|
||||
Reference in New Issue
Block a user