From 6a5208ef67627b8e15d40dbecb7b2320ee7dc2fd Mon Sep 17 00:00:00 2001 From: David Disu Date: Fri, 11 Feb 2022 12:12:39 +0100 Subject: [PATCH 1/2] Show error message when localstorage is full and restore default file content. --- apps/remix-ide/src/app/files/fileManager.ts | 18 ++++++++++++++++-- .../helper/src/lib/helper-components.tsx | 9 +++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index d9789f4512..c137776a24 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -4,7 +4,7 @@ import * as packageJson from '../../../../../package.json' import Registry from '../state/registry' import { EventEmitter } from 'events' import { RemixAppManager } from '../../../../../libs/remix-ui/plugin-manager/src/types' -import { fileChangedToastMsg } from '@remix-ui/helper' +import { fileChangedToastMsg, storageFullMessage } from '@remix-ui/helper' import helper from '../../lib/helper.js' /* @@ -715,8 +715,22 @@ class FileManager extends Plugin { if ((input !== null) && (input !== undefined)) { const provider = this.fileProviderOf(currentFile) if (provider) { - await provider.set(currentFile, input) + // use old content as default if save operation fails. + provider.get(currentFile, (error, oldContent) => { + provider.set(currentFile, input, (error) => { + if (error) { + if (error.message ) this.call('notification', 'toast', + error.message.indexOf( + 'LocalStorage is full') !== -1 ? storageFullMessage() + : error.message + ) + provider.set(currentFile, oldContent) + return console.error(error) + } else { this.emit('fileSaved', currentFile) + } + }) + }) } else { console.log('cannot save ' + currentFile + '. Does not belong to any explorer') } diff --git a/libs/remix-ui/helper/src/lib/helper-components.tsx b/libs/remix-ui/helper/src/lib/helper-components.tsx index edd85b1b31..67ff3cae03 100644 --- a/libs/remix-ui/helper/src/lib/helper-components.tsx +++ b/libs/remix-ui/helper/src/lib/helper-components.tsx @@ -69,3 +69,12 @@ export const envChangeNotification = (env: { context: string, fork: string }, fr ) + +export const storageFullMessage = () => ( +
+ + + Cannot save this file due full LocalStorage. Backup existing files and free up some space. + +
+) From 080dba58d7fa8300c35fccc383710303ce81eaa1 Mon Sep 17 00:00:00 2001 From: David Disu Date: Mon, 14 Feb 2022 11:17:35 +0100 Subject: [PATCH 2/2] Update toaster message --- libs/remix-ui/helper/src/lib/helper-components.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/helper/src/lib/helper-components.tsx b/libs/remix-ui/helper/src/lib/helper-components.tsx index 67ff3cae03..a71950315e 100644 --- a/libs/remix-ui/helper/src/lib/helper-components.tsx +++ b/libs/remix-ui/helper/src/lib/helper-components.tsx @@ -74,7 +74,7 @@ export const storageFullMessage = () => (
- Cannot save this file due full LocalStorage. Backup existing files and free up some space. + Cannot save this file due to full LocalStorage. Backup existing files and free up some space.
)