Skip to content

Commit dee78b8

Browse files
ioedeveloperAniket-Engg
authored andcommitted
Fix recent workspaces
1 parent 417ba15 commit dee78b8

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

apps/remix-ide/src/app/files/workspaceFileProvider.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ export default class WorkspaceFileProvider extends FileProvider {
2525
}
2626

2727
setWorkspace (workspace) {
28-
if (!workspace) return
29-
workspace = workspace.replace(/^\/|\/$/g, '') // remove first and last slash
28+
const workspaceName = (workspace || {}).name ? workspace.name : workspace
29+
30+
if (!workspaceName) return
31+
workspace = workspaceName.replace(/^\/|\/$/g, '') // remove first and last slash
3032
this.workspace = workspace
3133
}
3234

apps/remix-ide/src/app/panels/file-panel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,16 @@ export default class Filepanel extends ViewPlugin {
211211
}
212212

213213
saveRecent(workspaceName) {
214+
if (typeof workspaceName !== 'string') return
214215
if (workspaceName === 'code-sample') return
215216
if (!localStorage.getItem('recentWorkspaces')) {
216217
localStorage.setItem('recentWorkspaces', JSON.stringify([ { name: workspaceName, timestamp: Date.now() } ]))
217218
} else {
218219
let recents = JSON.parse(localStorage.getItem('recentWorkspaces'))
219220
// checking if we have a duplication
220-
if (!recents.find((el) => typeof el === 'string' ? el === workspaceName : el.name === workspaceName)) {
221+
if (!recents.find((el) => (el || {}).name ? el.name === workspaceName : el === workspaceName)) {
221222
recents = ([{ name: workspaceName, timestamp: Date.now() }, ...recents])
222-
recents = recents.filter((el) => typeof el === 'string' ? el !== '' : el.name !== '')
223+
recents = recents.filter((el) => (el || {}).name ? el.name !== '' : el !== '')
223224
localStorage.setItem('recentWorkspaces', JSON.stringify(recents))
224225
}
225226
}

libs/remix-ui/home-tab/src/lib/components/homeTabRecentWorkspaces.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function HomeTabRecentWorkspaces({ plugin }: HomeTabFileProps) {
3939
if (!recents) {
4040
newRecents = []
4141
} else {
42-
newRecents = recents.filter((el) => typeof el === 'string' ? el !== name : el.name !== name)
42+
newRecents = recents.filter((el) => (el || {}).name ? el.name !== name : el !== name)
4343
localStorage.setItem('recentWorkspaces', JSON.stringify(newRecents))
4444
}
4545
setState((prevState) => {
@@ -100,15 +100,15 @@ function HomeTabRecentWorkspaces({ plugin }: HomeTabFileProps) {
100100
</label>
101101
<div className="d-flex flex-column pl-2">
102102
{
103-
Array.isArray(state.recentWorkspaces) && state.recentWorkspaces.map((workspace, index) => {
104-
const workspaceName = typeof workspace === 'string' ? workspace : workspace.name
105-
const workspaceTimestamp = typeof workspace === 'string' ? null : workspace.timestamp
103+
Array.isArray(state.recentWorkspaces) && state.recentWorkspaces.map((workspace: any, index) => {
104+
const workspaceName = (workspace || {}).name ? workspace.name : workspace
105+
const workspaceTimestamp = (workspace || {}).timestamp ? workspace.timestamp : null
106106

107107
return index < 3 ? (
108108
<div key={index} className="d-flex flex-row align-items-center mb-2">
109109
{ loadingWorkspace === workspace ? <i className="fad fa-spinner fa-spin mr-2"></i> : <i className="fas fa-folder-tree mr-2"></i> }
110110
<div className="d-flex flex-row justify-content-between w-100 flex-wrap">
111-
<a className="cursor-pointer text-decoration-none d-inline-block" href="#" onClick={(e) => handleSwitchToRecentWorkspace(e, workspace)} key={index}>
111+
<a className="cursor-pointer text-decoration-none d-inline-block" href="#" onClick={(e) => handleSwitchToRecentWorkspace(e, workspaceName)} key={index}>
112112
<span style={{ color: isDark ? 'white' : 'black' }}>{workspaceName}</span>
113113
</a>
114114
<span className="text-muted">created {getTimeAgo(workspaceTimestamp)}</span>

0 commit comments

Comments
 (0)