import { call , select } from 'redux-saga/effects' ; import { ReadPersistedState , WritePersistedState } from '../actions/backup' ; import { persistedStateToJsonString , generateBackupBlob , createTemporaryDownloadLink , writeToPersistedState , downloadTemporaryAnchor , keepOnlyCheckedStateKeys } from '../utils/backup' ; import { failedImportPersistedState , failedDownloadStateToast , successfulDownloadStateToast } from '../utils/toaster' ; import { PersistedState } from '../types' ; import { refreshPage } from '../utils/refresh' ; import { uploadedStateSelector } from '../selectors/index' ; export function * downloadPersistedState ( action ) { try { const stateString = yield call ( persistedStateToJsonString ) ; const persistedStateBlob = generateBackupBlob ( stateString ) ; const temporaryAnchor = createTemporaryDownloadLink ( persistedStateBlob ) ; downloadTemporaryAnchor ( temporaryAnchor ) ; successfulDownloadStateToast ( ) ; } catch ( e ) { console . warn ( e ) ; failedDownloadStateToast ( ) ; } } export function * importPersistedState ( action ) { try { const uploadedState = yield select ( uploadedStateSelector ) ; const stateToImport = keepOnlyCheckedStateKeys ( action . whiteList ) ( uploadedState ) ; yield call ( writeToPersistedState , stateToImport ) ; refreshPage ( ) ; } catch ( e ) { console . warn ( e ) ; failedImportPersistedState ( ) ; } }