Skip to content

Commit 9da3cd0

Browse files
Merge branch 'master' into fix/textExportPDF
2 parents fe43b7b + fe22ed2 commit 9da3cd0

27 files changed

+440
-136
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
"keycode": "^2.2.1",
5252
"lodash": "^4.17.21",
5353
"mathjs": "7.6.0",
54-
"microsoft-cognitiveservices-speech-sdk": "^1.31.0",
54+
"microsoft-cognitiveservices-speech-sdk": "^1.32.0",
5555
"mime-types": "^2.1.35",
5656
"moment": "2.29.4",
57-
"mongoose": "^6.11.4",
57+
"mongoose": "^6.12.0",
5858
"ogv": "^1.8.9",
5959
"opencollective": "^1.0.3",
6060
"pdfmake": "^0.2.7",
@@ -69,7 +69,7 @@
6969
"react-dom": "^17.0.2",
7070
"react-grid-layout": "^0.16.6",
7171
"react-helmet": "^6.1.0",
72-
"react-icons": "^4.10.1",
72+
"react-icons": "^4.11.0",
7373
"react-intl": "^2.7.2",
7474
"react-joyride": "^2.5.4",
7575
"react-markdown": "^5.0.3",

src/api/api.js

+27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { isAndroid } from '../cordova-util';
1616

1717
const BASE_URL = API_URL;
1818
const LOCAL_COMMUNICATOR_ID = 'cboard_default';
19+
export let improvePhraseAbortController;
1920

2021
const getUserData = () => {
2122
const store = getStore();
@@ -626,6 +627,32 @@ class API {
626627
return data;
627628
}
628629
}
630+
631+
async improvePhrase({ phrase, language }) {
632+
const authToken = getAuthToken();
633+
if (!(authToken && authToken.length)) {
634+
throw new Error('Need to be authenticated to perform this request');
635+
}
636+
637+
try {
638+
const headers = {
639+
Authorization: `Bearer ${authToken}`
640+
};
641+
improvePhraseAbortController = new AbortController();
642+
const { data } = await this.axiosInstance.post(
643+
`/gpt/edit`,
644+
{ phrase, language },
645+
{
646+
headers,
647+
signal: improvePhraseAbortController.signal
648+
}
649+
);
650+
return data;
651+
} catch (error) {
652+
if (error.message !== 'canceled') console.error(error);
653+
return { phrase: '' };
654+
}
655+
}
629656
}
630657

631658
const API_INSTANCE = new API({});

src/components/Account/SignUp/SignUp.actions.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@ import { API_URL } from '../../../constants';
55

66
export function signUp(formValues) {
77
const endpoint = `${API_URL}user`;
8-
return axios
9-
.post(endpoint, formValues)
10-
.then(get('data'))
11-
.catch(get('response.data'));
8+
return axios.post(endpoint, formValues).then(get('data'));
129
}

src/components/Account/SignUp/SignUp.component.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ export class SignUp extends Component {
5252

5353
signUp(formValues)
5454
.then(signUpStatus => this.setState({ signUpStatus }))
55-
.catch(signUpStatus => this.setState({ signUpStatus }))
55+
.catch(error => {
56+
const responseMessage = error?.response?.data?.message;
57+
const message = responseMessage
58+
? responseMessage
59+
: this.props.intl.formatMessage(messages.noConnection);
60+
61+
this.setState({
62+
signUpStatus: { success: false, message: message }
63+
});
64+
})
5665
.finally(() => this.setState({ isSigningUp: false }));
5766
};
5867

src/components/Account/SignUp/SignUp.messages.js

+4
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ export default defineMessages({
4040
privacy: {
4141
id: 'cboard.components.SignUp.privacy',
4242
defaultMessage: 'Privacy Policy'
43+
},
44+
noConnection: {
45+
id: 'cboard.components.SignUp.noConnection',
46+
defaultMessage: 'Unable to connect to the server. Please try again later.'
4347
}
4448
});

src/components/App/App.reducer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const initialState = {
5050
quickUnlockActive: false,
5151
removeOutputActive: false,
5252
vocalizeFolders: false,
53-
liveMode: false
53+
liveMode: false,
54+
improvePhraseActive: false
5455
},
5556
symbolsSettings: {
5657
arasaacActive: false

src/components/App/__tests__/App.reducer.test.js

+21-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
FINISH_FIRST_VISIT,
77
UPDATE_CONNECTIVITY,
88
UPDATE_DISPLAY_SETTINGS,
9-
UPDATE_NAVIGATION_SETTINGS,
9+
UPDATE_NAVIGATION_SETTINGS
1010
} from '../App.constants';
1111
import appReducer from '../App.reducer';
1212

