From a8a31121469b45477d039aef6a86c21913db82b1 Mon Sep 17 00:00:00 2001 From: lianahus Date: Thu, 21 Sep 2023 10:07:45 +0200 Subject: [PATCH] refactoring the saved workspaces to have >3 saved --- apps/remix-ide/src/app/panels/file-panel.js | 17 +++--- .../src/lib/components/homeTabFile.tsx | 52 +++++++++---------- .../src/lib/components/LocalPluginForm.tsx | 6 +-- .../workspace/src/lib/actions/workspace.ts | 1 - .../workspace/src/lib/remix-ui-workspace.tsx | 2 +- 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 951497c1f0..c8c0c26dbe 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -181,17 +181,16 @@ module.exports = class Filepanel extends ViewPlugin { saveRecent(workspaceName) { if (!localStorage.getItem('recentWorkspaces')) { - localStorage.setItem('recentWorkspaces', JSON.stringify({ first: workspaceName, second: '', third: '' })) + localStorage.setItem('recentWorkspaces', JSON.stringify([ workspaceName ])) } else { - const recents = JSON.parse(localStorage.getItem('recentWorkspaces')) + let recents = JSON.parse(localStorage.getItem('recentWorkspaces')) // checking if we have a duplication - if (recents.first !== workspaceName && recents.second !== workspaceName && recents.third !== workspaceName) { - // filtering removed records - const firstW = workspaceName - const secondW = recents.first != '' ? recents.first : recents.second != '' ? recents.second : recents.third - const thirdW = recents.second != '' ? recents.second : recents.third - const newResents = JSON.stringify({ first: firstW, second: secondW, third: thirdW }) - localStorage.setItem('recentWorkspaces', newResents) + if (!recents.find((el) => { + return el === workspaceName + })) { + recents = ([workspaceName, ...recents]) + recents.filter((el) => { return el != "" }) + localStorage.setItem('recentWorkspaces', JSON.stringify(recents)) } } } 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 d450cf95fe..e467b2795f 100644 --- a/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx +++ b/libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx @@ -38,18 +38,14 @@ function HomeTabFile({ plugin }: HomeTabFileProps) { } importSource: string toasterMsg: string - recentWorkspaces: { - first: string - second: string - third: string - } + recentWorkspaces: Array }>({ searchInput: '', showModalDialog: false, modalInfo: { title: '', loadItem: '', examples: [], prefix: '' }, importSource: '', toasterMsg: '', - recentWorkspaces: { first: '', second: '', third: '' }, + recentWorkspaces: [], }) const [, dispatch] = useReducer(loadingReducer, loadingInitialState) @@ -60,26 +56,26 @@ function HomeTabFile({ plugin }: HomeTabFileProps) { plugin.on('filePanel', 'setWorkspace', async () => { let recents = JSON.parse(localStorage.getItem('recentWorkspaces')) - if (!recents) recents = { first: '', second: '', third: '' } - setState((prevState) => { - return { ...prevState, recentWorkspaces: { first: recents.first, second: recents.second, third: recents.third } } - }) + if (!recents) { + recents = [] + } else { + setState((prevState) => { + return { ...prevState, recentWorkspaces: recents.slice(0, recents.length <= 3 ? recents.length : 3) } + }) + } }) const deleteSavedWorkspace = (name) => { - console.log('deleted ', name) - let recents = JSON.parse(localStorage.getItem('recentWorkspaces')) - const newRecents = recents + const recents = JSON.parse(localStorage.getItem('recentWorkspaces')) + let newRecents = recents if (!recents) { - recents = { first: '', second: '', third: '' } + newRecents = [] } else { - Object.keys(recents).map((key) => { - if (recents[key] === name) newRecents[key] = '' - }) + newRecents = recents.filter((el) => { return el !== name}) localStorage.setItem('recentWorkspaces', JSON.stringify(newRecents)) } setState((prevState) => { - return { ...prevState, recentWorkspaces: { first: newRecents.first, second: newRecents.second, third: newRecents.third } } + return { ...prevState, recentWorkspaces: newRecents.slice(0, newRecents.length <= 3 ? newRecents.length : 3) } }) } plugin.on('filePanel', 'workspaceDeleted', async (deletedName) => { @@ -302,24 +298,24 @@ function HomeTabFile({ plugin }: HomeTabFileProps) { - {!(state.recentWorkspaces.first == '' && state.recentWorkspaces.second == '' && state.recentWorkspaces.third == '') && ( + {(state.recentWorkspaces[0] || state.recentWorkspaces[1] || state.recentWorkspaces[2]) && (
- {state.recentWorkspaces.first !== 'undefined' && state.recentWorkspaces.first !== '' && ( - handleSwichToRecentWorkspace(e, state.recentWorkspaces.first)}> - {state.recentWorkspaces.first} + {state.recentWorkspaces[0] && state.recentWorkspaces[0] !== '' && ( + handleSwichToRecentWorkspace(e, state.recentWorkspaces[0])}> + {state.recentWorkspaces[0]} )} - {state.recentWorkspaces.second !== 'undefined' && state.recentWorkspaces.second !== '' && ( - handleSwichToRecentWorkspace(e, state.recentWorkspaces.second)}> - {state.recentWorkspaces.second} + {state.recentWorkspaces[1] && state.recentWorkspaces[1] !== '' && ( + handleSwichToRecentWorkspace(e, state.recentWorkspaces[1])}> + {state.recentWorkspaces[1]} )} - {state.recentWorkspaces.third !== 'undefined' && state.recentWorkspaces.third !== '' && ( - handleSwichToRecentWorkspace(e, state.recentWorkspaces.third)}> - {state.recentWorkspaces.third} + {state.recentWorkspaces[2] && state.recentWorkspaces[2] !== '' && ( + handleSwichToRecentWorkspace(e, state.recentWorkspaces[2])}> + {state.recentWorkspaces[2]} )}
diff --git a/libs/remix-ui/plugin-manager/src/lib/components/LocalPluginForm.tsx b/libs/remix-ui/plugin-manager/src/lib/components/LocalPluginForm.tsx index 9c7e4d60c2..3dfcd6587d 100644 --- a/libs/remix-ui/plugin-manager/src/lib/components/LocalPluginForm.tsx +++ b/libs/remix-ui/plugin-manager/src/lib/components/LocalPluginForm.tsx @@ -265,7 +265,7 @@ function LocalPluginForm({closeModal, visible, pluginManager}: LocalPluginFormPr checked={location === 'sidePanel'} onChange={(e) => setLocation(e.target.value as 'sidePanel' | 'mainPanel' | 'none')} /> -