Skip to content

Commit

Permalink
fix: sending duplicate translate request with same text
Browse files Browse the repository at this point in the history
  • Loading branch information
chunibyocola committed Apr 15, 2021
1 parent 1f1bb93 commit 84acec1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/redux/reducers/multipleTranslateState.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ const multipleTranslateState = (state = initState, { type, payload }) => {
case types.MT_REMOVE_SOURCE:
return { ...state, translations: state.translations.filter(v => v.source !== payload.source) };
case types.MT_SET_TEXT:
return {
return payload.text !== state.text ? {
...state,
text: payload.text,
translations: state.translations.map(v => ({
...v,
status: { requesting: false, requestEnd: false, error: false }
})),
translateId: state.translateId + 1
};
} : state;
case types.MT_REQUEST_START:
return { ...state, translations: state.translations.map((v) => {
if (v.source === payload.source) {
Expand Down
52 changes: 45 additions & 7 deletions src/redux/reducers/singleTranslateState.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,57 @@ const initState = {
const singleTranslateState = (state = initState, { type, payload }) => {
switch (type) {
case types.ST_SET_TEXT:
return { ...state, status: { requesting: false, requestEnd: false, error: false }, text: payload.text, resultFromHistory: false, translateId: state.translateId + 1 };
return payload.text !== state.text ? {
...state,
status: { requesting: false, requestEnd: false, error: false },
text: payload.text,
resultFromHistory: false, translateId: state.translateId + 1
} : state;
case types.ST_REQUEST_START:
return { ...state, status: { requesting: true, requestEnd: false, error: false }, result: {}, resultFromHistory: false };
return {
...state,
status: { requesting: true, requestEnd: false, error: false },
result: {},
resultFromHistory: false
};
case types.ST_REQUEST_FINISH:
return { ...state, status: { requesting: false, requestEnd: true, error: false }, result: payload.result, resultFromHistory: false };
return {
...state,
status: { requesting: false, requestEnd: true, error: false },
result: payload.result,
resultFromHistory: false
};
case types.ST_REQUEST_ERROR:
return { ...state, status: { requesting: false, requestEnd: true, error: true, errorCode: payload.errorCode }, result: {}, resultFromHistory: false };
return {
...state,
status: { requesting: false, requestEnd: true, error: true, errorCode: payload.errorCode },
result: {},
resultFromHistory: false
};
case types.ST_SET_FROM_AND_TO:
return { ...state, status: { requesting: false, requestEnd: false, error: false }, from: payload.from, to: payload.to, translateId: state.translateId + 1 };
return {
...state,
status: { requesting: false, requestEnd: false, error: false },
from: payload.from,
to: payload.to,
translateId: state.translateId + 1
};
case types.ST_INIT:
return { ...state, source: payload.source, from: payload.from, to: payload.to };
return {
...state,
source: payload.source,
from: payload.from,
to: payload.to
};
case types.ST_SET_SOURCE_FROM_TO:
return { ...state, status: { requesting: false, requestEnd: false, error: false }, source: payload.source, from: payload.from, to: payload.to, translateId: state.translateId + 1 };
return {
...state,
status: { requesting: false, requestEnd: false, error: false },
source: payload.source,
from: payload.from,
to: payload.to,
translateId: state.translateId + 1
};
default: return state;
}
};
Expand Down

0 comments on commit 84acec1

Please sign in to comment.