autosave docs #5

This commit is contained in:
2019-08-31 22:10:04 +02:00
parent c95c7f1c9d
commit 00e3bbb9e2
3 changed files with 12 additions and 1 deletions

View File

@@ -115,6 +115,8 @@ export const docsReducer: Reducer<IDocsState, DocsAction> = (
name: payload.name,
dirty: false,
};
const dirtyDocs = Object.values(all).filter(e => e.dirty);
dirty = dirtyDocs.length > 0;
}
return { ...state, all, dirty };
}

View File

@@ -33,6 +33,7 @@ import {
newDocSuccess,
showDocsSpinner,
uploadDocsFail,
uploadDocsStart,
uploadDocsSuccess,
} from "./actions";
@@ -170,6 +171,13 @@ function* docsUploadStart(action: IDocsUploadStartAction) {
}
}
export function* uploadDocsTimer() {
while (true) {
yield docsUploadStart(uploadDocsStart());
yield delay(5000);
}
}
export function* docsSaga() {
yield all([
takeLatest(DocsTypes.DOCS_FETCH_START, docsFetchStart),

View File

@@ -6,7 +6,7 @@ import { rootReducer } from "~redux/reducers";
import { setToken } from "./api/utils";
import { authSaga } from "./auth/sagas";
import { docsSaga } from "./docs/sagas";
import { docsSaga, uploadDocsTimer } from "./docs/sagas";
import { getUser } from "./user/actions";
import { userSaga } from "./user/sagas";
@@ -28,3 +28,4 @@ export const persistor = persistStore(store, null, () => {
sagaMiddleware.run(authSaga);
sagaMiddleware.run(userSaga);
sagaMiddleware.run(docsSaga);
sagaMiddleware.run(uploadDocsTimer);