From 61e648ba3491c1f3574256f2f2888ecaf91dfb8f Mon Sep 17 00:00:00 2001 From: lianahus Date: Mon, 12 Jun 2023 10:52:07 +0200 Subject: [PATCH] Delete workspace --- apps/remix-ide/src/app/panels/file-panel.js | 6 +-- .../src/lib/components/homeTabFile.tsx | 39 ++++++++++++------- .../workspace/src/lib/remix-ui-workspace.tsx | 6 +-- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index fefbf92ad9..38f5e1da6c 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -179,12 +179,12 @@ module.exports = class Filepanel extends ViewPlugin { const workspaceProvider = this.fileProviders.workspace const current = this.currentWorkspaceMetadata this.currentWorkspaceMetadata = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` } - if (workspace.name !== " - connect to localhost - ") { - localStorage.setItem('currentWorkspace', workspace.name) - } if (this.currentWorkspaceMetadata.name !== current) { this.saveRecent(workspace.name) } + if (workspace.name !== " - connect to localhost - ") { + localStorage.setItem('currentWorkspace', workspace.name) + } this.emit('setWorkspace', workspace) } diff --git a/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx index 7491a00167..21de735878 100644 --- a/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx @@ -65,10 +65,32 @@ function HomeTabFile({plugin}: HomeTabFileProps) { return { ...prevState, recentWorkspaces: { first: recents.first, second: recents.second, third: recents.third } } }) }) + + const updateWorkspaceName = (name, newName = '') => { + let recents = JSON.parse(localStorage.getItem('recentWorkspaces')) + const newRecents = recents + if (!recents) { + recents = {first:'', second: '', third: ''} + } else { + Object.keys(recents).map(key => { + if (recents[key] === name) newRecents[key] = newName + }) + } + setState(prevState => { + return { ...prevState, recentWorkspaces: { first: newRecents.first, second: newRecents.second, third: newRecents.third } } + }) + } + plugin.on('filePanel', 'workspaceDeleted', async (deletedName) => { + updateWorkspaceName(deletedName) + }) + plugin.on('filePanel', 'workspaceRenamed', async (name, newName) => { + updateWorkspaceName(name, newName) + }) return () => { plugin.off('filePanel', 'setWorkspace') + plugin.off('filePanel', 'workspaceDeleted') } - }, []) + }, [state.recentWorkspaces]) const processLoading = (type: string) => { _paq.push(['trackEvent', 'hometab', 'filesSection', 'importFrom' + type]) @@ -121,7 +143,7 @@ function HomeTabFile({plugin}: HomeTabFileProps) { await plugin.call('filePanel', 'createWorkspace', wName, 'remixDefault') } await plugin.call('filePanel', 'switchToWorkspace', { name: wName, isLocalHost: false }) - await plugin.call('filePanel', 'switchToWorkspace', { name: wName, isLocalHost: false }) // don't ask why + await plugin.call('filePanel', 'switchToWorkspace', { name: wName, isLocalHost: false }) // calling once is not working. const content = `// SPDX-License-Identifier: MIT pragma solidity >=0.7.0 <0.9.0; @@ -174,20 +196,7 @@ function HomeTabFile({plugin}: HomeTabFileProps) { const handleSwichToRecentWorkspace = async (e, workspaceName) => { e.preventDefault(); -<<<<<<< HEAD - await plugin.call('filePanel', 'switchToWorkspace', { name: workspaceName, isLocalhost: false }) -======= -<<<<<<< HEAD -<<<<<<< HEAD - await plugin.call('filePanel', 'switchToWorkspace', { name: workspaceName, isLocalhost: false }) - console.log('The link was clicked.'); -======= - await plugin.call('filePanel', 'switchToWorkspace', { name: workspaceName, isLocalhost: false }) ->>>>>>> e9b2848c5... cleanup fix undefined workspaces. Creating default Workspace -======= await plugin.call('filePanel', 'switchToWorkspace', { name: workspaceName, isLocalhost: false }) ->>>>>>> 06483cab7... fix vreating workspace ->>>>>>> 1b238a875... fix vreating workspace } const examples = state.modalInfo.examples.map((urlEl, key) => ( 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 e19799971d..6e6fef7373 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -899,10 +899,10 @@ export function Workspace() { ) : null} - +