From 6ca1ff6227c80fd4d086bdf532a9dda5ddbcb53c Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Sun, 19 Jan 2020 20:45:38 +0300 Subject: [PATCH] don't overwrite local document content on upload --- frontend/src/redux/docs/reducer.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/redux/docs/reducer.ts b/frontend/src/redux/docs/reducer.ts index 37a7197..3008163 100644 --- a/frontend/src/redux/docs/reducer.ts +++ b/frontend/src/redux/docs/reducer.ts @@ -34,6 +34,14 @@ const defaultDocsState: IDocsState = { deletedDocument: null, }; +function isDocDirty(doc1: IDocumentJSON, doc2: IDocumentJSON) { + return ( + doc1.content !== doc2.content || + doc1.name !== doc2.name || + doc1.shared !== doc2.shared + ); +} + export const docsReducer: Reducer = ( state: IDocsState = defaultDocsState, action: DocsAction | UserAction, @@ -83,7 +91,11 @@ export const docsReducer: Reducer = ( case DocsTypes.DOCS_UPLOAD_SUCCESS: { const all: { [key: number]: IDocumentEntry } = { ...state.all }; action.payload.all.forEach(doc => { - all[doc.id] = { ...doc, remote: doc, dirty: false }; + if (isDocDirty(all[doc.id], doc)) { + all[doc.id] = { ...all[doc.id], remote: doc, dirty: true }; + } else { + all[doc.id] = { ...all[doc.id], remote: doc, dirty: false }; + } }); return { ...state, all, uploading: false, dirty: false }; }