Skip to content

Commit

Permalink
refactor: use getState once in requests.js functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Jan 29, 2025
1 parent 729780e commit 9f74c07
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/editors/data/redux/thunkActions/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,26 @@ export const importTranscript = ({ youTubeId, ...rest }) => (dispatch, getState)
};

export const deleteTranscript = ({ language, videoId, ...rest }) => (dispatch, getState) => {
const isLibrary = selectors.app.isLibrary(getState());
const state = getState();
const isLibrary = selectors.app.isLibrary(state);
if (isLibrary) {
dispatch(module.networkRequest({
requestKey: RequestKeys.deleteTranscript,
promise: api.deleteTranscriptV2({
language,
videoId,
handlerUrl: selectors.video.transcriptHandlerUrl(getState()),
handlerUrl: selectors.video.transcriptHandlerUrl(state),
}),
...rest,
}));
} else {
dispatch(module.networkRequest({
requestKey: RequestKeys.deleteTranscript,
promise: api.deleteTranscript({
blockId: selectors.app.blockId(getState()),
blockId: selectors.app.blockId(state),
language,
videoId,
studioEndpointUrl: selectors.app.studioEndpointUrl(getState()),
studioEndpointUrl: selectors.app.studioEndpointUrl(state),
}),
...rest,
}));
Expand All @@ -271,12 +272,13 @@ export const uploadTranscript = ({
language,
...rest
}) => (dispatch, getState) => {
const isLibrary = selectors.app.isLibrary(getState());
const state = getState();
const isLibrary = selectors.app.isLibrary(state);
if (isLibrary) {
dispatch(module.networkRequest({
requestKey: RequestKeys.uploadTranscript,
promise: api.uploadTranscriptV2({
handlerUrl: selectors.video.transcriptHandlerUrl(getState()),
handlerUrl: selectors.video.transcriptHandlerUrl(state),
transcript,
videoId,
language,
Expand All @@ -287,11 +289,11 @@ export const uploadTranscript = ({
dispatch(module.networkRequest({
requestKey: RequestKeys.uploadTranscript,
promise: api.uploadTranscript({
blockId: selectors.app.blockId(getState()),
blockId: selectors.app.blockId(state),
transcript,
videoId,
language,
studioEndpointUrl: selectors.app.studioEndpointUrl(getState()),
studioEndpointUrl: selectors.app.studioEndpointUrl(state),
}),
...rest,
}));
Expand All @@ -305,12 +307,13 @@ export const updateTranscriptLanguage = ({
videoId,
...rest
}) => (dispatch, getState) => {
const isLibrary = selectors.app.isLibrary(getState());
const state = getState();
const isLibrary = selectors.app.isLibrary(state);
if (isLibrary) {
dispatch(module.networkRequest({
requestKey: RequestKeys.updateTranscriptLanguage,
promise: api.uploadTranscriptV2({
handlerUrl: selectors.video.transcriptHandlerUrl(getState()),
handlerUrl: selectors.video.transcriptHandlerUrl(state),
transcript: file,
videoId,
language: languageBeforeChange,
Expand All @@ -322,25 +325,26 @@ export const updateTranscriptLanguage = ({
dispatch(module.networkRequest({
requestKey: RequestKeys.updateTranscriptLanguage,
promise: api.uploadTranscript({
blockId: selectors.app.blockId(getState()),
blockId: selectors.app.blockId(state),
transcript: file,
videoId,
language: languageBeforeChange,
newLanguage: newLanguageCode,
studioEndpointUrl: selectors.app.studioEndpointUrl(getState()),
studioEndpointUrl: selectors.app.studioEndpointUrl(state),
}),
...rest,
}));
}
};

export const getTranscriptFile = ({ language, videoId, ...rest }) => (dispatch, getState) => {
const isLibrary = selectors.app.isLibrary(getState());
const state = getState();
const isLibrary = selectors.app.isLibrary(state);
if (isLibrary) {
dispatch(module.networkRequest({
requestKey: RequestKeys.getTranscriptFile,
promise: api.getTranscriptV2({
handlerUrl: selectors.video.transcriptHandlerUrl(getState()),
handlerUrl: selectors.video.transcriptHandlerUrl(state),
videoId,
language,
}),
Expand All @@ -350,8 +354,8 @@ export const getTranscriptFile = ({ language, videoId, ...rest }) => (dispatch,
dispatch(module.networkRequest({
requestKey: RequestKeys.getTranscriptFile,
promise: api.getTranscript({
studioEndpointUrl: selectors.app.studioEndpointUrl(getState()),
blockId: selectors.app.blockId(getState()),
studioEndpointUrl: selectors.app.studioEndpointUrl(state),
blockId: selectors.app.blockId(state),
videoId,
language,
}),
Expand Down

0 comments on commit 9f74c07

Please sign in to comment.