diff --git a/apps/remix-ide/src/app/files/dgitProvider.js b/apps/remix-ide/src/app/files/dgitProvider.js index 249640a0f3..d4a1a26c8c 100644 --- a/apps/remix-ide/src/app/files/dgitProvider.js +++ b/apps/remix-ide/src/app/files/dgitProvider.js @@ -233,11 +233,11 @@ class DGitProvider extends Plugin { return this.calculateLocalStorage() } - async clone (input) { + async clone (input, workspaceName) { const permission = await this.askUserPermission('clone', 'Import multiple files into your workspaces.') if (!permission) return false if (this.calculateLocalStorage() > 10000) throw new Error('The local storage of the browser is full.') - await this.call('filePanel', 'createWorkspace', `workspace_${Date.now()}`, true) + await this.call('filePanel', 'createWorkspace', workspaceName || `workspace_${Date.now()}`, true) const cmd = { url: input.url, diff --git a/libs/remix-ui/helper/src/lib/remix-ui-helper.ts b/libs/remix-ui/helper/src/lib/remix-ui-helper.ts index 71abad338d..d9fd9b03b9 100644 --- a/libs/remix-ui/helper/src/lib/remix-ui-helper.ts +++ b/libs/remix-ui/helper/src/lib/remix-ui-helper.ts @@ -47,6 +47,22 @@ export const createNonClashingNameAsync = async (name: string, fileManager, pref return name + counter + prefix + '.' + ext } +export const createNonClashingTitle = async (name: string, fileManager) => { + if (!name) name = 'Undefined' + let _counter + let exist = true + + do { + const isDuplicate = await fileManager.exists(name + (_counter || '')) + + if (isDuplicate) _counter = (_counter || 0) + 1 + else exist = false + } while (exist) + const counter = _counter || '' + + return name + counter +} + export const joinPath = (...paths) => { paths = paths.filter((value) => value !== '').map((path) => path.replace(/^\/|\/$/g, '')) // remove first and last slash) if (paths.length === 1) return paths[0] diff --git a/libs/remix-ui/tooltip-popup/src/lib/tooltip-popup.tsx b/libs/remix-ui/tooltip-popup/src/lib/tooltip-popup.tsx index b1a22b5726..077ed1a167 100644 --- a/libs/remix-ui/tooltip-popup/src/lib/tooltip-popup.tsx +++ b/libs/remix-ui/tooltip-popup/src/lib/tooltip-popup.tsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState } from 'react' import { OverlayTrigger, Popover } from 'react-bootstrap' import { TooltipPopupProps } from '../types' import './tooltip-popup.module.css' @@ -13,8 +13,12 @@ const popover = (title?: string, content?: string | React.ReactNode) => ( ) export function TooltipPopup(props: TooltipPopupProps) { + const [show, setShow] = useState(false) + return ( - + { + setShow(nextShow) + }}> ) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index ea1da26338..4c64b811e7 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -1,8 +1,8 @@ import React from 'react' import { bufferToHex, keccakFromString } from 'ethereumjs-util' import axios, { AxiosResponse } from 'axios' -import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' -import { checkSlash, checkSpecialChars } from '@remix-ui/helper' +import { addInputFieldSuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace } from './payload' +import { checkSlash, checkSpecialChars, createNonClashingTitle } from '@remix-ui/helper' import { JSONStandardInput, WorkspaceTemplate } from '../types' import { QueryParams } from '@remix-project/remix-lib' @@ -326,6 +326,14 @@ export const cloneRepository = async (url: string) => { const config = plugin.registry.get('config').api const token = config.get('currentFile') const repoConfig = { url, token } + const urlArray = url.split('/') + let repoName = urlArray[urlArray.length - 1] - plugin.call('dGitProvider', 'clone', repoConfig) + try { + repoName = await createNonClashingTitle(repoName, plugin.fileManager) + await plugin.call('dGitProvider', 'clone', repoConfig, repoName) + await plugin.call('manager', 'activatePlugin', 'dgit') + } catch (e) { + dispatch(displayPopUp('An error occured: ' + e)) + } } 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 f70bf31612..623c2cac15 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -131,7 +131,7 @@ export function Workspace () { const url = cloneUrlRef.current.value if (url) { - global.dispatchCloneRepository() + global.dispatchCloneRepository(url) } else { console.log('Please provide a valid github repository url.') }