diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index 2e4feaf0e2..d8f55573f5 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -46,6 +46,7 @@ const profile = { 'loadTemplate', 'clone', 'isExpanded', + 'isGist' ], events: ['setWorkspace', 'workspaceRenamed', 'workspaceDeleted', 'workspaceCreated'], icon: 'assets/img/fileManager.webp', @@ -131,6 +132,20 @@ module.exports = class Filepanel extends ViewPlugin { }) } + /** + * return the gist id if the current workspace is a gist workspace, otherwise returns null + * @argument {String} workspaceName - the name of the workspace to check against. default to the current workspace. + * @returns {string} gist id or null + */ + isGist (workspaceName) { + workspaceName = workspaceName || this.currentWorkspaceMetadata && this.currentWorkspaceMetadata.name + const isGist = workspaceName.startsWith('gist') + if (isGist) { + return workspaceName.split(' ')[1] + } + return null + } + getCurrentWorkspace() { return this.currentWorkspaceMetadata } 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 3847cae628..0e493a8e0c 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/filePanel.json +++ b/apps/remix-ide/src/app/tabs/locales/en/filePanel.json @@ -62,10 +62,10 @@ "filePanel.compileForNahmii": "Compile for Nahmii", "filePanel.createNewFile": "Create new file", "filePanel.createNewFolder": "Create new folder", - "filePanel.publishToGist": "Publish all files to GitHub gist", + "filePanel.publishToGist": "Publish workspace to GitHub gist", "filePanel.uploadFile": "Upload files", "filePanel.uploadFolder": "Upload folder", - "filePanel.updateGist": "Update the current [gist] explorer", + "filePanel.updateGist": "Publish workspace to GitHub gist", "filePanel.viewAllBranches": "View all branches", "filePanel.createBranch": "Create branch", "filePanel.switchBranches": "Switch branches", diff --git a/libs/remix-core-plugin/src/lib/gist-handler.ts b/libs/remix-core-plugin/src/lib/gist-handler.ts index 5a1e04d98e..e204b21a1b 100644 --- a/libs/remix-core-plugin/src/lib/gist-handler.ts +++ b/libs/remix-core-plugin/src/lib/gist-handler.ts @@ -117,7 +117,7 @@ export class GistHandler extends Plugin { const obj: StringByString = {} Object.keys(data.files).forEach((element) => { const path = element.replace(/\.\.\./g, '/') - obj['/gist-' + gistId + '/' + path] = data.files[element] + obj['/' + path] = data.files[element] }) this.call('fileManager', 'setBatchFiles', obj, isElectron()? 'electron':'workspace', true, async (errorSavingFiles: any) => { if (errorSavingFiles) { diff --git a/libs/remix-ui/workspace/src/lib/actions/index.ts b/libs/remix-ui/workspace/src/lib/actions/index.ts index 998a39779c..15344a2a4b 100644 --- a/libs/remix-ui/workspace/src/lib/actions/index.ts +++ b/libs/remix-ui/workspace/src/lib/actions/index.ts @@ -225,14 +225,19 @@ export type SolidityConfiguration = { runs: string } -export const publishToGist = async (path?: string, type?: string) => { +export const publishToGist = async (path?: string) => { // If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer. const folder = path || '/' try { - const name = await plugin.call('filePanel', 'getCurrentWorkspace') - const id = name && name.startsWith('gist ') ? name.split(' ')[1] : null - + let id + if (path) { + // check if the current folder is a gist folder + id = await plugin.call('filePanel', 'isGist', extractNameFromKey(path)) + } else { + // check if the current workspace is a gist workspace + id = await plugin.call('filePanel', 'isGist') + } const packaged = await packageGistFiles(folder) // check for token const config = plugin.registry.get('config').api @@ -521,11 +526,6 @@ const packageGistFiles = async (directory) => { if (/^\s+$/.test(content) || !content.length) { content = '// this line is added to create a gist. Empty file is not allowed.' } - if (path.indexOf('gist-') === 0) { - path = path.split('/') - path.shift() - path = path.join('/') - } path = path.replace(/\//g, '...') ret[path] = { content } }) diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index 0bbdf6b368..7649e1400d 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -609,6 +609,7 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea Object.keys(items) .filter((item) => items[item].isDirectory) .map(async (folder) => { + const name = folder.replace(workspacesPath + '/', '') const isGitRepo: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.git') const hasGitSubmodules: boolean = await plugin.fileProviders.browser.exists('/' + folder + '/.gitmodules') if (isGitRepo) { @@ -618,17 +619,20 @@ export const getWorkspaces = async (): Promise<{ name: string; isGitRepo: boolea branches = await getGitRepoBranches(folder) currentBranch = await getGitRepoCurrentBranch(folder) return { - name: folder.replace(workspacesPath + '/', ''), + name, isGitRepo, branches, currentBranch, - hasGitSubmodules + hasGitSubmodules, + isGist: null } } else { + const gistId = await plugin.call('filePanel', 'isGist', name) return { - name: folder.replace(workspacesPath + '/', ''), + name, isGitRepo, - hasGitSubmodules + hasGitSubmodules, + isGist: gistId } } }) diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx index 243f68e1a9..bba7bbc39a 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer-menu.tsx @@ -33,6 +33,13 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { placement: 'top', platforms:[appPlatformTypes.web] }, + { + action: 'updateGist', + title: 'Update the cdddurrent gist', + icon: 'fab fa-github', + placement: 'bottom-start', + platforms:[appPlatformTypes.web] + }, { action: 'uploadFile', title: 'Upload files into current workspace', @@ -46,13 +53,6 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { icon: 'far fa-folder-upload', placement: 'top', platforms:[appPlatformTypes.web] - }, - { - action: 'updateGist', - title: 'Update the current [gist] explorer', - icon: 'fab fa-github', - placement: 'bottom-start', - platforms:[appPlatformTypes.web] } ].filter( (item) => @@ -65,16 +65,6 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { }) const enableDirUpload = {directory: '', webkitdirectory: ''} - useEffect(() => { - const actions = { - updateGist: () => {} - } - - setState((prevState) => { - return {...prevState, actions} - }) - }, []) - return ( (!global.fs.browser.isSuccessfulWorkspace ? null : <> @@ -165,7 +155,7 @@ export const FileExplorerMenu = (props: FileExplorerMenuProps) => { props.createNewFile() } else if (action === 'createNewFolder') { props.createNewFolder() - } else if (action === 'publishToGist') { + } else if (action === 'publishToGist' || action == 'updateGist') { props.publishToGist() } else { state.actions[action]() diff --git a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx index c57585ce8a..8d7c1ac5bd 100644 --- a/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx +++ b/libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx @@ -117,8 +117,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => { await deleteAllWorkspaces() } - const dispatchPublishToGist = async (path?: string, type?: string) => { - await publishToGist(path, type) + const dispatchPublishToGist = async (path?: string) => { + await publishToGist(path) } const dispatchUploadFile = async (target?: SyntheticEvent, targetFolder?: string) => { diff --git a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts index 2d6b15a26c..d2f923ceb8 100644 --- a/libs/remix-ui/workspace/src/lib/reducers/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/reducers/workspace.ts @@ -17,6 +17,7 @@ export interface BrowserState { name: string }[] currentBranch?: string + isGist: string }[] files: {[x: string]: Record} flatTree: FileType[] @@ -150,7 +151,6 @@ export const browserReducer = (state = browserInitialState, action: Actions) => case 'SET_WORKSPACES': { const payload = action.payload - return { ...state, browser: { @@ -986,8 +986,7 @@ const removeInputField = ( isDirectory: true, path, name: extractNameFromKey(path), - type: - extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder', + type: 'folder', child: prevFiles ? prevFiles.child : {} }, Object @@ -1117,8 +1116,7 @@ const normalize = ( path, name: extractNameFromKey(path), isDirectory: filesList[key].isDirectory, - type: - extractNameFromKey(path).indexOf('gist-') === 0 ? 'gist' : 'folder' + type: 'folder' } } else { files[extractNameFromKey(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 e71d94ffd9..fc059dc90d 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -32,6 +32,7 @@ export function Workspace() { hasGitSubmodules?: boolean branches?: {remote: any; name: string}[] currentBranch?: string + isGist: string }>(null) const [showDropdown, setShowDropdown] = useState(false) const [showIconsMenu, hideIconsMenu] = useState(false) @@ -73,7 +74,7 @@ export function Workspace() { }, mouseOverElement: null, showContextMenu: false, - reservedKeywords: [ROOT_PATH, 'gist-'], + reservedKeywords: [ROOT_PATH], copyElement: [], dragStatus: false }) @@ -922,7 +923,6 @@ export function Workspace() { ) } - return (
)} {!(global.fs.browser.isRequestingWorkspace || global.fs.browser.isRequestingCloning) && global.fs.mode === 'browser' && currentWorkspace !== NO_WORKSPACE && ( -