Skip to content

Commit a94fc9b

Browse files
committed
fix: type checks and image-field handling
1 parent 1babc76 commit a94fc9b

6 files changed

Lines changed: 24 additions & 20 deletions

File tree

src/course-unit/add-component/AddComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ const AddComponent = ({
188188
});
189189
break;
190190
case COMPONENT_TYPES.games:
191-
handleCreateNewCourseXBlock({ type: type, category: type, parentLocator: blockId });
191+
handleCreateNewCourseXBlock({ type, category: type, parentLocator: blockId });
192192
break;
193193
default:
194194
}

src/editors/containers/GameEditor/index.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
MoreHoriz,
2929
Check,
3030
} from '@openedx/paragon/icons';
31+
import { getConfig } from '@edx/frontend-platform';
3132
import {
3233
actions,
3334
selectors,
@@ -42,7 +43,6 @@ import SettingsOption from '../ProblemEditor/components/EditProblemView/Settings
4243
import Button from '../../sharedComponents/Button';
4344
import DraggableList, { SortableItem } from '../../../generic/DraggableList';
4445
import messages from './messages';
45-
import { getConfig } from '@edx/frontend-platform';
4646

4747
export const hooks = {
4848
getContent: ({ type, settings, list }) => ({
@@ -142,9 +142,7 @@ export const GameEditor = ({
142142

143143
// Backward compatible wrappers
144144
const saveTermImage = (index) => handleImageUpload(index, 'term');
145-
const removeTermImage = (index) => handleImageRemove(index, 'term');
146145
const saveDefinitionImage = (index) => handleImageUpload(index, 'definition');
147-
const removeDefintionImage = (index) => handleImageRemove(index, 'definition');
148146

149147
const moveCardUp = (index) => {
150148
if (index === 0) { return; }

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const triggerCourseRefresh = () => {
133133
*/
134134
export const saveBlock = (content, returnToUnit) => (dispatch, getState) => {
135135
dispatch(actions.app.setBlockContent(content));
136-
136+
137137
// Games block uses a custom handler for saving
138138
const blockType = selectors.blockType(getState());
139139
if (blockType === 'games' && content.gameType) {
@@ -147,7 +147,6 @@ export const saveBlock = (content, returnToUnit) => (dispatch, getState) => {
147147
returnToUnit(response.data);
148148
},
149149
onFailure: (error) => {
150-
console.error('Failed to save games settings:', error);
151150
dispatch(actions.requests.failRequest({
152151
requestKey: RequestKeys.saveBlock,
153152
error,
@@ -156,7 +155,7 @@ export const saveBlock = (content, returnToUnit) => (dispatch, getState) => {
156155
}));
157156
return;
158157
}
159-
158+
160159
// Standard save for other block types
161160
dispatch(requests.saveBlock({
162161
content,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('app thunkActions', () => {
3636
let getState;
3737
beforeEach(() => {
3838
dispatch = jest.fn((action) => ({ dispatch: action }));
39-
getState = jest.fn().mockImplementation(() => ({ app: { blockId: 'blockId', images: {} } }));
39+
getState = jest.fn().mockImplementation(() => ({ app: { blockId: 'blockId', blockType: 'html', images: {} } }));
4040
});
4141
describe('fetchBlock', () => {
4242
beforeEach(() => {
@@ -339,7 +339,7 @@ describe('app thunkActions', () => {
339339
let calls;
340340
beforeEach(() => {
341341
returnToUnit = jest.fn();
342-
thunkActions.saveBlock(testValue, returnToUnit)(dispatch);
342+
thunkActions.saveBlock(testValue, returnToUnit)(dispatch, getState);
343343
calls = dispatch.mock.calls;
344344
});
345345
it('dispatches actions.app.setBlockContent with content, before dispatching saveBlock', () => {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const actions = {
1515
export const loadGamesSettings = () => (dispatch) => {
1616
dispatch(requests.getGamesSettings({
1717
onSuccess: (response) => {
18-
const data = response.data;
18+
const { data } = response;
1919

2020
if (data.game_type) {
2121
dispatch(actions.game.updateType(data.game_type));
@@ -50,7 +50,6 @@ export const loadGamesSettings = () => (dispatch) => {
5050
}
5151
},
5252
onFailure: (error) => {
53-
console.error('Failed to load game settings:', error);
5453
dispatch(actions.requests.failRequest({
5554
requestKey: RequestKeys.fetchBlock,
5655
error,
@@ -72,15 +71,14 @@ export const uploadGameImage = ({ index, imageFile, imageType }) => (dispatch) =
7271
// Extract the URL from the response
7372
// Response format: { success: true, url: "/media/games/...", filename: "..." }
7473
const imageUrl = response.data?.url;
75-
74+
7675
if (imageType === 'term') {
7776
dispatch(actions.game.updateTermImage({ index, termImage: imageUrl }));
7877
} else if (imageType === 'definition') {
7978
dispatch(actions.game.updateDefinitionImage({ index, definitionImage: imageUrl }));
8079
}
8180
},
8281
onFailure: (error) => {
83-
console.error('Failed to upload game image:', error);
8482
dispatch(actions.requests.failRequest({
8583
requestKey: RequestKeys.uploadAsset,
8684
error,

src/editors/data/services/cms/api.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,22 @@ export const apiMethods = {
427427
hasTimer,
428428
}) => {
429429
// Transform cards to include order and format properly
430-
const formattedCards = cards.map((card, index) => ({
431-
term: card.term || '',
432-
term_image: card.term_image || '',
433-
definition: card.definition || '',
434-
definition_image: card.definition_image || '',
435-
order: index + 1,
436-
}));
430+
// For matching games, exclude image fields
431+
const formattedCards = cards.map((card, index) => {
432+
const baseCard = {
433+
term: card.term || '',
434+
definition: card.definition || '',
435+
order: index + 1,
436+
};
437+
if (gameType === 'flashcards') {
438+
return {
439+
...baseCard,
440+
term_image: card.term_image || '',
441+
definition_image: card.definition_image || '',
442+
};
443+
}
444+
return baseCard;
445+
});
437446

438447
const payload: any = {
439448
game_type: gameType,

0 commit comments

Comments
 (0)