download workspace files and folders

pull/3504/head
Aniket-Engg 2 years ago committed by yann300
parent 477018d94c
commit 47024aa90b
  1. 21
      libs/remix-ui/workspace/src/lib/actions/index.ts
  2. 1
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  3. 7
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  4. 6
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -376,6 +376,27 @@ export const handleDownloadFiles = async () => {
}
}
export const handleDownloadWorkspace = async () => {
try {
const zip = new JSZip()
const workspaceProvider = plugin.fileProviders.workspace
await workspaceProvider.copyFolderToJson('/', ({ path, content }) => {
zip.file(path, content)
})
zip.generateAsync({ type: 'blob' }).then(function (blob) {
const today = new Date()
const date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate()
const time = today.getHours() + 'h' + today.getMinutes() + 'min'
saveAs(blob, `remix-backup-at-${time}-${date}.zip`)
}).catch((e) => {
plugin.call('notification', 'toast', e.message)
})
} catch (e) {
plugin.call('notification', 'toast', e.message)
}
}
export const restoreBackupZip = async () => {
await plugin.appManager.activatePlugin(['restorebackupzip'])
await plugin.call('mainPanel', 'showContent', 'restorebackupzip')

@ -33,6 +33,7 @@ export const FileSystemContext = createContext<{
dispatchHandleClickFile: (path: string, type: 'file' | 'folder' | 'gist') => Promise<void>
dispatchHandleExpandPath: (paths: string[]) => Promise<void>,
dispatchHandleDownloadFiles: () => Promise<void>,
dispatchHandleDownloadWorkspace: () => Promise<void>,
dispatchHandleRestoreBackup: () => Promise<void>
dispatchCloneRepository: (url: string) => Promise<void>,
dispatchMoveFile: (src: string, dest: string) => Promise<void>,

@ -7,7 +7,7 @@ import { FileSystemContext } from '../contexts'
import { browserReducer, browserInitialState } from '../reducers/workspace'
import { initWorkspace, fetchDirectory, removeInputField, deleteWorkspace, deleteAllWorkspaces, clearPopUp, publishToGist, createNewFile, setFocusElement, createNewFolder,
deletePath, renamePath, downloadPath, copyFile, copyFolder, runScript, emitContextMenuEvent, handleClickFile, handleExpandPath, addInputField, createWorkspace,
fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder,
fetchWorkspaceDirectory, renameWorkspace, switchToWorkspace, uploadFile, uploadFolder, handleDownloadWorkspace, handleDownloadFiles, restoreBackupZip, cloneRepository, moveFile, moveFolder,
showAllBranches, switchBranch, createNewBranch, checkoutRemoteBranch, createSolidityGithubAction, createTsSolGithubAction, createSlitherGithubAction
} from '../actions'
import { Modal, WorkspaceProps, WorkspaceTemplate } from '../types'
@ -135,6 +135,10 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await handleDownloadFiles()
}
const dispatchHandleDownloadWorkspace = async () => {
await handleDownloadWorkspace()
}
const dispatchHandleRestoreBackup = async () => {
await restoreBackupZip()
}
@ -284,6 +288,7 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
dispatchHandleClickFile,
dispatchHandleExpandPath,
dispatchHandleDownloadFiles,
dispatchHandleDownloadWorkspace,
dispatchHandleRestoreBackup,
dispatchCloneRepository,
dispatchMoveFile,

@ -160,7 +160,11 @@ export function Workspace () {
}
const onFinishDownloadWorkspace = async () => {
console.log('inside onFinishDownloadWorkspace')
try {
await global.dispatchHandleDownloadWorkspace()
} catch (e) {
console.error(e)
}
}
const onFinishCreateWorkspace = async () => {

Loading…
Cancel
Save