Skip to content

Commit 713339c

Browse files
Muhammad Faraz  MaqsoodMuhammad Faraz  Maqsood
authored andcommitted
fix: publish btn doesn't show after component edit
When we edit & save the component, publish button doesn't show up until we refresh the page manualy or open this unit by opening previous unit and coming back to this unit again. In this commit, we are dispatching a storage event whenever we edit the component, it'll refresh the page & show the publish button as expected.
1 parent aeefcc6 commit 713339c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/course-unit/hooks.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,21 @@ export const useCourseUnit = ({ courseId, blockId }) => {
213213
}
214214
}, [isMoveModalOpen]);
215215

216+
useEffect(() => {
217+
const handlePageRefreshUsingStorage = (event) => {
218+
if (event.key === 'courseRefreshTriggerOnComponentEditSave') {
219+
dispatch(fetchCourseSectionVerticalData(blockId, sequenceId));
220+
dispatch(fetchCourseVerticalChildrenData(blockId, isSplitTestType));
221+
localStorage.removeItem(event.key);
222+
}
223+
};
224+
225+
window.addEventListener('storage', handlePageRefreshUsingStorage);
226+
return () => {
227+
window.removeEventListener('storage', handlePageRefreshUsingStorage);
228+
};
229+
}, [blockId, sequenceId, isSplitTestType]);
230+
216231
return {
217232
sequenceId,
218233
courseUnit,

src/editors/data/redux/thunkActions/app.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ export const saveBlock = (content, returnToUnit) => (dispatch) => {
125125
content,
126126
onSuccess: (response) => {
127127
dispatch(actions.app.setSaveResponse(response));
128+
const parsedData = JSON.parse(response.config.data);
129+
if (parsedData?.has_changes) {
130+
const storageKey = 'courseRefreshTriggerOnComponentEditSave';
131+
localStorage.setItem(storageKey, Date.now());
132+
133+
window.dispatchEvent(new StorageEvent('storage', {
134+
key: storageKey,
135+
newValue: Date.now().toString(),
136+
}));
137+
}
128138
returnToUnit(response.data);
129139
},
130140
}));

0 commit comments

Comments
 (0)