@@ -24,9 +24,9 @@ describe('reducer', () => {
2424
communicatorTour: {
2525
isCommBoardsEnabled: true,
2626
isPublicBoardsEnabled: true,
27-
isAllMyBoardsEnabled: true,
27+
isAllMyBoardsEnabled: true
2828
},
29-
isAnalyticsTourEnabled: true,
29+
isAnalyticsTourEnabled: true
3030
},
3131
displaySettings: {
3232
uiSize: DISPLAY_SIZE_STANDARD,
@@ -35,7 +35,7 @@ describe('reducer', () => {
3535
hideOutputActive: false,
3636
increaseOutputButtons: false,
3737
labelPosition: 'Below',
38-
darkThemeActive: false,
38+
darkThemeActive: false
3939
},
4040
navigationSettings: {
4141
active: false,
@@ -47,11 +47,12 @@ describe('reducer', () => {
4747
quickUnlockActive: false,
4848
removeOutputActive: false,
4949
vocalizeFolders: false,
50+
improvePhraseActive: false
5051
},
5152
symbolsSettings: {
52-
arasaacActive: false,
53+
arasaacActive: false
5354
},
54-
userData: {},
55+
userData: {}
5556
};
5657
uData = { name: 'martin bedouret', email: '[email protected]' };
5758
mockApp = {
@@ -62,7 +63,7 @@ describe('reducer', () => {
6263
labelPosition: 'Below',
6364
fontFamily: DEFAULT_FONT_FAMILY,
6465
fontSize: 'Standard',
65-
darkThemeActive: false,
66+
darkThemeActive: false
6667
},
6768
isConnected: true,
6869
isFirstVisit: false,
@@ -76,8 +77,9 @@ describe('reducer', () => {
7677
quickUnlockActive: false,
7778
removeOutputActive: false,
7879
vocalizeFolders: false,
80+
improvePhraseActive: false
7981
},
80-
userData: uData,
82+
userData: uData
8183
};
8284
});
8385
it('should return the initial state', () => {
@@ -86,57 +88,57 @@ describe('reducer', () => {
8688
it('should handle login ', () => {
8789
const login = {
8890
type: LOGIN_SUCCESS,
89-
payload: uData,
91+
payload: uData
9092
};
9193
expect(appReducer(initialState, login)).toEqual({
9294
...initialState,
9395
userData: uData,
94-
isFirstVisit: false,
96+
isFirstVisit: false
9597
});
9698
});
9799
it('should handle logout', () => {
98100
const logout = {
99-
type: LOGOUT,
101+
type: LOGOUT
100102
};
101103
expect(appReducer(initialState, logout)).toEqual(initialState);
102104
});
103105
it('should handle updateDisplaySettings', () => {
104106
const updateDisplaySettings = {
105107
type: UPDATE_DISPLAY_SETTINGS,
106-
payload: mockApp.displaySettings,
108+
payload: mockApp.displaySettings
107109
};
108110
expect(appReducer(initialState, updateDisplaySettings)).toEqual({
109111
...initialState,
110-
displaySettings: mockApp.displaySettings,
112+
displaySettings: mockApp.displaySettings
111113
});
112114
});
113115
it('should handle updateNavigationSettings', () => {
114116
const updateNavigationSettings = {
115117
type: UPDATE_NAVIGATION_SETTINGS,
116-
payload: mockApp.navigationSettings,
118+
payload: mockApp.navigationSettings
117119
};
118120
expect(appReducer(initialState, updateNavigationSettings)).toEqual({
119121
...initialState,
120-
navigationSettings: mockApp.navigationSettings,
122+
navigationSettings: mockApp.navigationSettings
121123
});
122124
});
123125
it('should handle finishFirstVisit ', () => {
124126
const finishFirstVisit = {
125-
type: FINISH_FIRST_VISIT,
127+
type: FINISH_FIRST_VISIT
126128
};
127129
expect(appReducer(initialState, finishFirstVisit)).toEqual({
128130
...initialState,
129-
isFirstVisit: false,
131+
isFirstVisit: false
130132
});
131133
});
132134
it('should handle updateConnectivity', () => {
133135
const updateConnectivity = {
134136
type: UPDATE_CONNECTIVITY,
135-
payload: false,
137+
payload: false
136138
};
137139
expect(appReducer(initialState, updateConnectivity)).toEqual({
138140
...initialState,
139-
isConnected: false,
141+
isConnected: false
140142
});
141143
});
142144
});

src/components/Board/Board.actions.js

+38-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
CLICK_SYMBOL,
1818
CLICK_OUTPUT,
1919
CHANGE_OUTPUT,
20+
CHANGE_IMPROVED_PHRASE,
2021
CHANGE_LIVE_MODE,
2122
REPLACE_BOARD,
2223
HISTORY_REMOVE_BOARD,
@@ -55,6 +56,7 @@ import {
5556
import { isAndroid, writeCvaFile } from '../../cordova-util';
5657
import { DEFAULT_BOARDS } from '../../helpers';
5758
import history from './../../history';
59+
import { improvePhraseAbortController } from '../../api/api';
5860

5961
const BOARDS_PAGE_LIMIT = 100;
6062

@@ -324,9 +326,42 @@ export function clickOutput(outputPhrase) {
324326
}
325327

326328
export function changeOutput(output) {
327-
return {
328-
type: CHANGE_OUTPUT,
329-
output
329+
return async (dispatch, getState) => {
330+
const {
331+
app: {
332+
navigationSettings: { improvePhraseActive }
333+
}
334+
} = getState();
335+
if (improvePhraseActive) dispatch(improvePhrase(output));
336+
dispatch({
337+
type: CHANGE_OUTPUT,
338+
output
339+
});
340+
};
341+
}
342+
343+
export function improvePhrase(output) {
344+
const fetchImprovePhrase = async language => {
345+
const MIN_TILES_TO_IMPROVE = 1;
346+
if (output.length <= MIN_TILES_TO_IMPROVE) return '';
347+
const labels = output.map(symbol => symbol.label);
348+
const phrase = labels.join(' '); //this.handlePhraseToShare();
349+
const improvedPhrase = await API.improvePhrase({ phrase, language });
350+
return improvedPhrase.phrase;
351+
};
352+
return async (dispatch, getState) => {
353+
try {
354+
const language = getState().language.lang;
355+
if (improvePhraseAbortController?.abort)
356+
improvePhraseAbortController.abort();
357+
const improvedPhrase = await fetchImprovePhrase(language);
358+
dispatch({
359+
type: CHANGE_IMPROVED_PHRASE,
360+
improvedPhrase
361+
});
362+
} catch (err) {
363+
console.error('error', err);
364+
}
330365
};
331366
}
332367

src/components/Board/Board.component.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import './Board.css';
3434
import BoardTour from './BoardTour/BoardTour';
3535
import ScrollButtons from '../ScrollButtons';
3636
import { NAVIGATION_BUTTONS_STYLE_SIDES } from '../Settings/Navigation/Navigation.constants';
37+
import ImprovePhraseOutput from './ImprovePhraseOutput';
3738

3839
export class Board extends Component {
3940
static propTypes = {
@@ -315,7 +316,9 @@ export class Board extends Component {
315316
setIsScroll,
316317
isScroll,
317318
totalRows,
318-
changeDefaultBoard
319+
changeDefaultBoard,
320+
improvedPhrase,
321+
speak
319322
} = this.props;
320323

321324
const tiles = this.renderTiles(board.tiles);
@@ -524,7 +527,12 @@ export class Board extends Component {
524527
/>
525528
)}
526529
</div>
527-
530+
{navigationSettings.improvePhraseActive && (
531+
<ImprovePhraseOutput
532+
improvedPhrase={improvedPhrase}
533+
speak={speak}
534+
/>
535+
)}
528536
<Dialog
529537
open={this.state.openTitleDialog}
530538
aria-labelledby="board-dialog-title"

src/components/Board/Board.constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const FOCUS_TILE = 'cboard/Board/FOCUS_TILE';
1515
export const CLICK_SYMBOL = 'cboard/Board/CLICK_SYMBOL';
1616
export const CLICK_OUTPUT = 'cboard/Board/CLICK_OUTPUT';
1717
export const CHANGE_OUTPUT = 'cboard/Board/CHANGE_OUTPUT';
18+
export const CHANGE_IMPROVED_PHRASE = 'cboard/Board/CHANGE_IMPROVED_PHRASE';
1819
export const CHANGE_LIVE_MODE = 'cboard/Board/CHANGE_LIVE_MODE';
1920
export const HISTORY_REMOVE_BOARD = 'cboard/Board/HISTORY_REMOVE_BOARD';
2021
export const UNMARK_BOARD = 'cboard/Board/UNMARK_BOARD';

src/components/Board/Board.container.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,9 @@ export class BoardContainer extends Component {
15401540
navHistory,
15411541
board,
15421542
focusTile,
1543-
isPremiumRequiredModalOpen
1543+
isPremiumRequiredModalOpen,
1544+
improvedPhrase,
1545+
speak
15441546
} = this.props;
15451547

15461548
if (!this.state.translatedBoard) {
@@ -1614,6 +1616,8 @@ export class BoardContainer extends Component {
16141616
totalRows={this.state.totalRows}
16151617
ref={this.boardRef}
16161618
changeDefaultBoard={this.props.changeDefaultBoard}
1619+
improvedPhrase={improvedPhrase}
1620+
speak={speak}
16171621
/>
16181622
<Dialog
16191623
open={!!this.state.copyPublicBoard && !isPremiumRequiredModalOpen}
@@ -1726,7 +1730,8 @@ const mapStateToProps = ({
17261730
offlineVoiceAlert,
17271731
isRootBoardTourEnabled: liveHelp.isRootBoardTourEnabled,
17281732
isUnlockedTourEnabled: liveHelp.isUnlockedTourEnabled,
1729-
isPremiumRequiredModalOpen: premiumRequiredModalState?.open
1733+
isPremiumRequiredModalOpen: premiumRequiredModalState?.open,
1734+
improvedPhrase: board.improvedPhrase
17301735
};
17311736
};
17321737

0 commit comments

Comments
 (0)