From 6a5208ef67627b8e15d40dbecb7b2320ee7dc2fd Mon Sep 17 00:00:00 2001 From: David Disu Date: Fri, 11 Feb 2022 12:12:39 +0100 Subject: [PATCH 1/3] 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/3] 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.
) From bb949c952e395c882b4c6bddc05f5502bdabd274 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Mon, 21 Feb 2022 19:18:38 +0100 Subject: [PATCH 3/3] Update ResultFileName.tsx --- .../search/src/lib/components/results/ResultFileName.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx index d4cf2e4304..5d6412af25 100644 --- a/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx +++ b/libs/remix-ui/search/src/lib/components/results/ResultFileName.tsx @@ -13,8 +13,6 @@ export const ResultFileName = (props: ResultItemProps) => { if (props.file && props.file.path) { setIcon(getPathIcon(props.file.path)) } - // remove path from string - // const path = props.file.path.split('/').slice(0, -1).join('/') }, [props.file]) return (