Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: probably detect changes
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman committed Oct 23, 2023
1 parent 55022af commit 556a4bd
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions packages/core/src/reducers/entryDraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,13 @@ function entryDraftReducer(
}

case DRAFT_UPDATE: {
let newState = { ...state };
if (!newState.entry) {
if (!state.entry) {
return state;
}

const { data } = action.payload;

newState = {
...newState,
entry: {
...newState.entry,
data,
},
};
const newState = set(state, 'entry.data', data);

let hasChanged =
!isEqual(newState.entry?.meta, newState.original?.meta) ||
Expand All @@ -194,8 +187,7 @@ function entryDraftReducer(
}

case DRAFT_CHANGE_FIELD: {
let newState = { ...state };
if (!newState.entry) {
if (!state.entry) {
return state;
}

Expand All @@ -204,26 +196,21 @@ function entryDraftReducer(
? ['meta']
: (i18n && getDataPath(i18n.currentLocale, i18n.defaultLocale)) || ['data'];

const newEntry = cloneDeep(newState.entry);

newState = {
...newState,
entry: set(newEntry, `${dataPath.join('.')}.${path}`, value),
};
let newState = set(state, `entry.${dataPath.join('.')}.${path}`, value);

if (i18n) {
newState = duplicateI18nFields(newState, field, i18n.locales, i18n.defaultLocale, path);
}

let hasChanged =
!isEqual(newEntry?.meta, newState.original?.meta) ||
!isEqual(newEntry?.data, newState.original?.data);
!isEqual(newState.entry?.meta, newState.original?.meta) ||
!isEqual(newState.entry?.data, newState.original?.data);

const i18nData = newEntry?.i18n ?? {};
const i18nData = newState.entry?.i18n ?? {};
for (const locale in i18nData) {
hasChanged =
hasChanged ||
!isEqual(newEntry?.i18n?.[locale]?.data, newState.original?.i18n?.[locale]?.data);
!isEqual(newState.entry?.i18n?.[locale]?.data, newState.original?.i18n?.[locale]?.data);
}

return {
Expand Down

0 comments on commit 556a4bd

Please sign in to comment.