From 91f8df60a39198be004a73509cf40aefd7c6b4d4 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 12 Dec 2023 12:56:00 +0100 Subject: [PATCH] alwayd delete the code-sample workspace but propose to turn it into a normal workspace --- apps/remix-ide/src/app/files/workspaceFileProvider.js | 7 +++++++ apps/remix-ide/src/app/panels/file-panel.js | 1 + apps/remix-ide/src/app/tabs/locales/en/filePanel.json | 3 ++- libs/remix-ui/workspace/src/lib/actions/index.ts | 8 ++++---- libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx | 10 +++++++++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/remix-ide/src/app/files/workspaceFileProvider.js b/apps/remix-ide/src/app/files/workspaceFileProvider.js index 6193e7b486..6884300f51 100644 --- a/apps/remix-ide/src/app/files/workspaceFileProvider.js +++ b/apps/remix-ide/src/app/files/workspaceFileProvider.js @@ -9,6 +9,13 @@ class WorkspaceFileProvider extends FileProvider { this.workspacesPath = '.workspaces' this.workspace = null this.event = new EventManager() + + try { + // make sure "code-sample" has been removed + window.remixFileSystem.unlink(this.workspacesPath + '/code-sample') + } catch (e) { + console.error(e) + } } setWorkspace (workspace) { diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 7b813aea1c..38950b939a 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -180,6 +180,7 @@ module.exports = class Filepanel extends ViewPlugin { } saveRecent(workspaceName) { + if (workspaceName === 'code-sample') return if (!localStorage.getItem('recentWorkspaces')) { localStorage.setItem('recentWorkspaces', JSON.stringify([ workspaceName ])) } else { diff --git a/apps/remix-ide/src/app/tabs/locales/en/filePanel.json b/apps/remix-ide/src/app/tabs/locales/en/filePanel.json index 44cf82bfe0..556f968536 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/filePanel.json +++ b/apps/remix-ide/src/app/tabs/locales/en/filePanel.json @@ -128,5 +128,6 @@ "filePanel.movingFileFailedMsg": "Unexpected error while moving file: {src}", "filePanel.movingFolderFailed": "Moving Folder Failed", "filePanel.movingFolderFailedMsg": "Unexpected error while moving folder: {src}", - "filePanel.workspaceActions": "Workspace actions" + "filePanel.workspaceActions": "Workspace actions", + "filePanel.saveCodeSample": "This code sample will not be persisted. Please click here to save this code as a persisted workspace." } diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index d6d9d3204d..2285090e6d 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -55,9 +55,9 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. const workspaces = await getWorkspaces() || [] dispatch(setWorkspaces(workspaces)) if (params.gist) { - await createWorkspaceTemplate('gist-sample', 'gist-template') - plugin.setWorkspace({ name: 'gist-sample', isLocalhost: false }) - dispatch(setCurrentWorkspace({ name: 'gist-sample', isGitRepo: false })) + await createWorkspaceTemplate('code-sample', 'gist-template') + plugin.setWorkspace({ name: 'code-sample', isLocalhost: false }) + dispatch(setCurrentWorkspace({ name: 'code-sample', isGitRepo: false })) await loadWorkspacePreset('gist-template') } else if (params.code || params.url) { await createWorkspaceTemplate('code-sample', 'code-template') @@ -82,7 +82,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React. {id: 5, name: 'goerli'} ] let found = false - const workspaceName = 'etherscan-code-sample' + const workspaceName = 'code-sample' let filePath const foundOnNetworks = [] for (const network of networks) { diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 008ffe53f9..f377893e43 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -1,7 +1,7 @@ import React, {useState, useEffect, useRef, useContext, ChangeEvent} from 'react' // eslint-disable-line import {FormattedMessage, useIntl} from 'react-intl' import {Dropdown} from 'react-bootstrap' -import {CustomIconsToggle, CustomMenu, CustomToggle, extractNameFromKey, extractParentFromKey} from '@remix-ui/helper' +import {CustomIconsToggle, CustomMenu, CustomToggle, CustomTooltip, extractNameFromKey, extractParentFromKey} from '@remix-ui/helper' import {FileExplorer} from './components/file-explorer' // eslint-disable-line import {FileSystemContext} from './contexts' import './css/remix-ui-workspace.css' @@ -943,6 +943,14 @@ export function Workspace() { + {selectedWorkspace && selectedWorkspace.name === 'code-sample' && } + > + renameCurrentWorkspace()} className="far fa-exclamation-triangle text-info ml-2 mt-1" aria-hidden="true"> + }