Skip to content

Commit

Permalink
Merge pull request #1741 from RodriSanchez1/fix/syncCommunicator
Browse files Browse the repository at this point in the history
Fix/syncCommunicator
  • Loading branch information
RodriSanchez1 authored Jul 23, 2024
2 parents 2be728b + 9b74df2 commit c85429f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/Communicator/Communicator.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export function syncCommunicators(remoteCommunicators) {
return remote;
}
}
return remote;
return local;
};
const getActiveCommunicator = getState => {
return getState().communicator.communicators.find(
Expand All @@ -343,6 +343,7 @@ export function syncCommunicators(remoteCommunicators) {
return async (dispatch, getState) => {
const localCommunicators = getState().communicator.communicators;
const updatedCommunicators = [...localCommunicators];
const activeCommunicatorId = getActiveCommunicator(getState).id ?? null;

for (const remote of remoteCommunicators) {
const localIndex = localCommunicators.findIndex(
Expand All @@ -355,8 +356,11 @@ export function syncCommunicators(remoteCommunicators) {
localCommunicators[localIndex],
remote
);
if (reconciled === localCommunicators[localIndex]) {
// Local is more recent, update the server
if (
reconciled === localCommunicators[localIndex] &&
activeCommunicatorId === localCommunicators[localIndex].id
) {
// Local active communicator is recent, update the server
try {
const res = await dispatch(
updateApiCommunicator(localCommunicators[localIndex])
Expand All @@ -374,10 +378,11 @@ export function syncCommunicators(remoteCommunicators) {
}
}

const activeCommunicatorId = getActiveCommunicator(getState).id ?? null;
const lastRemoteSavedCommunicatorId = remoteCommunicators[0].id ?? null; //The last communicator saved on the server
const needToChangeActiveCommunicator =
activeCommunicatorId !== lastRemoteSavedCommunicatorId &&
activeCommunicatorId === defaultCommunicatorID &&
// activeCommunicatorId !== lastRemoteSavedCommunicatorId &&
// TODO - Fix mulitple communicators creation on the server
updatedCommunicators.length &&
lastRemoteSavedCommunicatorId &&
updatedCommunicators.findIndex(
Expand Down

0 comments on commit c85429f

Please sign in to comment.